almost done. just need to add last few things. would like it to print in nice neat columns.
1. Create a new project, which consists of one class: the RacingData class.
2. The class should have data members that are used to represent the name of the player, the score achieved, and the time (in both minutes and seconds) taken to achieve this score. The functions in the class should perform the following:
set the name, score, and time
return this same data
print this data
3. Add a default constructor and a constructor with parameters.
1. The class should have an additional function that overloads the + operator, such that when used to add two objects, it will add the scores of each object as well as the time to achieve these scores. It will not check that the names are the same. The result of adding two RacingData objects together should be another RacingData object with combined data. Write the complete implementation for this function.
1. Construct a main method so that it can test the class. This is to be done by creating six objects that are to represent two players, each playing three games.
2. Using the OVERLOADED + OPERATOR, find the average score and time for each player, and print out which performer had the lowest total time and which performer had the highest total score.
#include <iostream>
#include <string>
using namespace std;
int patrickAvg;
int gordonAvg;
int partickTotal;
int gordonTotal;
void racerAverages(int minutes, int seconds, int seconds_sum, int minutes_avg, int seconds_avg);
class RacingData
{
public:
RacingData(string,int,int,int); //constructor with parameters
RacingData(); // default constructor
RacingData operator+(const RacingData& a); // overloaded operator +
void printRacingData(); //displays race results
int score, minutes, seconds;
string racerName;
};
RacingData::RacingData()
{
racerName = " ";
score = 0;//sets score to 0
minutes = 0;//sets minutes to 0
seconds = 0;//sets seconds to 0
}
RacingData RacingData::operator+(const RacingData& a)//Operator + for the class RacingData
{
RacingData res = RacingData();
if (racerName == [login to view URL])// copy name but only if both names are identical
{
[login to view URL] = racerName;
}
[login to view URL] = score + [login to view URL]; // add up all data
[login to view URL] = minutes + [login to view URL]; // add up all data
if (seconds == 0)
{
[login to view URL] = seconds + [login to view URL];
cout << "0" << endl;
}
if ([login to view URL] >= 60)//seconds can not be more than 60
{
[login to view URL] += [login to view URL] / 60;
[login to view URL] = [login to view URL] % 60;
}
return res;
}
RacingData::RacingData(string new_racerName, int new_score, int new_minutes, int new_seconds)
{
racerName = new_racerName;
score = new_score;
minutes = new_minutes;
seconds = new_seconds;
}
void RacingData::printRacingData()
{
cout << racerName << " " << score << " " << minutes << ":" << seconds << "\n";
}
void racerAverages(int minutes, int seconds, int seconds_sum, int minutes_avg, int seconds_avg)//averages racers time
{
seconds_sum = minutes * 60 + seconds;
minutes_avg = seconds_avg / 60;
seconds_avg = seconds_sum / 3 % 60;
}
int main()
{
RacingData patrickRace1("Danica Patrick", 185, 11, 20);//preset data for racers with score, minuts and seconds entered
RacingData patrickRace2("Danica Patrick", 103, 11, 30);//preset data for racers with score, minuts and seconds entered
RacingData patrickRace3("Danica Patrick ", 73, 12 ,40);//preset data for racers with score, minuts and seconds entered
RacingData gordonRace1("Jeff Gordon ", 155, 10, 10);//preset data for racers with score, minuts and seconds entered
RacingData gordonRace2("Jeff Gordon ", 127, 11, 15);//preset data for racers with score, minuts and seconds entered
RacingData gordonRace3("Jeff Gordon ", 34, 12, 35);//preset data for racers with score, minuts and seconds entered
cout << "Race Results Score: Time:\n";
cout << '\n';
[login to view URL]();//prints Patrick race 1
[login to view URL]();//prints Patrick race 2
[login to view URL]();//prints Patrick race 3
cout << '\n';
[login to view URL]();//prints Gordon race 1
[login to view URL]();//prints Gordon race 2
[login to view URL]();//prints Gordon race 3
cout << '\n';
cout << "Total Scores: Score: Time: \n";
cout << '\n';
RacingData patrickTotal = patrickRace1 + patrickRace2 + patrickRace3;//adds Patrick races 1-3 for total
RacingData gordonTotal = gordonRace1 + gordonRace2 + gordonRace3;//adds Gordon races 1-3 for total
cout << "Danica Patrick", [login to view URL]();//prints Patrick totals
cout << "Jeff Gordon ", [login to view URL]();//prints Gordon totals
return 0;
}