Question: C++ include carType.h #include #include #include class carType { private: int mileage; int year; double price; string color; string style; int id; public: void print()
C++
include "carType.h" #include
class carType { private: int mileage; int year; double price; string color; string style; int id;
public: void print() const; carType(); void getALL(int&, int& double&, string&, string&, int&) const; void setALL(int, int, double, string, string, int);
}
int main() {
carType cars[500]; int index=0; int miles, yr, carID; double p; string col, st;
// Read input data
cars[index].setAll(miles, yr, p, col, st, carID);
}
Program 6- Using an Array of Class Objects Due 11/12/2018 This program builds on the in-class labs of October 29 and 31The main program will declare an array of carType objects (no more than 500), get file input for some number of array objects, and determine how many array objects were input. (This was done as a Lab.) Next, the program presents the user with a menu of choices: a- Add a new car s- Sell a car y- Print data for all cars in a given model year p- Print a car's data q- Quit The program reads the user's choice, calls a function to do the user's choice, then displays the menu again. The program loops and does the user's choices until the user selects q (Quit). Required functions in main) readInput function from Lab, to read file input into the array of carType objects Menu function: displays the menu and gets input of the user's choice Add a new car function: gets keyboard input from the user for car name, price, number of packages on hand, and ID: the next available carType object in the array accesses its member function setAll with these values as parameters, then the number of car objects in the array is incremented Sell a car function: Asks the user to input a car ID, then finds the corresponding car object in the array (or reports "not found to the user and exits the function). The sold car's object must be removed from the array. Car objects after the sold one must be "moved" (copied) from their index position to (their index minus I) position, starting from the object right after the sold one. Print all cars in a model year function: Asks the user to input a model year, then finds all car objects with that model year and outputs the car data values. If no car object has that year, then a "none found" message is output. Print a car's data function: Asks the user to input a car ID, then finds the corresponding car object in the array (or reports "not found" to the user and exits the function). Outputs the car's data values. carType class functions: Note that you may modify the class definition of carType by inserting useful class functions as needed. For example, to search for a car ID in the array objects, you need a public function getID which retums the ID data value. In the header file, put the function prototype in the class definition, and add the function definition below it. Program 6- Using an Array of Class Objects Due 11/12/2018 This program builds on the in-class labs of October 29 and 31The main program will declare an array of carType objects (no more than 500), get file input for some number of array objects, and determine how many array objects were input. (This was done as a Lab.) Next, the program presents the user with a menu of choices: a- Add a new car s- Sell a car y- Print data for all cars in a given model year p- Print a car's data q- Quit The program reads the user's choice, calls a function to do the user's choice, then displays the menu again. The program loops and does the user's choices until the user selects q (Quit). Required functions in main) readInput function from Lab, to read file input into the array of carType objects Menu function: displays the menu and gets input of the user's choice Add a new car function: gets keyboard input from the user for car name, price, number of packages on hand, and ID: the next available carType object in the array accesses its member function setAll with these values as parameters, then the number of car objects in the array is incremented Sell a car function: Asks the user to input a car ID, then finds the corresponding car object in the array (or reports "not found to the user and exits the function). The sold car's object must be removed from the array. Car objects after the sold one must be "moved" (copied) from their index position to (their index minus I) position, starting from the object right after the sold one. Print all cars in a model year function: Asks the user to input a model year, then finds all car objects with that model year and outputs the car data values. If no car object has that year, then a "none found" message is output. Print a car's data function: Asks the user to input a car ID, then finds the corresponding car object in the array (or reports "not found" to the user and exits the function). Outputs the car's data values. carType class functions: Note that you may modify the class definition of carType by inserting useful class functions as needed. For example, to search for a car ID in the array objects, you need a public function getID which retums the ID data value. In the header file, put the function prototype in the class definition, and add the function definition below it
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
