Answer to Question #187521 in C++ for Jackie

Question #187521

(fourth part)

You should read the data using this pattern:

Read the first line of data from the vacation.txt file (the miles traveled and the time in

minutes).

while (! inStream.fail() )

// Use here your name for the input file stream.

{

Compute the average speed for this part of the trip. Do so by calling your FindAverage

function.

Print to the report.txt file the numbers just read in as well as the average speed on this

leg of the trip.

Read the next line of data from the vacation.txt file.

}


1
Expert's answer
2021-05-01T14:10:48-0400
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;


float FindAverage(float miles,float time){
	return miles/(time/60.0);
}
int main(){
	ifstream ifstreamVacationFile;
	ofstream ofstreamReportFile;
	ifstreamVacationFile.open("vacation.txt");
	ofstreamReportFile.open("report.txt");
	float miles;
	float time;
	//Read the first line of data from the vacation.txt file (the miles traveled and the time in minutes).
	ifstreamVacationFile>>miles>>time;
	// Use here your name for the input file stream.
	while (!ifstreamVacationFile.fail()){
		//Compute the average speed for this part of the trip. Do so by calling your FindAverage function.
		float as=FindAverage(miles,time);
		//Print to the report.txt file the numbers just read in as well as the average speed on this leg of the trip.
		ofstreamReportFile<<fixed<<setprecision(1)<<miles<<" "<<setprecision(1)<< time<<" "<<setprecision(1)<<as<< endl;
		//Read the next line of data from the vacation.txt file.
		ifstreamVacationFile>>miles>>time;
	}
	//close files stream
	ifstreamVacationFile.close();
	ofstreamReportFile.close();


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS