In this project, you will:
A motorsport is a global term used to encompass the group of competitive sporting events which primarily involve the use of motorized vehicles prominently used in racing. The top racers in the world earn more than $38M each year (and drive Formula One cars). For this project, we are going to create a racing simulator where the user can compete Racecars, Trucks, or Formula One in multi-lap races. You can picture the racers using a track like the track displayed below (which is used for a variety of styles of races).
This project requires a special data structure, an Lqueue, that we are going to build using a linked list. The Lqueue is a templated data structure that is designed to handle most types of data which is first-in, first-out (FIFO). This structure will be used to keep track of what order every racer is in.
Class 1 Lqueue This is a very important class. It is used to manage the racers. It uses a linked list to store the information about whatever it is designed to hold (in this case Racers more specifically a subclass of either Racecar, Truck, or Formula). As a linked list, is uses templated nodes to store data. For this project, the data in every node must be private. You will need to implement normal queue functions such as Push (which inserts in the end), Pop (which removes from front), Display(which displays data in each node), Front(which returns the first element in the queue), Swap (which swaps two nodes), RemoveInsertEnd(which removes a node and moves it to the end), and Clear (which removes all nodes from the lqueue). Finally, you must implement the copy constructor and assignment operator in this class. There should be absolutely NO references to racer, racecar, truck, formula or race in this class.
You should implement this class by itself and then test it completely before using it. Do not forget how we must implement templated classes!
Class 2: Racer This is a trivial parent class with little more than a very simple constructor, setters, getters, and an overloaded << function (which must be implemented in the three subclasses). The overloaded << operator and the toString function are very similar to project 4. They are used to be able to output a racer (or either subclass).
Classes 3, 4, and 5: Racecar/Truck/Formula These are the three subclasses to Racer. They are very similar to each other except that the overloaded << operator displays something different. The other function is an overridden toString that displays information about the Racer.
Class 5: Race This is the class that manages the race. It is templated as a race can be with any one of the three racers (Racecar, Truck, or Formula). It is called directly from driver.cpp. There are no data files for this project everything is stored in two arrays included in Race.h. A race can have between 2 and 100 racers. Each race can have any number of laps between 1 and 1000. When the race starts, the Lqueue is populated with a static (no dynamically allocated racers) number of racers. The racers are displayed with their numbers. Racecars start at 200mph, Trucks start at 150mph, and Formula start at 220mph. Each lap, a car has a 1 in 200 chance of crashing. If a car crashes, it is moved to the end of the lqueue (indicating it is in last place), has a new speed of 0, and is updated to indicate that it has crashed. For all cars that havent crashed, a new current speed is calculated based on their current speed. Each lap, a racers current speed can increase or decrease 15% either direction (minimum 0 mph but no upper limit). (Yes, it can make cars go impossibly fast!) After the new speed is calculated, the current speed of a racer is compared to each racer directly before and after it. If a racer has a higher speed, the racers are swapped (indicating a new order).
This is a list of the requirements of this application. For you to earn all the points you will need to meet all the defined requirements.
For this project, there are no input files. Command line arguments have been included (as well as the makefile) so you can use make run or make val to test your code.
Races with one or two racers are relatively short so they are listed below. Longer runs are included:
/afs/.edu/users/j/d/j/pub/cs202/proj5/
They are called proj5_sample1.txt and proj5_sample2.txt. Below is a sample with four Trucks for 10 laps:
./proj5
What type of vehicle would you like to race?
1. Cars
2. Trucks
3. Formula 1
4. Exit
2
How many racers would you like in the race?
4
Pole Positions
Truck Fletcher (#6) going 150MPH
Truck Baird (#58) going 150MPH
Truck Whitley (#17) going 150MPH
Truck Palmer (#79) going 150MPH
How many laps would you like to do?
10
Lap 1
Truck Fletcher (#6) going 156MPH
Truck Whitley (#17) going 163MPH
Truck Baird (#58) going 153MPH
Truck Palmer (#79) going 144MPH
Lap 2
Truck Whitley (#17) going 156MPH
Truck Baird (#58) going 169MPH
Truck Fletcher (#6) going 154MPH
Truck Palmer (#79) going 131MPH
Lap 3
Truck Baird (#58) going 184MPH
Truck Fletcher (#6) going 163MPH
Truck Palmer (#79) going 145MPH
Truck Whitley (#17) going 134MPH
Lap 4
Truck Fletcher (#6) going 177MPH
Truck Baird (#58) going 158MPH
Truck Palmer (#79) going 142MPH
Truck Whitley (#17) going 116MPH
Lap 5
Truck Fletcher (#6) going 192MPH
Truck Baird (#58) going 170MPH
Truck Palmer (#79) going 133MPH
Truck Whitley (#17) going 128MPH
Lap 6
Truck Baird (#58) going 185MPH
Truck Fletcher (#6) going 174MPH
Truck Whitley (#17) going 144MPH
Truck Palmer (#79) going 129MPH
Lap 7
CRASH!!! Truck Fletcher crashed and is out of the race.
Truck Baird (#58) going 157MPH
Truck Whitley (#17) going 144MPH
Truck Palmer (#79) going 141MPH
Truck Fletcher crashed and is out of the race.
Lap 8
Truck Whitley (#17) going 161MPH
Truck Baird (#58) going 160MPH
Truck Palmer (#79) going 156MPH
Truck Fletcher crashed and is out of the race.
Lap 9
Truck Baird (#58) going 179MPH
Truck Whitley (#17) going 165MPH
Truck Palmer (#79) going 162MPH
Truck Fletcher crashed and is out of the race.
Lap 10
Truck Baird (#58) going 189MPH
Truck Whitley (#17) going 174MPH
Truck Palmer (#79) going 145MPH
Truck Fletcher crashed and is out of the race.
The winner of the race is Truck Baird (#58) going 189MPH
What type of vehicle would you like to race?
1. Cars
2. Trucks
3. Formula 1
4. Exit
./proj5
What type of vehicle would you like to race?
1. Cars
2. Trucks
3. Formula 1
4. Exit
1
How many racers would you like in the race?
2
Pole Positions
Racecar Fletcher (#6) going 200MPH
Racecar Baird (#58) going 200MPH
How many laps would you like to do?
4
Lap 1
Racecar Fletcher (#6) going 218MPH
Racecar Baird (#58) going 206MPH
Lap 2
Racecar Fletcher (#6) going 224MPH
Racecar Baird (#58) going 187MPH
Lap 3
Racecar Fletcher (#6) going 257MPH
Racecar Baird (#58) going 213MPH
Lap 4
Racecar Fletcher (#6) going 246MPH
Racecar Baird (#58) going 208MPH
The winner of the race is Racecar Fletcher (#6) going 246MPH
What type of vehicle would you like to race?
1. Cars
2. Trucks
3. Formula 1
4. Exit