Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program This program will get its input from a file. An example input file for this program is shown below. On the first line

C++ Program

This program will get its input from a file. An example input file for this program is shown below. On the first line is a participants first name, last name, height in inches, and the number of activities the participant engaged in. The following lines list activities by code and minutes. A chart below this sample input file lists the codes for all activities. A code of 24 is walking 4 mph and this participant walked for 60 minutes. The next line of this small, sample input file lists a code of 25, weight lifting, and 45 minutes. The next line lists a code of 22 for tennis and 55 minutes, and the last line lists a code of 26, yoga, for 30 minutes.

Cindy Arnold 62.5 4

24 60

25 45

22 55

26 30

In the table below, steps gained per minute are showed to help with programming the mathematical portion of the code.

Activity

Steps in 1 minute

Code

Assembly Line

85

0

Basketball (shooting baskets)

136

1

Basketball game

242

2

Bicycling under 10mph

121

3

Bicycling

242

4

Cooking

61

5

Dance

167

6

Football

242

7

Hiking

182

8

House cleaning

91

9

Gardening

99

10

Miniature golf

91

11

Racquetball

212

12

Rowing

212

13

Running 6 mph

303

14

Running 7 mph

348

15

Running 8 mph

409

16

Shopping

70

17

Soccer

212

18

Softball

152

19

Stairs

273

20

Swimming laps

212

21

Tennis

212

22

Walking 3mph

100

23

Walking 4mph

152

24

Weight lifting

121

25

Yoga

76

26

The program starts by printing a welcome message and asking the user for the name of an input file with the following applicable error messages.

  • If the file doesnt exist, print the following error message where ________ is the file name and end the program.

File ________ does not exist. Please contact the administrator.

  • If the file is empty, print the following error message where ________ is the file name and end the program.

File _________ is empty. Please contact the administrator.

If the file exists and is non-empty, it will be in the format described above. The program reads the data file into an array of Participant structures created with the following definition using the constants listed.

const int MAX_NAME_LENGTH = 21;

const int MAX_ACTIVITIES = 365;

const int MAX_PARTICIPANTS = 40;

struct Participant {

char firstName[MAX_NAME_LENGTH];

char lastName[MAX_NAME_LENGTH];

double height; // in inches

int numActivities;

int activities[MAX_ACTIVITIES]; // parallel array with

int minutes[MAX_ACTIVITIES]; // minutes array

double totalMiles;

};

After reading the data into an array of structures, calculates each individuals total miles, sorts the array of structures in descending order by miles, and prints the results with a goodbye message. The results should be printed in a formatted table as shown in the Sample Execution. Assume each name will be no longer than 20 characters and total miles will be less than 99,999.99.

Besides the constants listed above, use constants for the activity codes and steps. For example,

const int ASSEMBLY_LINE = 0;

const int BASKETBALL_SHOOTING = 1;

etc.

const int ACTIVITY_STEPS[NUM_ACTIVITIES] = {85, 136, etc.

so that

ACTIVITIES[BASKETBALL_GAME] or ACTIVITIES[participants[i].activities[j]]

is number of steps for 1 minute of participant is jthactivity, assuming an array of Participant structures named participant. In other words, participants[i].activities[j] is the jthactivity that one participant engaged in, and participants[i].minutes[j] is how many minutes the participant engaged in that activity.

To calculate the number of feet and then miles that one participant earns for one activity use the following formula. Assume the distance in feet in one persons step,f, is given by the following formula wherehis the persons height in inches.

f = (0.413 * h ) /12,

Recall that there are 5280 feet in a mile.

Finally, for some real input, each student will need to track their activities for one week and enter it in the spreadsheet provided in our online course content. Make sure to use the correct codes to specify an activity. Do not make up codes.

Sample execution

Welcome to the PSCC Fitness Tracker.

Input file: tracking.prn

Tracking Results

Name Miles

--------------------------------------------------

Bilbo Baggins 165.90

Rick Grimes 75.40

Cindy Arnold 11.61

Zelda Hyrule 1.99

==================================================

TOTAL 254.90

Thank you for using the PSCC Fitness Tracker.

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions