Question: Need help! Need a code for this problem. Write a program that reads four triathlon race time records from a file. The name of the
Need help!
Need a code for this problem.
Write a program that reads four triathlon race time records from a file. The name of the file is racedat.txt. Each line of the file represents one record and contains an athlete identifier (a single character) and three numeric values. The three values are the completion times (in minutes) for the running, swimming, and biking stages of a triathlon. You will produce a nicely formatted report that displays these values, as well as the total time for each athlete. Finally, your report should calculate the average total time for the race.
Hint: You can create your own racedat.txt file using Windows Notepad or other text editor.
Your input file should have the format:
A 31 27 52
B 29 31 58
C 35 36 51
D 34 36 62
******** Turn in copy of Program, input file and output file.
this is code
#include
#include
#include
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
int running, swimming, biking, total;
double average;
char identifier;
infile.open("racedat");
if (!infile.is_open()) {
cout << "Could not open file racedat" << endl;
return 1;
//These are the variables bing inputed into the file
infile >> identifier >> running >> swimming >> biking;
infile >> identifier;
infile >> running;
infile >> swimming;
infile >> biking;
//this is them being displayed on the file
outfile << "Athlete Identifier:" << identifier << endl;
outfile << "Athlete Running:" << running << endl;
outfile << "Athlete Swimming:" << swimming << endl;
outfile << "Athlete Biking:" << biking << endl;
total = running + swimming + biking;
outfile << "Total Time:" << total << endl;
outfile << setprecision(3);
outfile << "Average Time:" << (total / 3) << endl;
outfile.open("result.txt"); {
//outfile
outfile.close();
}
}
system("pause");
return 0;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
