Question: For this project, you must create a separate .h and .cpp files for your class implementation and your driver (client) program. a) First, write a
For this project, you must create a separate .h and .cpp files for your class implementation and your driver (client) program.
a) First, write a C++ class named Car that has the following private member variables
year (int)
make (string)
speed (int)
Add the following public members functions to class Car
Default Constructor with no parameters: This constructor should set the year to -1, make to "none" and speed to 0.
Constructor with parameters: The constructor should accept the make and year as arguments and use these arguments values to set the year and make member variables of the class. Speed should be initialized to 0 by this constructor.
Accessors (getters): add these member functions for year, make and speed member variables.
Mutators (setters): add these member functions for year, make and speed member variables.
accelerate: this member function should add 5 to speed member variable each time it is called.
brake: this member function should subtract 5 from speed member variable each time it is called.
print: this member function should print the values of make, model, and speed of the car in to the screen.
The declaration of class Car must be done in Car.h file and the definition (implementation) of the member functions of class Car must be done in Car.cpp file.
b) Then, add another source file called CarTest.cpp to your project and have a main function in the CarTest.cpp file: Create an two objects of class Car in your main function, one with using the default constructor and the other one using the constructor with parameters.
call print function for each Car objects.
call accelerate function for each Car object and followed by a call to print function for each Car object.
call brake function for each Car object and followed by a call to print function for each Car object.
Put all your .h and .cpp files in a folder, save the folder as Lab4-1-yourName and .zip (compress) the folder to submit.
2) You will create another version of your project from part (1)
a) Your job is first to add 4 stand-alone functions to your CarTest.cpp file. The headers of the functions are provided below, you must provide the definition (implementation) of each function. Note that you are not allowed to change the headers of the functions.
// This function will get the information of a car interactively from the user who will enter (year, make and speed) information from the keyboard. The function will return the car information
Car getCarInfo_ver1();
// This function will get the information of a car interactively from the user who will enter (year, make and speed) information from the keyboard. The function will save information in the reference parameter newCar.
void getCarInfo_ver2(Car &newCar);
// this function will print the information of theCar to the screen
void printCarInfo(const Car &theCar);
// this function will write the information of theCar to the output text file outFile
void saveCarInfo(ofstream &outFile, const Car &theCar);
b) Next, you must update your main function to show the use of each of the functions you wrote in part (2a) above by calling each function twice.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
