The Racingdata Class

Program Title: The RacingData Class

In a racing car game a RacingData class is used to represent the outcome of a certain race. In this lab you will create this class with its appropriate attributes and functions. You will then overload the + operator to work with this class. Finally you will create a small main() program to test your work.

STEP 1: Create a New Project

Create a new project which consists of one class; the RacingData class.

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
Also add a default constructor and a constructor with parameters.

Operator Overloading: 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.

STEP 2: Construct Main Method

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. Use the following data to construct the six objects:

Name Score Minutes Seconds
Danica Patrick 185 11 20
Danica Patrick 103 11 30
Danica Patrick 73 12 40
Jeff Gordon 155 10 10
Jeff Gordon 127 11 15
Jeff Gordon 34 12 35

USING THE OVERLOADED + OPERATOR, find the average score and time for each player and print out which performer had to lowest total time and which performer had the highest total score.

I have attached a copy of the grading criteria in Excel format, and the pseudocode for project is posted below:

class RacingData
{
public:
constructor to handle all four private variables
default constructor since we have a parameter constructor
function to set the private variables
function(s) to get the private variables (may be able to use one function if using pass by reference)
function to print the contents of the private variables
function to overload the + operator, taking two objects, and return a new object

private:
string to hold the driver name
int to hold the score
int to hold the minutes
int to hold the seconds
}

Functions outside of class:
function to find highest scorer between two objects and return a new object
function to find lowest time between two objects and return a new object
function to print the averages score of an object

main:
instantiate 6 objects for each score
set initial data
instantiate 2 objects for each player
total first player’s scores using overloaded operator + and display average
total second player’s scores using overloaded operator + and display average
instantiate 1 object for the winner
find highest scorer between two players and display winner
find lowest time between two players and display winner

Leave a Reply

Your email address will not be published. Required fields are marked *