Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

extend the structure definition in cars.cpp (attached) to use a personType structure rather than just a string for the customer name. Also, update the program

extend the structure definition in cars.cpp (attached) to use a personType structure rather than just a string for the customername. Also, update the program to use this new structure and move all the structure definitions to a separate .h file.

Step 1: Create a car.h file with the current structure definitions. Include that file in cars.cpp and make sure that the program still compiles/runs. (Note: You could make separate .h files for each struct.)

Step 2: Create the new personType structure in car.h and use it in place of the string type for customer.

Step 3: Modify cars.cpp to use the new personType struct.

Submit:

Commented .cpp and .h files with all team members names included in the top comments.

Here is my current program

// Program Cars reads a record from a file and writes // its contents back to another file with the price member // increased by 10%. #include  #include  #include  using namespace std; struct Date { int month; int day; int year; }; struct Car { float price; Date purchased; string customer; }; // Pre: File dataIn has been opened. // Post: The fields of car are read from file dataIn. Car GetCar(ifstream& dataIn); // Pre: File dataOut has been opened. // Post: The fields of car are written on file dataOut, // appropriately labeled. void WriteCar(ofstream& dataOut, Car car); int main () { Car car; ifstream dataIn; ofstream dataOut; dataIn.open("cars.dat"); dataOut.open("cars.out"); cout << fixed << showpoint; car = GetCar(dataIn); while (dataIn) { car.price = car.price * 1.10; WriteCar(dataOut, car); car = GetCar(dataIn); } return 0; } //***************************************************** Car GetCar(ifstream& dataIn) { Car car; dataIn >> car.customer; dataIn >> car.price >> car.purchased.day >> car.purchased.month >> car.purchased.year; dataIn.ignore(2, ' '); return car; } //***************************************************** void WriteCar(ofstream& dataOut, Car car) { dataOut << "Customer: " << car.customer << endl << "Price: " << car.price << endl << "Purchased:" << car.purchased.day << "/" << car.purchased.month << "/" << car.purchased.year << endl; } 

Here is the data from a file to go with it.

TinyTim 55000 1 1 1985 MaryMurphay 12500 2 7 1995 BearBare 44444 9 6 1990 SallySale 7500 6 3 1970 BettyBye 18888 4 8 1988 AliceAlas 23005 6 6 1992

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Select suitable tools to analyze service problems.

Answered: 1 week ago