(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.
}
#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;
}
Comments
Leave a comment