Question: 4 Hierarchical Records Use program Cars for Exercises 4 - 5 . EGR 1 2 1 Introduction to Computer Programming in C + + College
Hierarchical Records
Use program Cars for Exercises
EGR Introduction to Computer Programming in
College of Engineering, California Baptist University
ifstream dataIn;
ofstream dataOut:
dataIn.open "cars.dat";
dataOut.open "cars.out" ;
cout fixed showpoint;
car GetCar dataIn ;
whlle dataIn
car.price car.price ;
VriteCar dataout, car ;
car GetCar dataIn ;
return ;
CarType GetCar ifstream dataIn
Exercise :
Using Notepad, enter the following data into a file named cars dat:
Run the program. Show the content of the output file cars.out.
Exercise :
Modify the CarType struct to add a Boolean type member called sold and a DateType member called
soldDate. In the GetCar function, initialize sold to false. In the while loop in function main, ask user
whether the car has been sold for each car record read from cars.dat. If the car is not sold, write the record
to cars.out with the price increased by as before. If the car is sold, call function CarSold. The void
function CarSold takes one parameter of CarType. It should ask the user when the car was sold, and
update two members of the reference parameter of CarType: set sold to true, and set soldDate with the
sold date entered by user, then write the updated record to file carssold.our instead of cars.out. Run your
program using file cars.dat and show your test results with IO in console window, contents in
carssold.out and cars.out. You can assume that Mary's and Betty's cars have been resold. Include your
modified program in the report.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
