Answering Questions 5

profileGareth Beckham
COSC1437Lab2-Racetrackintrotoobjects1.docx

COSC 1437

Racetrack

Start with objective 1 and work on creating objects for your lab. If you have questions or encounter errors with your code contact the instructor by email or during live sessions for assistance.

Objective 1 (50%):

You are to take the given code which shows 1 car running a race. Your job will be to add 5 more cars with varying stats which should participate in the race just like the first car. In this lab each car holds the same types of information, behaves in the same way and only differs in their values for said information. So the optimal solution would be to use Objects. Create an object capable of holding the information for each car. Also include the operations that the cars do as methods (functions). Make certain to create a constructor that takes, as input, adequate information to allow you to build the cars more easily. (Due note that credit for this objective will not be earned if you do not create and use objects for the car’s information.)

· String car2Name = "Pat Sajak Car";

· car2HandlingS = 0.45f;

· car2HandlingC = 0.65f;

· car2HandlingU = 0.3f;

· car2RaceProgress = 0;

· car2CurrentSpeed = 0;

· car2TopSpeed = 0.83f;

· car2Acceleration = 0.14f;

· car2Wins = 0;

· car2Symbol = 'P';

· String car3Name = "Alex Trebek Car";

· car3HandlingS = 0.29f;

· car3HandlingC = 0.45f;

· car3HandlingU = 0.02f;

· car3RaceProgress = 0;

· car3CurrentSpeed = 0;

· car3TopSpeed = 0.85f;

· car3Acceleration = 0.19f;

· car3Wins = 0;

· car3Symbol = 'A';

· String car4Name = "Bob Eubanks Car";

· Car4HandlingS = 0.15f;

· Car4HandlingC = 0.18f;

· Car4HandlingU = 0.05f;

· Car4RaceProgress = 0;

· Car4CurrentSpeed = 0;

· Car4TopSpeed = 0.89f;

· Car4Acceleration = 0.21f;

· Car4Wins = 0;

· Car4Symbol = 'E';

· String car5Name = "Monty Hall Car";

· Car5HandlingS = 0.18f;

· Car5HandlingC = 0.22f;

· Car5HandlingU = 0.09f;

· Car5RaceProgress = 0;

· Car5CurrentSpeed = 0;

· Car5TopSpeed = 0.93f;

· Car5Acceleration = 0.17f;

· Car5Wins = 0;

· Car5Symbol = 'M';

· String car5Name = "Richard Dawson Car";

· Car5HandlingS = 0.40f;

· Car5HandlingC = 0.5f;

· Car5HandlingU = 0.35f;

· Car5RaceProgress = 0;

· Car5CurrentSpeed = 0;

· Car5TopSpeed = 0.815f;

· Car5Acceleration = 0.19f;

· Car5Wins = 0;

· Car5Symbol = 'R';

Objective 2 (25%):

Right now the race is only being run once. I want you to adjust the code so that the race can be run 25 times to simulate an entire season of racing. At the end of the season I want you to output each car’s race wins and finally display the car with the most wins as the season champion.

Objective 3 (25%):

Each race of the season should be a different race. Randomly create racetracks prior to the start of each race. Do this by randomly appending the four characters to a string. You can skew the random numbers to give more straightaways or turns depending on your preference (so long as there is a chance of any type of racetrack being possible). *note that some cars are better than others and 1 or 2 of them are just awful and have no chance of winning – you do not have to balance it in any way, if 1 car wins every time that is fine (there will probably be some competition between at least 2 of them but again, it is not your job to balance the win rates).

Bonus Objective (5pts):

For this lab you are allowed to hard-code the values for the race car instances in, but for the bonus objective you should move these to a file(s) where the information can be read into the program.

Bonus Objective 2 (5pts):

In all likelihood you created your program where each car outputs his progress on his own individual line. For 5 additional points adjust your program so that it draws each car on the same line unless there are multiple cars at the exact same position (in which case it would draw that car on the next line).