Question: 1. Using the same CarRecords.txt input file from Blackboard, write an object-oriented C++ program in a single file called CarRecords.cpp. In the file, define two





1. Using the same "CarRecords.txt" input file from Blackboard, write an object-oriented C++ program in a single file called CarRecords.cpp. In the file, define two independent classes; class Car, class CarRecords, and the main function. Implement class Car with the following description: Car private: string make string model int year string color public: Car() setFields (string mk, string md, int yr, string cl) string getMake () string getModel() int getYear() string getColor() Variables: make, model, year, color-the four data fields from the file Methods: Car() - default constructor sets the data fields to their default values. setFields (string mk, string md, int yr, string cl) - sets the class member fields to the values passed. string getMake() - returns make string getModel() - returns model int getYear() - returns year string getColor() - returns color Implement class CarRecords with the following description: CarRecords private int arraysize 11 keep track of number of records ifstream infile Car *cars public: CarRecords (int size) // Reads file records to array -CarRecords () void printCarRecords () void sort_cars_by_make () void sort_cars_by_year() void print_duplicates () Variables: arraySize - size of the array set to the number of records read from the file infile-input file stream used to read information from a file cars - a pointer object to a dynamically allocated array of objects) Methods: CarRecords (int size) - constructor sets the value passed to the arraysize member, creates a dynamic array enough to hold arraySize objects of type Car. In addition, the constructor uses the infile file stream and the setFields () method to initialize all the cars array elements with the car records read from the file. CarRecords () - Destructor frees the memory allocated with new, and closes the file handler. void printCarRecords () - prints out the car records from the array of objects (see sample output) void sort_cars_by_make () - sorts the records in ascending order based on the make field. void sort_cars_by_year() - sorts the records in descending order based on the year field. void print_duplicates () - identifies any repeated records, and prints them out when found. Repeated records means that all the fields are the same. Car Records.txt Subaru, Outback, 2016, green Toyota, Corolla, 2006, white Dodge, Neon, 1993, pink Ford, Fusion, 2013, yellow Honda, Fit, 2015, blue Ford, Expedition, 2009, silver Toyota, Corolla, 2006, white Ford, Fusion, 2013, yellow Jeep, Cherokee, 1999, red Mazda, Protoge, 1996, gold 2. Test your program with the main program below. If the user enters a value equal to or less than 10 for records to read, the program should create an arrays with that many elements using dynamically memory allocation and should only read that many records from the file, e.g. if the user enters 5, the program should create an array of 5 elements and only read 5 car records. If the user enters a number greater than 10, the program should create an array of only 10 elements and read all 10 records from the file. This checking is done in the CarRecords (int size) constructor when it reads the file. Note: For modularity, or if needed, your classes and the main function can have other helper functions. Your code should be well commented. int main() { int numRecs; cout > numRecs; Car Records *cr = new Car Records (numRecs); // Print car records cr->printCarRecords (); // Sort by Year cr->sort_cars_by_year(); // Print car records cr->print CarRecords(); // Sort by Make cr->sort cars by make(); // Print car records cr->print CarRecords(); // Check for Duplicates cr->print_duplicates); delete cr; 1 // end main // end main Sample output Number or Records to read? 15 PRINTING 10 RECORDS! Subaru, Outback, 2016, green Toyota, Corolla, 2006, white Dodge, Neon, 1993, pink Ford, Fusion, 2013, yellow Honda, Fit, 2015, blue Ford, Expedition, 2009, silver Toyota, Corolla, 2006, white Ford, Fusion, 2013, yellow Jeep, Cherokee, 1999, red Mazda, Protoge, 1996, gold SORTING RECORDS BY YEAR.... PRINTING 10 RECORDS! Dodge, Neon, 1993, pink Mazda, Protoge, 1996, gold Jeep, Cherokee, 1999, red Toyota, Corolla, 2006, white Toyota, Corolla, 2006, white Ford, Expedition, 2009, silver D . Show transcribed image text
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
