Devam Ediyor

503044 The RacingData Class

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 == [url removed, login to view])// copy name but only if both names are identical

{

[url removed, login to view] = racerName;

}

[url removed, login to view] = score + [url removed, login to view]; // add up all data

[url removed, login to view] = minutes + [url removed, login to view]; // add up all data

if (seconds == 0)

{

[url removed, login to view] = seconds + [url removed, login to view];

cout << "0" << endl;

}

if ([url removed, login to view] >= 60)//seconds can not be more than 60

{

[url removed, login to view] += [url removed, login to view] / 60;

[url removed, login to view] = [url removed, login to view] % 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';

[url removed, login to view]();//prints Patrick race 1

[url removed, login to view]();//prints Patrick race 2

[url removed, login to view]();//prints Patrick race 3

cout << '\n';

[url removed, login to view]();//prints Gordon race 1

[url removed, login to view]();//prints Gordon race 2

[url removed, login to view]();//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", [url removed, login to view]();//prints Patrick totals

cout << "Jeff Gordon ", [url removed, login to view]();//prints Gordon totals

return 0;

}

Beceriler: Her şey Kabul, C Programlama

Daha fazlasını görün: string the, string find c, public programming, programming operator, programming class, find the operator, c programming string functions, c programming operator, c programming function to find the average, c programming find function, c programming class, combined result, class programming, class in programming, score score, find operator, the time, std, performer, Patrick, jeff, gordon, find new programming, endl, time class

İşveren Hakkında:
( 5 değerlendirme ) no where, United States

Proje NO: #2248967

Seçilen:

Algotrade

I can help you out with this project. Please PM if interested.

1 gün içinde 20$ USD
(9 Değerlendirme)
3.5