Find Jobs
Hire Freelancers

503044 The RacingData Class

N/A

已完成
已发布将近 13 年前

N/A

货到付款
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; }
项目 ID: 2248967

关于此项目

1条提案
远程项目
活跃12 年前

想赚点钱吗?

在Freelancer上竞价的好处

设定您的预算和时间范围
为您的工作获得报酬
简要概述您的提案
免费注册和竞标工作
颁发给:
用户头像
I can help you out with this project. Please PM if interested.
$20 USD 在1天之内
4.8 (9条评论)
3.5
3.5

关于客户

UNITED STATES的国旗
no where, United States
5.0
5
付款方式已验证
会员自5月 15, 2011起

客户认证

谢谢!我们已通过电子邮件向您发送了索取免费积分的链接。
发送电子邮件时出现问题。请再试一次。
已注册用户 发布工作总数
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
加载预览
授予地理位置权限。
您的登录会话已过期而且您已经登出,请再次登录。