Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Marathon Simulator

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 spaces. 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. Produce a module structure chart and/or flowchart as part of your design process.

RUNNERS

1 Louise Antony 5:00 2 David Armstrong 6:05 3 Alexander Bain 6:00 4 Thomas Baldwin 5:20 5 Gregory Bateson 4:50 6 Balthasar Bekker 5:40 7 Henri Bergson 4:50 8 Ned Block 6:15 9 Margaret Boden 4:15 10 Paul Boghossian 5:05 11 Emil Reymond 4:45 12 Hans Bothe 6:10 13 Robert Brandom 3:55 14 Berit Brogaard 5:20 15 David Brooks 5:55 16 Thomas Brown 4:35 17 Tyler Burge 5:55 18 Peter Carruthers 3:40 19 David Chalmers 5:50 20 Noam Chomsky 4:30 21 Patricia Churchland 3:40 22 Andy Clark 5:05 23 Donald Davidson 5:45 24 Daniel Dennett 4:15 25 Gerhard Dorn 4:40 

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions