Question: I need help with this program LAB part. lab (part 1) (100%) MotorVehicleModule Design and code a class namedMotorVehiclethat holds information about a vehicle with
I need help with this program LAB part.
lab (part 1) (100%)
MotorVehicleModule
Design and code a class namedMotorVehiclethat holds information about a vehicle with an engine. Place your class definition in a header file namedMotorVehicle.hand your function definitions in an implementation file namedMotorVehicle.cpp.
Include in your solution all of the statements necessary for your code to compile under a standard C++ compiler and within thesddsnamespace.
MotorVehicleClass
Design and code a class namedMotorVehiclethat holds information about a vehicle with an engine.
MotorVehiclePrivate Members
The class should be able to store the following data:
- a license plate number as a statically allocated array of characters of size 9.
- the address where the vehicle is at a given moment as a statically allocated array of characters of size 64.
- the year when the vehicle was built.
You can add any other private members in the class, as required by your design.
MotorVehiclePublic Members
- a custom constructor that receives as parameters the license plate number and the year when the vehicle was built. Set the location of the vehicle atFactory. Assume all data is valid.
- void moveTo(const char* address): moves the vehicle to the new address if the new address is different from the current address. Prints to the screen the message
|[LICENSE_PLATE]| |[CURRENT_ADDRESS] ---> [NEW_ADDRESS]|
- where
- the license plate is a field of 8 characters aligned to the right
- current address is a field of 20 characters aligned to the right
- new address is a field of 20 characters aligned to left
- ostream& write(ostream& os): a query that inserts intoosthe content of the object in the format
| [YEAR] | [PLATE] | [ADDRESS]
- istream& read(istream& in): a mutator that reads from the streaminthe data for the current object
Built year: [USER TYPES HERE] License plate: [USER TYPES HERE] Current location: [USER TYPES HERE]
Helper Functions
- overload the insertion and extraction operators to insert aMotorVehicleinto a stream and extract aMotorVehiclefrom a stream. These operators should call thewrite/readmember functions in the classMotorVehicle.
TruckModule
Design and code a class namedTruckthat holds information about a motor vehicle that can carry cargo. Place your class definition in a header file namedTruck.hand your function definitions in an implementation file namedTruck.cpp.
Include in your solution all of the statements necessary for your code to compile under a standard C++ compiler and within thesddsnamespace.
TruckClass
Design and code a class namedTruckthat holds information about a motor vehicle that can carry cargo.This class should inherit fromMotorVehicleclass.
TruckPrivate Members
The class should be able to store the following data (on top of data coming from the parent class):
- a capacity in kilograms as a floating-point number in double precision; this is the maximum weight of the cargo the truck can carry.
- the current cargo load (in kilograms) is a floating-point number in double precision; the load cannot exceed the capacity.
You can add any other private members in the class, as required by your design.Do not duplicate members from the base class!
TruckPublic Members
- a custom constructor that receives as parameters the license plate number, the year when the truck was built, the capacity of the truck and the current address. Call the constructor from the base class and pass the license number and year to it. Set the current cargo to 0 and move the truck to the address specified in the last parameter.
- bool addCargo(double cargo): a mutator that adds to the attribute that stores the current cargo load the weight specified as a parameter.Do not exceed the capacity!If the current load has been changed, returntrue, otherwise returnfalse.
- bool unloadCargo(): a mutator that unloads current cargo (sets the attribute to 0). If the current load has been changed, returntrue, otherwise, returnfalse.
- ostream& write(ostream& os): a query that inserts intoosthe content of the object in the format
| [YEAR] | [PLATE] | [ADDRESS] | [CURRENT_CARGO]/[CAPACITY]
- istream& read(istream& in): a mutator that reads from the streaminthe data for the current object
Built year: [USER TYPES HERE] License plate: [USER TYPES HERE] Current location: [USER TYPES HERE] Capacity: [USER TYPES HERE] Cargo: [USER TYPES HERE]
Helper Functions
- overload the insertion and extraction operators to insert aTruckinto a stream and extract aTruckfrom a stream. These operators should call thewrite/readmember functions in the classTruck.
mainModule (supplied)
Do not modify this module!Look at the code and make sure you understand it.
Sample Output
---------------------------------------- |> T1: Vehicle ---------------------------------------- | 2010 | VVV-111 | Factory | VVV-111| | Factory ---> Downtown Toronto | | VVV-111| | Downtown Toronto ---> Mississauga | | VVV-111| | Mississauga ---> North York | | 2010 | VVV-111 | North York ---------------------------------------- |> T2: Read/Write ---------------------------------------- Built year: 2020 License plate: abc-111 Current location: Toronto | 2020 | abc-111 | Toronto ---------------------------------------- |> T3: Truck ---------------------------------------- | T-1111| | Factory ---> Toronto HQ | | T-1111| | Toronto HQ ---> Toronto Deposit | Cargo loaded! | 2015 | T-1111 | Toronto Deposit | 2345/5432 | T-1111| | Toronto Deposit ---> Montreal | Cargo loaded! | 2015 | T-1111 | Montreal | 5432/5432 | T-1111| | Montreal ---> New York | Adding cargo failed! | 2015 | T-1111 | New York | 5432/5432 | T-1111| | New York ---> New Jersey | Cargo unloaded! | 2015 | T-1111 | New Jersey | 0/5432 | T-1111| | New Jersey ---> Toronto | Unloading cargo failed! | 2015 | T-1111 | Toronto | 0/5432 ---------------------------------------- |> T4: Read/Write ---------------------------------------- Built year: 2019 License plate: def-222 Current location: Montreal Capacity: 2345 Cargo: 1234 | 2019 | def-222 | Montreal | 2019 | def-222 | Montreal | 1234/2345
link: https://github.com/Seneca-244200/BTP-Workshops/tree/main/WS07
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
