[SOLVED] CENG242 Homework3

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon hw3-mtd80z.zip (547.7 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
Rate this product

This homework aims to help you get familiar with the fundamental C++ programming concepts.

Keywords: Constructor/Copy Constructor/Destructor, Assignment/Move, Operator Overloading, Memory Management

1Β Β Β Β Β Β Β Β Β Β Β Β  Problem Definition

TL;DR: Implement the methods in the given 4 classes (Laptime, Car, Race, Championship). Cars have Laptimes, Races have Cars, Championships have Races. The details are on their way.

Another TA who watched Drive to Survive

…

Oh God show mercy to this boring soul.

F1 needs a new clear backbone for their visualisation system. As a Computer Engineering student from METU, they trusted you with the task. Your task is to keep track of the laptimes, cars, races and tracks. As situation requested shiny features of the latest C++ is not available to you. Therefore, you have to be careful with your programs memory management (You do not want to leave a program that is leaking memory as your legacy).

2Β Β Β Β Β Β Β Β Β Β Β Β  Class Definitions

2.1Β Β Β Β Β Β Β Β Β Β  Laptime

Laptime is the most basic class in this homework. Basically, it’s the node in a linked-list which would keep the time information of the laps for each Car (not the best way to keep lap times of Cars, but let’s assume F1 is not paying you anything and you let this go).

class Laptime {

private :

int laptime;

Laptime βˆ—next;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PRIVATE METHODS/PROPERTIES BELOW

public :

/βˆ—βˆ— βˆ— Constructor .

βˆ—

βˆ— @param intΒ Β Β Β Β Β  valueΒ Β Β Β  inΒ Β Β Β Β  laptime .

βˆ—/

Laptime( int laptime) ;

/βˆ—βˆ— βˆ— Copy Constructor .

βˆ—

βˆ— @param rhs The laptime to be copied .

βˆ—/

Laptime( const Laptime& rhs) ;

˜Laptime() ;

/βˆ—βˆ—

βˆ— Sets the next chainΒ Β Β Β Β Β Β Β Β Β Β Β  forΒ Β Β Β Β Β Β  this Laptime .

βˆ— You shouldΒ Β Β Β Β Β Β Β Β Β  insertΒ Β Β Β  the given Laptime to theΒ  object which the method is ←called upon

βˆ—

βˆ— @param next The next Laptime .

βˆ—/ void addLaptime(Laptime βˆ—next) ;

/βˆ—βˆ— βˆ— Less than overload .

βˆ—

βˆ— TrueΒ Β Β Β  i fΒ Β Β Β Β Β Β  this LaptimeΒ Β Β Β Β Β Β  lessΒ Β Β Β Β Β Β Β Β Β  than the rhs Laptime .

βˆ—

βˆ— @param rhs The Laptime to compare . βˆ— @return True i f this laptime is smaller , false otherwise .

βˆ—/ bool operator <(const Laptime& rhs) const ;

/βˆ—βˆ—

βˆ— Greater than overload .

βˆ—

βˆ— TrueΒ Β Β Β  i fΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  this Laptime greater than the rhs Laptime .

βˆ—

βˆ— @param rhs The Laptime to compare .

βˆ— @return TrueΒ Β Β Β Β Β Β Β Β Β Β Β Β  i fΒ Β Β Β  thisΒ Β Β Β Β Β  laptimeΒ Β Β Β Β Β Β Β Β  is bigger ,Β Β Β Β Β Β Β Β Β Β Β Β Β Β  false otherwise .
βˆ—/ Β 
bool

/βˆ—βˆ—

operator >(const Laptime& rhs) const ; Β 
βˆ—

βˆ—

Plus overload Β  Β 
βˆ—

βˆ—

Add two Laptime and return the lhs Laptime Β 
βˆ— @param Laptime to add Β  Β 
βˆ— @returns Summation ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  the two laptime Β 
βˆ—/

Laptime& operator+(const Laptime& rhs) ;

/βˆ—βˆ— βˆ— Stream overload .

βˆ—

βˆ— What to stream :

βˆ— minute : second . miliseconds βˆ—

βˆ— Example :

βˆ— @important Your laptimeΒ Β Β Β Β Β Β Β Β Β Β Β  variableΒ Β Β Β Β Β  isΒ Β Β Β Β Β Β  representationΒ Β Β Β Β Β Β Β Β Β  in terms ofΒ Β Β Β Β Β Β Β Β  miliseconds

βˆ— and you have to turnΒ Β Β Β Β Β Β Β Β Β Β  itΒ Β Β Β  toΒ Β Β Β Β Β Β Β Β  desired outcome type

βˆ— Print the Laptime ofΒ Β Β Β Β Β Β Β Β Β Β  theΒ Β Β Β Β Β Β Β Β Β Β Β  object which the method isΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β  called upon .

βˆ— @param os Stream to be used .

βˆ— @param laptime Laptime to be streamed . βˆ— @return The current Stream .

βˆ—/ friend std : : ostream& operator <<(std : : ostream& os,Β Β Β Β Β Β Β  const Laptime& laptime) ;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PUBLIC METHODS/PROPERTIES BELOW

};

2.2Β Β Β Β Β Β Β Β Β Β  Cars

Cars are similar to Laptimes, but they contain the name of the driver which is up to you (LeClerc can be a good start. Bahrain 2019 :/ ). It is again a node in a linked-list, but every car contains the linked-list of Laptime class (Memory Problems 2019).

class Car {

private :

std : : string driver_name;

double performance;

Laptime βˆ—head;

Car βˆ—next;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PRIVATE METHODS/PROPERTIES BELOW

public :

/βˆ—βˆ— βˆ— Constructor .

βˆ—

βˆ— @Important :Β Β Β Β Β  setΒ Β Β Β Β Β Β Β Β Β  the performanceΒ  variable ofΒ Β Β Β Β Β Β Β Β Β Β  the car by usingΒ  Utilizer : : ←generatePerformance ()

βˆ—

βˆ— @param std : : string The Car β€˜ sΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  driver name.

βˆ—/

Car(std : : string driver_name) ;

/βˆ—βˆ— βˆ— Copy Constructor .

βˆ—

Β 
βˆ— @param rhs The car to be

βˆ—/

Car( const Car& rhs) ;

˜Car() ;

/βˆ—βˆ—

βˆ— Gets theΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  drivers name

βˆ—

βˆ—

βˆ— @returns :Β Β Β Β Β Β Β Β Β Β Β Β Β Β  drivers name

βˆ—/

copied .
std : : string getDriverName()

/βˆ—βˆ—

const ;

Gets the performance

βˆ— @returns the performance

βˆ—

βˆ—/ double getPerformance()Β Β Β Β Β Β Β Β  const ;

/βˆ—βˆ—

βˆ— Sets the next chainΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  forΒ Β Β Β Β Β  this Car .

βˆ— Adds a new car behindΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  existingΒ Β Β Β Β Β  car

Β  Β  Β  Β  Β  Β 
βˆ— You shouldΒ Β Β Β  insertΒ Β Β Β  the givenΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  Car to upon

βˆ— Important : Car does NOT ”own” next .

the object which the method is called ←–

βˆ—

βˆ— @param next The next Car .

βˆ—/ void addCar(Car βˆ—next) ;

/βˆ—βˆ— βˆ— Less than overload .

βˆ—

βˆ— TrueΒ Β Β Β  i fΒ Β Β Β  totalΒ Β Β Β Β Β  laptimeΒ Β Β Β Β  ofΒ Β Β Β Β Β Β Β  this Car isΒ Β Β Β Β Β Β Β Β  lessΒ Β Β Β Β Β Β Β Β Β  than the rhs Car .

βˆ—

βˆ— Important :

βˆ—

βˆ— @param rhs The Car to compare . βˆ— @return True i f this car β€˜ s total laptime is smaller , false otherwise .

βˆ—/ bool operator <(const Car& rhs) const ;

/βˆ—βˆ— βˆ— Greater than overload .

βˆ—

βˆ— TrueΒ Β Β Β  i fΒ Β Β Β  totalΒ Β Β Β Β Β  laptimeΒ Β Β Β Β  ofΒ Β Β Β Β Β Β Β  this Car isΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  greater than the rhs Car .

βˆ—

βˆ— Important :

βˆ—

βˆ— @param rhs The Car to compare . βˆ— @return True i f this car β€˜ s total laptime is greater , false otherwise .

βˆ—/ bool operator >(const Car& rhs) const ;

/βˆ—βˆ— βˆ— Indexing .

βˆ—

βˆ— Find the laptimeΒ Β Β Β Β Β Β Β Β  ofΒ Β Β Β Β Β Β Β  the given lap .

βˆ— You willΒ Β Β Β Β Β Β Β Β Β Β Β Β  use 0 based indexing .

βˆ— For example , after 20 lap your car should have 20 laptimes . To get 15th ←laptime you will give 14 as the input parameter .

βˆ—

βˆ— @return The Laptime with the given lap . Laptime with zero time i f given ←lap does not exists .

βˆ—/

Laptime operator [ ] ( constΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β  int lap) const ;

/βˆ—βˆ—

βˆ— Car completes one lap and recordsΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  itsΒ Β Β Β Β Β  laptime

βˆ—

βˆ— @Important : Based on your cars performance calculate some variance to add ←averagelaptime

βˆ— Use Utilizer : : generateLaptimeVariance ( performance ) then add it to ←averagelaptime

βˆ— Β  Β  Β 
βˆ— @param: Car takesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  average laptimeΒ Β Β Β Β Β  ofΒ Β Β Β Β Β Β  the

βˆ—

βˆ—/ void Lap( const Laptime& average_laptime) ;

/βˆ—βˆ— βˆ— Stream overload .

βˆ—

βˆ— What to stream :

race Β  Β 
βˆ— First Three letters of the drivers surname( Capitalized )βˆ’βˆ’Latest Fastest Laptimeβˆ’βˆ’Total Laptime βˆ— Example :

βˆ— For Lewis Hamilton

Laptimeβˆ’βˆ’β†β€“ Β 
Β  βˆ— HAMβˆ’βˆ’1:19.235βˆ’βˆ’1:18.832βˆ’βˆ’90:03.312

βˆ—

Β  Β 
Β  βˆ— @Important : for lap numbers smaller in size you have to put as neccasary

βˆ— @Important : you can use Laptime ostream when neccessary

βˆ—

βˆ— @param os Stream to be used .

βˆ— @param car Car to be streamed .

zeros as much ←–

βˆ— @return The current Stream .

βˆ—/ friend std : : ostream& operator <<(std : : ostream& os,Β Β Β Β Β Β Β  const Car& car) ;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PUBLIC METHODS/PROPERTIES BELOW

};

2.3Β Β Β Β Β Β Β Β Β Β  Race

Race keeps a linked-list of Cars. You have to keep your cars in the order from fastest to slowest (Nobody wants to see some randomly ordered car info). The details are in the code itself below:

class Race {

private :

std : : string race_name;

Laptime average_laptime; Car βˆ—head;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PRIVATE METHODS/PROPERTIES BELOW

public :

/βˆ—βˆ— βˆ— Constructor .

βˆ—

βˆ— @Important : Generate average laptime by using Utilizer : : ←generateAverageLaptime () βˆ—

βˆ— @param std : : string The name ofΒ Β Β Β Β Β Β Β Β Β Β Β Β  the Race .

βˆ—/ Race(std : : string race_name) ; /βˆ—βˆ— βˆ— Copy Constructor .

βˆ—

βˆ— @Important just copy the names and performances of the cars βˆ— without any laptime . βˆ— Cars should be deep copied

βˆ—

βˆ— @param rhs The race to be copied .

βˆ—/

Race( const Race& rhs) ;

˜Race() ; std : : string getRaceName() const ; /βˆ—βˆ—

βˆ— Add a new car to race .

βˆ—

βˆ— @Important : At theΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  startΒ Β Β Β Β  ofΒ Β Β Β Β  the raceΒ Β Β Β Β Β Β  theirΒ Β Β Β Β Β Β Β Β Β  ordering

βˆ—

isΒ Β Β Β Β Β Β Β Β Β Β  not important
βˆ— No parameter means that you willΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  generate your own carΒ Β Β Β  in Β 
βˆ— thisΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  function ( with a random name)and add itΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  to your

βˆ—/

void addCartoRace() ;

/βˆ—βˆ—

βˆ— Add a new car to race .

βˆ—

Cars Β 
βˆ— @Important : At theΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  startΒ Β Β Β Β  ofΒ Β Β Β Β  the raceΒ Β Β Β Β Β Β  theirΒ Β Β Β Β Β Β Β Β Β  ordering isΒ Β Β Β Β Β Β Β Β Β Β  not important

βˆ—

βˆ— @param:Β Β Β Β Β Β Β Β Β Β Β  car Add given Car toΒ Β Β Β Β Β Β Β Β Β Β  others

βˆ—/ void addCartoRace(Car& car) ;

/βˆ—βˆ—

βˆ— Information About how much carΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  isΒ Β Β Β Β Β Β Β  in the race

βˆ—

βˆ— @returns number ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  cars

βˆ—

βˆ—/ int getNumberOfCarsinRace() ;

/βˆ—βˆ—

βˆ— Return stateΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  ofΒ Β Β Β Β Β Β  everything toΒ Β Β Β Β Β Β Β  desiredΒ Β Β Β Β  lap β€˜ sΒ Β Β Β Β  state

βˆ—

Β  Β  Β 
βˆ— Your Race willΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  have many lapsΒ Β  in the courseΒ Β Β Β Β Β Β  ofΒ Β Β Β Β Β Β Β Β Β Β  its carsΒ  willΒ Β Β Β Β Β Β Β  have new Laptimes etc . l i f e . In each lap , your←–
βˆ— For example , i f you have 20 Laps in your Race , but redo last 10 laps of it . By using goBacktoLap , let β€˜ s say you want to ←–
βˆ— you willΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  take your Race back to 10th Lap.Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  ThisΒ Β Β Β Β Β  will also make changes in ←–
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  your Cars . Your carsΒ Β Β Β Β Β Β Β Β Β Β  willΒ Β Β Β Β Β Β Β Β Β Β Β  have only the informationΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β  of theΒ Β Β Β  f i r s tΒ Β Β Β Β  10 laps .
βˆ— Lap numbers start from zero . If 5 is given as int lap , you will take back to 6th lap .

βˆ— @Important :Β Β Β Β Β Β Β Β Β Β Β Β  thisΒ Β Β Β Β  willΒ Β Β Β Β  alsoΒ Β Β Β Β Β  apply toΒ Β Β Β Β Β Β Β Β Β Β Β Β  cars and leaderboard too

βˆ—

Race ←–

βˆ— @param lap to return

βˆ—

βˆ—/ void goBacktoLap( int lap) ;

/βˆ—βˆ—

βˆ— PrefixΒ Β Β Β Β Β Β Β  additionΒ Β Β Β Β Β Β  overload

βˆ—

βˆ— add one more lap toΒ Β Β Β Β Β Β Β Β Β Β  allΒ Β Β Β Β  cars

βˆ—

βˆ— @Important : Update the order of the cars so that the fastest one stays at ←the front

βˆ—

βˆ—/ void operator++(); /βˆ—βˆ—

βˆ—Β Β Β Β Β Β Β Β Β Β Β Β Β  Prefix decrement overload

βˆ—

βˆ— remove one lap fromΒ Β Β Β Β Β Β Β Β Β  allΒ Β Β Β Β  cars

βˆ—

βˆ— @Important : Update the order of the cars the front

βˆ—

βˆ—/ void operator βˆ’βˆ’();

/βˆ—βˆ—

βˆ—

βˆ— IndexingΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  overload

βˆ—

so that theΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  fastest one staysΒ Β Β Β Β Β Β Β Β Β Β Β Β  at ←–
βˆ— This function willΒ Β Β Β Β Β Β Β  not be testedΒ Β Β Β Β Β Β  forΒ Β Β Β Β Β Β Β Β Β  the positionΒ Β Β  does notΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β  exist .

βˆ—

casesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  in which Car in given ←–
βˆ— @param:Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  car in position Car in the given position Β  Β 
βˆ— @returns the carΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  in theΒ Β Β Β Β Β  desiredΒ Β Β Β Β Β Β Β Β Β Β Β Β  position

βˆ—/

Car operator [ ] ( constΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  int car_in_position) ;

/βˆ—βˆ—

βˆ—

βˆ— IndexingΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  overload

βˆ—

in the currentΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  lap Β  Β 
βˆ— This function will not be tested for the driver name does not exist .

βˆ—

casesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  in which Car with given ←–
βˆ— @param:Β Β Β Β Β Β Β Β Β Β  driver nameΒ Β Β Β Β Β Β Β  driver β€˜ s name ofΒ Β Β Β Β Β Β Β Β Β Β Β  the desiredΒ Β Β Β Β Β Β  car Β 

βˆ— @returns the car whose driver named as the given @param

βˆ—/ Car operator [ ] ( std : : string driver_name) ;

/βˆ—βˆ—

βˆ— Assignment

βˆ—

βˆ— @param rhs The Race toΒ Β Β Β Β Β Β Β Β Β Β  assignΒ Β Β Β Β  intoΒ Β Β Β Β  thisΒ Β Β Β Β  race

βˆ— @return The assigned Race

βˆ—/

Race& operator=(const Race& rhs) ;

/βˆ—βˆ— βˆ— Stream overload .

βˆ—

βˆ— What to stream :

βˆ— Positionβˆ’βˆ’βˆ—Driver Name( leader of the race )βˆ’βˆ’Latest Laptimeβˆ’βˆ’Fastest ←Laptime of the Driverβˆ’βˆ’Sum of Laptimes( in display Laptime format )βˆ’βˆ’Points β†βˆ’βˆ’ExtraPoint ( If applicable ) βˆ— . . .

βˆ— Positionβˆ’βˆ’βˆ—Driver Name( lastΒ Β Β Β Β Β Β Β Β Β Β Β  placeΒ Β Β Β  ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  the race )βˆ’βˆ’Latest Laptimeβˆ’βˆ’Fastest ←–

Laptime ofΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  the Driverβˆ’βˆ’Sum of Laptimes( inΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  display Laptime format )βˆ’βˆ’Points ←–

βˆ’βˆ’ExtraPoint ( IfΒ Β Β Β Β Β Β Β Β Β  applicable )

βˆ— βˆ— Example : βˆ— 001βˆ’βˆ’TUFβˆ’βˆ’1:19.461βˆ’βˆ’1:18.935βˆ’βˆ’60:35.193βˆ’βˆ’25

βˆ— 002βˆ’βˆ’UTAβˆ’βˆ’1:19.335βˆ’βˆ’1:18.335βˆ’βˆ’60:37.321βˆ’βˆ’18βˆ’βˆ’1 βˆ— 003βˆ’βˆ’GRTβˆ’βˆ’1:20.223βˆ’βˆ’1:19.932βˆ’βˆ’60:45.184βˆ’βˆ’15 βˆ— . . .

βˆ— 099βˆ’βˆ’CEIβˆ’βˆ’1:21.005βˆ’βˆ’1:19.867βˆ’βˆ’63:47.293

βˆ— 100βˆ’βˆ’ECHβˆ’βˆ’1:23.213βˆ’βˆ’1:21.331βˆ’βˆ’64:00.123

βˆ—

βˆ— @Important : for driver numbers smaller in size you have to put zeros as ←much as neccasary to their beginning

βˆ— Example :Β Β Β Β Β  i fΒ Β Β Β  thereΒ Β Β Β Β  isΒ Β Β Β Β Β  11 racersΒ Β Β Β Β Β  f i r s tΒ Β Β Β Β  positionΒ Β Β Β Β Β Β Β  should be 01

βˆ— @Important . you can use Laptime ostream when neccessary

βˆ— @Important : You should order theΒ Β Β Β Β Β Β Β Β Β Β Β Β Β  racersΒ Β Β Β Β Β Β Β  according toΒ Β Β Β Β Β Β  theirΒ Β Β Β Β Β  totalΒ Β Β Β Β Β  laptime

βˆ— @Important :Β Β Β Β Β Β Β Β Β Β Β Β Β  There are two differentΒ Β Β Β Β Β Β Β Β Β Β Β  pointΒ Β Β Β Β  typesΒ Β Β Β Β Β  for F1

βˆ— First one is the Fastest Lap point which is 1 point and it is given the ←fastest car i f it is in top 10

βˆ— Other one is normal racing points and they are 25βˆ’18βˆ’15βˆ’12βˆ’10βˆ’8βˆ’6βˆ’4βˆ’2βˆ’1 in←this order

βˆ—

βˆ— @param os Stream to be used .

βˆ— @param car Car to be streamed . βˆ— @return The current Stream .

βˆ—/ friend std : : ostream& operator <<(std : : ostream& os,Β Β Β Β Β Β Β  const Race& race) ;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PUBLIC METHODS/PROPERTIES BELOW

};

2.4Β Β Β Β Β Β Β Β Β Β  Championship

Championship is the final part of this homework. They keep races with different names. Championship.

class Championship { private : std : : vector< Race > races;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PRIVATE METHODS/PROPERTIES BELOW

public :

/βˆ—βˆ— βˆ— Constructor .

βˆ—

βˆ—/ Championship() ; /βˆ—βˆ— βˆ— Copy Constructor .

βˆ—

βˆ— @param rhs The Championship to be copied .

βˆ—/

Championship( const Championship& rhs) ;

˜Championship() ;

/βˆ—βˆ— βˆ— Add a new Race to Championship .

βˆ—

βˆ— @Important :Β Β Β Β Β Β Β Β  Purpose ofΒ Β Β Β Β Β Β  thisΒ Β Β Β Β Β  functionΒ Β Β Β Β Β  isΒ Β Β Β Β Β  to add theΒ Β Β Β Β Β  f i r s tΒ Β Β Β  race .

βˆ—

βˆ— @param race Race to add

βˆ—/ void addNewRace(Race& race) ;

/βˆ—βˆ— βˆ— Add a new Race to Championship .

βˆ—

βˆ— @Important : You willΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  use getAverageLaptime functionΒ Β Β Β Β Β Β Β Β Β Β Β  forΒ Β Β Β Β  this

βˆ— @Important : You can use copy constructorΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  ofΒ Β Β Β Β Β Β Β  the Race classΒ Β Β Β Β Β Β Β  inΒ Β Β Β  order

βˆ— to just copy driver names for your new Race βˆ— @Important : Driver names should be same for each race

βˆ—

βˆ— @param race name create a new race with given name

βˆ—/

void addNewRace(std : : string race_name) ;

/βˆ—βˆ—

βˆ— Remove race from by usingΒ Β Β Β Β Β Β Β Β Β Β Β Β  its name

βˆ—

βˆ— @param race name remove race from championship

βˆ—

βˆ—/ void removeRace(std : : string race_name) ;

/βˆ—βˆ—

βˆ—

βˆ— Add lap to race with the given name

βˆ—

βˆ— @param race name you willΒ Β Β Β Β Β Β Β Β Β  findΒ Β Β Β Β Β Β Β  the race withΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  this name and add a lap toΒ Β Β Β Β Β Β Β Β Β Β Β Β  it

βˆ—/ void addLap(std : : string race_name) ;

/βˆ—βˆ—

βˆ—

βˆ— IndexingΒ Β Β Β Β Β Β Β  overload

βˆ—

βˆ—

βˆ— @param: race name βˆ— @returns the desired Race

βˆ—/

Race operator [ ] ( std : : string race_name) ;

/βˆ—βˆ—

βˆ— Stream overload .

βˆ—

βˆ— What to stream :

βˆ— Championship Results

Β  Β  Β  Β 
βˆ— Driver Surname f i r s t βˆ— . . . three letters in capital (from winner )βˆ’βˆ’Total Points
βˆ— Driver SurnameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β  f i r s t

βˆ—

βˆ— Example :

βˆ— Championship Results

βˆ— 01βˆ’RAIβˆ’βˆ’194

βˆ— 02βˆ’HAMβˆ’βˆ’190

βˆ— 03βˆ’LECβˆ’βˆ’100

βˆ— 77βˆ’OCOβˆ’βˆ’60

βˆ— 78βˆ’RICβˆ’βˆ’1

βˆ— 79βˆ’GROβˆ’βˆ’0

βˆ—

three letters in capital ( toΒ Β Β Β Β Β Β Β Β  lastΒ Β Β Β Β Β Β Β Β Β  place )βˆ’βˆ’Total Points
βˆ— @Important : for driver placements numbers smaller in size you have to put ←zeros as much as neccasary to their start

βˆ— Example : i f there is 111 racers f i r s t position should be 001 βˆ— @Important : You will order drivers according to their total points

βˆ—

βˆ— @param os Stream to be used .

βˆ— @param car Car to be streamed .

βˆ— @return The current Stream .

βˆ—/ friend std : : ostream& operator <<(std : : ostream& os, const Championship& ←championship) ;

// DO NOT MODIFY THE UPPER PART

// ADD OWN PUBLIC METHODS/PROPERTIES BELOW

};

3Β Β Β Β Β Β Β Β Β Β Β Β  Extras

While generating Cars you need to produce random double value for its performance. To do this, you MUST use Utilizer class. It’ll return random small double numbers.

The implementation of the the Utilizer is already provided to you. Hence, you just need to do this:

double performance = Utilizer : : generatePerformance() ;

You also MUST use Utilizer::generateLaptimeVariance() for generating a difference to average laptime. After that you will add this to calculate laptime of the car (You will do this for every lap). For generating average laptimes of the Races you again MUST use Utilizer::generateAverageLaptime() function which will return an integer value (You will turn it to Laptime class).

The summary of the memory ownership:

  • A Laptime WILL NOT own its nextLaptime.
  • A Car WILL NOT own its nextCar.
  • A Car WILL own the headLaptime when constructed with.
  • A Race WILL own the headCar.
  • CopyConstructers WILL not yield ownership of the old variables.
  • assignment operator ”=” WILL yield ownership of the old variables.
  • Owning a Car/Laptime also means owning the nextCar/nextLaptime, and the nextCar/nextLaptim of the nextCar/nextLaptime, …
  • hw3-mtd80z.zip