#include "stdafx.h" #include #include "AthleteDeclarations.h" using namespace std; // ------------------------------------------------------------------------------------------------------------- // Functions for Question 2. // ------------------------------------------------------------------------------------------------------------- void GetAthleteLapTimes(double athleteLapTimes[][NUM_LAPS], int numAthletes, int numLaps) { cout << "Enter the lap times for each athlete:" << endl; for (int athlete = 0; athlete < numAthletes; athlete++) { for (int lap = 0; lap < numLaps; lap++) { double time; cout << "Athlete " << athlete + 1 << ", lap " << lap + 1 << " time: "; cin >> time; athleteLapTimes[athlete][lap] = time; } } } void DisplayAthleteLapTimes(const double athleteLapTimes[][NUM_LAPS], int numAthletes, int numLaps) { cout << endl << "Lap times for each athlete:"; for (int athlete = 0; athlete < numAthletes; athlete++) { cout << endl << "Athlete " << athlete + 1 << " lap times: "; for (int lap = 0; lap < numLaps; lap++) { cout << athleteLapTimes[athlete][lap] << " "; } } cout << endl; } // ------------------------------------------------------------------------------------------------------------- // Functions for Question 3. // ------------------------------------------------------------------------------------------------------------- void DisplayFinishingTimes(const double athleteLapTimes[][NUM_LAPS], int numAthletes, int numLaps) { cout << endl << "Total finishing times for each athlete: " << endl; for (int athlete = 0; athlete < numAthletes; athlete++) { double athleteTotalTime = 0; for (int lap = 0; lap < numLaps; lap++) { athleteTotalTime += athleteLapTimes[athlete][lap] ; } cout << "Total time for athlete " << athlete + 1 << ": " << athleteTotalTime << endl; } } // ------------------------------------------------------------------------------------------------------------- // Functions for Question 4. // ------------------------------------------------------------------------------------------------------------- void CalculateFinishingTimes(double finishingTimes[], const double athleteLapTimes[][NUM_LAPS], int numAthletes, int numLaps) { for (int athlete = 0; athlete < numAthletes; athlete++) { finishingTimes[athlete] = 0; for (int lap = 0; lap < numLaps; lap++) { finishingTimes[athlete] += athleteLapTimes[athlete][lap]; } } } void SortAndDisplayFinishingTimes(double finishingTimes[], int numAthletes) { cout << endl << "Sorted total finishing times: " << endl; for (int athlete = 0; athlete < numAthletes; athlete++) { for (int others = athlete + 1; others < numAthletes; others++) { if (finishingTimes[athlete] > finishingTimes[others]) { double temp = finishingTimes[others]; finishingTimes[others] = finishingTimes[athlete]; finishingTimes[athlete] = temp; } } } for (int athlete = 0; athlete < numAthletes; athlete++) { cout << finishingTimes[athlete] << endl; } }