Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 6 A running club keeps information on record about each of its members. Define a class Runner as an ADT that uses separate files

Question 6 A running club keeps information on record about each of its members. Define a class Runner as an ADT that uses separate files for the interface and the implementation. This class represents a one runner's record. For each Runner the following information should be kept as member variables:

number (to run the Comrades, you need to be member of a running club, and will have a unique number to identify you), name, age, sex (a char member variable), whether or not the runner has qualified for entering the Comrades marathon ( a bool member variable), an array with the distances (in kilometers) of each of the last five races the runner ran, and a corresponding array with the times (in seconds) the runner took to complete each of these five races.

The class should contain a default constructor that initialises all the member variables with string values to empty strings and all the member variables with numeric values to 0. The bool member variable should be initialised to false. The destructor should print a message "Bye!"

Class Runner has accessor and mutator functions that returns / sets the value of the member variables for the runner's number, name, age, sex and Comrades qualification. Also include a private member functions to convert time in hours, minutes and seconds to seconds only.

Class Runner has a member function update() to remove the first element in the two arrays that keeps the race distance and corresponding time, then move all subsequent elements one place up in the array and add a new element with the distance and time of the last race run in the last element of each of the two arrays

To qualify to run the Comrades marathon, a runner needs to have completed either a half marathon (21 km) in less than 90 minutes or a marathon (42 km) in less than 3 hours (180 minutes) during the preceding six months. Include a void member function runComrades() in class Runner to check whether or not a runner will be allowed to enter the Comrades. Member function runComrades() should only check the last race that has been run and update the bool member variable indicating whether or not the runner has qualified for entering the Comrades marathon, accordingly. NB: Note that it may be possible that a runner has already qualified for the Comrades, but that the last race does not allow the runner to qualify. In this case the member variable indicating whether or not the runner has qualified for entering the Comrades marathon should not be changed.

Add a member function displayInfo() to display a runner's information. Member function displayInfo() display a runner's number, name, age, sex (male or female), whether or not the runner has qualified for entering the Comrades marathon, the distances of the last five races run and the corresponding times (in hours, minutes and seconds.

Overload the stream extraction operator >> (implemented as a friend function) so that it can be used to input an object of class Runner from a file.

Overload the stream insertion operator << (implemented as a friend function) so that it can be used to output an object of class Runner containing values for all the member variables of class Runner to a file.

Demonstrate the class in an application program (main()) to test your class that does the following:

Extract one object of class Runner from a file (Runners.dat), display the runner's number and name on the screen, and request the user to enter the detail of the last race the runner had run, i.e. the distance and time taken to complete the race. Use member function update() to update the two arrays keeping the race distance and corresponding time.

Use the member function runComrades() to check whether or not the runner has qualified for entering the Comrades marathon and update the member variable indicating whether or not the runner has qualified for entering the Comrades marathon accordingly. Once a runner's record has been updated, use member function displayInfo() to display a runner's info on the screen, and output the record to a file RunnerUpdated.dat. Your program should also determine how many men and how many women have qualified to enter the Comrades.

Use the following as the contents for the file Runners.dat:

145 John Martin

23 M 1

21 42 42 21 42

4680 8700 11040 5640 10900

3222 Peter Monyane

26 M 1

42 42 42 42 42

11000 11070 10960 10090 9090

2343 Sarah Sekonyane

31 F 0

21 21 21 42 21

5600 5499 5555 12000 6000

5432 Sean Naidoo

35 M 0

21 21 42 21 21

6000 5600 11900 5500 6120

The first four lines represent the record kept for the first runner, John Martin. His number is 145, he is 23 years old, male and has already qualified for the Comrades (see line 2). He has run two half marathons (21 km) and three full marathons (42 km). The fourth line contains the times he has taken to complete each race in seconds.

Assume the race results used to update the runners records is for a half marathon (21 km). John Martin completed it in 2 hours, 2 minutes and 2 seconds; Peter Monyane completed it in 1 hour 40 minutes and 21 seconds; Sarah Sekonyane completed it in 1 hour 29 minutes and 22 seconds (just qualifying!); and Sean Naidoo completed it in 1 hour 40 minutes and 23 minutes.

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 Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

How do most small business owners choose a location? Is this wise?

Answered: 1 week ago