Question: - Create the following Program that stores the year and the make of car in a data file. in C++ - Car makes will consist
- Create the following Program that stores the year and the make of car in a data file. in C++ - Car makes will consist of Chevy, Dodge, Ford, Honda and Toyota - Create a data file called cars.txt to contain the above info - Create a void function called NewInfo that prompts the user to input year and make info from the keyboard. Use a do while or while loop to call NewInfo and input the make and year until the user has indicated he is finished entering data. Be sure to count how many records are input. Hint: use a sentinel to signal end of input or a prompt to continue or count the number of items during file operations. - Create a return function called countCar that will return the number of each particular make of car. This function will be called 5 times. Once for each make of car (see next line) - Use a for loop to call the return function countCar then print out each car make and number of occurrences of each vehicle type - Create a void function called printInfo that prints out each make and year - Be sure to label and make your output readable and use proper documentation
#include
using namespace std;
struct car { string make; int year; };
void NewInfo(string &mk, int &year){ cout << "Enter the make of the car-Chevy, Dodge, Ford, Honda or Toyota: "; cin >> mk; cout << "Please enter the year of the car: "; cin >> year; }
void printinfo(car data[], int count){ cout << setw(10) <<"Make" << setw(10) << "Year" << endl; for (int i = 0; i int countCar(car data[]){ ifstream fin("cars.txt"); if (!fin){ cout << "Error opening file "; return 0; } int count = 0; while(fin>>data[count].make>>data[count].year) count++; fin.close(); return count; } int main(){ car data[100]; int count; char choice; count = countCar(data); while (true){ NewInfo(data[count].make,data[count].year); cout<<"Would you like to enter data for another car? y or n "; cin >> choice; if (choice == 'n'||'N') break; } cout<<"Do you like to display all data? y or n "; cin >> choice; if (choice == 'y'||'Y'){ printinfo(data, count); } ofstream fout("cars.txt"); for (int i = 0; i }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
