Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Arrays of Structures Introduction This lab emulates part of the code for a fitness tracker app that might be used with a wearable device like

Arrays of Structures

Introduction

This lab emulates part of the code for a fitness tracker app that might be used with a wearable device

like a FitBit. It calculates how many equivalent miles a person gets for an activity based upon that persons

height. It totals these miles walked for an individual and for an entire group of people.

Detailed Information

Since we dont have an input device like a wearable, this program will get its input from a file.

However, the program code will be similar to the code that would be part of a fitness tacker app. 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 minutes of activity are adapted from

https://www.verywellfit.com/pedometer-step-equivalents-for-exercises-and-activities-3435742

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 j

th

activity, assuming an array of

Participant

structures named

participant.

In other words,

participants[i].activities[j]

is the j

th

activity 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 where

h

is the persons height in inches.

f = (0.413 * h ) /12

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.

Relevance Questions

The code of this program is similar to code in a lot of apps that help people track their activities such as

MyFitnessPal and apps that come with wearable device such as a Fitbit that tracks steps and more. This

program just doesnt have a good interface for input such as a nice GUI or a blue-tooth enabled wearable. Even

without the nice input, there is a lot of functionality that could be added to this program.

1.

What are two functionalities besides a nice interface and/or input device that could be added to this

program?

Rubric

For any credit on this lab, the program MUST read data into an array of

Participant

structures from

an input file, use this array, and have at least three functions other than the main function.

(10 points) Comments and style

(4 points) Relevance questions

(4 points) Fitness tracking

Program correctness

o

(7 points) Constants

o

(4 points) Non-existent file

o

(4 points) Empty file

o

(15 points) Correct miles calculation for file with one person who did every activity

o

(30 points) Correct miles calculation for file with class data

o

(10 points) Class data sorted by miles in descending order

o

(12 points) Miscellaneou

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

Personal Trainer Online Purchase Managerial Accounting

Authors: Carl S. Warren, James M. Reeve, Philip E. Fess

8th Edition

0324204604, 978-0324204605

More Books

Students also viewed these Accounting questions