#include #include #include #include using namespace std; void sort( int finish[], int pace[], string names[], int count ); void swap( int &num1, int &num2 ); void swap( string &name1, string &name2 ); void readInput(ifstream &in, int totalTime[], int paceTime[], string names[], int &racer); void print( ofstream &out, int totalTime[], int paceTime[], string names[], int racer ); int computeTotalSeconds( int hours, int minutes, int seconds ); const int NUMBEROFRACERS = 100; int main() { ifstream in; ofstream out; in.open("Race.txt"); out.open("summary.txt"); int racer = 0; int totalTime[NUMBEROFRACERS]; int paceTime[NUMBEROFRACERS]; string names[NUMBEROFRACERS]; readInput( in, totalTime, paceTime, names, racer ); sort( totalTime, paceTime, names, racer ); print( out, totalTime, paceTime, names, racer ); in.close(); out.close(); return 0; } void sort( int finish[], int pace[], string names[], int count ) { for ( int pass=0; pass finish[check] ) { min = check; } } swap( finish[pass], finish[min] ); swap( pace[pass], pace[min] ); swap( names[pass], names[pass] ); } } void swap( int &num1, int &num2 ) { int temp = num1; num1 = num2; num2 = temp; } void swap( string &name1, string &name2 ) { string temp = name1; name1 = name2; name2 = name1; } void readInput(ifstream &in, int totalTime[], int paceTime[], string names[], int &racer) { int distanceTenths; int hours; int minutes; int seconds; int totalSeconds; int secondsMile; double distance; char colon; string name; in.ignore( 200, ':' ); in >> distance; in.ignore( 200, '\n' ); in.ignore( 200, '\n' ); distanceTenths = distance * 10; //priming read getline( in, name, '\t' ); in >> hours >> colon >> minutes >> colon >> seconds; in.ignore( 200, '\n' ); while ( in ) { totalSeconds = computeTotalSeconds( hours, minutes, seconds ); secondsMile = 10 * ( (double)totalSeconds / distanceTenths ); if ( racer < NUMBEROFRACERS ) { names[racer] = name; totalTime[racer] = totalSeconds; paceTime[racer] = secondsMile; racer++; } //priming read getline( in, name, '\t' ); in >> hours >> colon >> minutes >> colon >> seconds; in.ignore( 200, '\n' ); } } int computeTotalSeconds( int hours, int minutes, int seconds ) { int totalSeconds; totalSeconds = hours * 3600 + minutes * 60 + seconds; return totalSeconds; } void print( ofstream &out, int totalTime[], int paceTime[], string names[], int racer ) { int paceMinute; int paceSecond; char colon = ':'; out << left << setw(20) << "Name" << right << setw(13) << "Time" << setw(15) << "Pace" << endl; for( int i=0; i<49; i++) out << "="; out <