Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code to simulate the running of a marathon (40 kilometer foot race) with 25 runners. Each runner has a pair of parameters which dictates

Write code to simulate the running of a marathon (40 kilometer foot race) with 25 runners. Each runner has a pair of parameters which dictates how far they travel each kilometer. You are provided with a file contacting runner numbers, runner names, and the average pace for each runner, separated by commas. For example:

1 John Smith 5:05

2 Sally Jones 4:55

This means that, on average, John runs 1 KM in 5 minutes 5 seconds, while Sally runs 1 KM in 4 minutes 55 seconds. Keeping that average pace, John would take 3 hours 32 minutes 20 seconds to run 40 KM, while Sally would take 3:16:40.

You are to first read the file into a set of two arrays, one for the runner name, and one for the pace. Store the runner names and associated paces in two arrays, string name[] and float pace[]. Since the numbers in the file are stored as two integers, you might choose to write a function that will convert from floating point minutes to minutes and seconds ,and vice versa.

To simulate the marathon, you will generate random values for each runner that is near their given pace. This represents the time that runner took for that kilometer. To do this, calculate a value which is 5% slower and another value 5% faster, and generate a random number between these two bounds. Repeat this for all runners, for all 40 kilometres.

Maintain an elapsed time for each runner in a third array, float time[]. Each loop through your program will represent another kilometer elapsed in the rase.

After the first 20 kilometres, output to the user a list of the fastest runner and their elapsed time, as well as the slowest runner and their elapsed time.

At the end of the race, show the fastest and slowest runner, and generate a log file containing the runners and their times.

Your code must use at least 3 separate functions, passing an array to a function at least once.

Assignment deliverables

all files must have the indicated filenames (replace 200200000 with your student number):

1. Program file named A6code_200200000.cpp

2. Representative output screenshot(s) named A6scrn_200200000-1.png, A6scrn_200200000-2.png etc

2. Screenshot/Image of your module structure chart named "A6chart_200200000.png"

3. Output log file named A6out_200200000.txt

Cool expansions you could add for fun:

Sort the time[] array after each loop to see who is in the lead. You may want to maintain an unsorted copy of the time[] array so it can be easily updated each loop.

Add a fatigue value for each runner that indicates how fast he or she gets tired, and modify their average pace during the race.

Design an interesting way to display the race kilometer by kilometer

Simulate and display the race in accelerated real-time with each minute represented by 1 second.

Run the simulation with 1000 runners instead of 25.

Reframe the simulation as a crowd of zombies in a game. As each zombie approaches, the player can make choices about which weapon to use to shoot them.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions