Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the program so that, rather than printing data directly to the screen, it will read the data into an array of car structs and

Modify the program so that, rather than printing data directly to the screen, it will read the data into an array of car structs and then print out the contents of the array.

#include "car.h" #include  #include  #include  #include  

Car GetCar(ifstream& dataIn);

// Pre: File dataIn has been opened.

// Post: The fields of car are read from file dataIn.

void WriteCar(ofstream& dataOut, Car car);

// Pre: File dataOut has been opened.

// Post: The fields of car are written on file dataOut,

// appropriately labeled.

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.10f;

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;

}

.h file

#include  struct PersonType { std::string firstname; std::string lastname; }; struct Date { int month; int day; int year; }; struct Car { float price; Date purchased; PersonType customer; }; 

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

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago