Question: Use the class and program provided and COMBINE them. Incorporate the use of overloaded stream ( < < and >>) functions and the overloaded relational

Use the class and program provided and COMBINE them. Incorporate the use of overloaded stream (<< and >>) functions and the overloaded relational Functions. Also, implement a dynamic array of n runners and determine the first 3 positions.

__________Class___________

#include

#include

#include

#include

#include

using namespace std;

class Time

{

public:

Time(); // constructor

void setTime( int, int, int ); // set hour, minute and second

void printUniversal() const; // print time in universal-time format

void printStandard() const; // print time in standard-time format

private:

string name;

unsigned int hour; // 0 - 23 (24-hour clock format)

unsigned int minute; // 0 - 59

unsigned int second; // 0 - 59

}; // end class Time

_____________ program________

int main() { string runner1; // To hold the name of runner 1 string runner2; // To hold the name of runner 2 string runner3; // To hold the name of runner 3

double time1; // To hold the time for runner 3 double time2; // To hold the time for runner 3 double time3; // To hold the time for runner 3

string place1; // To hold the 1st place runner's name string place2; // To hold the 2nd place runner's name string place3; // To hold the 3rd place runner's name

cout << "Enter the names of three runners " << "and their finishing times. "; cout << "I will tell you who came in first, " << "second, and third. ";

// Get the first runner's name. cout << "Name of Runner 1: "; getline(cin, runner1); // Get the first runner's time. cout << "Runner 1's finishing time: "; cin >> time1; cin.ignore();

// Get the second runner's name. cout << " Name of Runner 2: "; getline(cin, runner2); // Get the second runner's time. cout << "Runner 2's finishing time: "; cin >> time2; cin.ignore(); // Get the third runner's name. cout << " Name of Runner 3: "; getline(cin, runner3); // Get the third runner's time. cout << "Runner 3's finishing time: "; cin >> time3;

// Validate the times. if (time1 < 0 || time2 < 0 || time3 < 0) { cout << " Enter positive values only for " << "each runner's time. "; }

// Determine the and display the results. else { // Determine first place finisher. if (time1 < time2 && time1 < time3) place1 = runner1; else if (time2 < time1 && time2 < time3) place1 = runner2; else place1 = runner3;

// Determine second place finisher. if ( (time1 < time2 && time1 > time3) || (time1 > time2 && time1 < time3) ) place2 = runner1; else if ( (time2 < time1 && time2 > time3) || (time2 > time1 && time2 < time3) ) place2 = runner2; else place2 = runner3;

// Determine third place finisher. if (time1 > time2 && time1 > time3) place3 = runner1; else if (time2 > time1 && time2 > time3) place3 = runner2; else place3 = runner3;

// Display the results. cout << endl << place1 << " came in 1st place. " << place2 << " came in 2nd place. " << place3 << " came in 3rd place. "; }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!