Extra Credit Pre-Lab Assignment , CSE 1320-002 Spring 2009

 

Due Date:       See class website for due date

(see instructions on website for how to turn this in)

 

Grade value;    Extra credit 3% (out of 100% for all grades) added to total of lab grades.

 

Topic objectives:   Arithmetic and relational operators

                              Control structures

                              Functions

                              Arrays

                              Data types

                              Global constants

                              Pre-processor directives

                              Searching

                              Program design

                              Modular programming structure

                              Error checking

                              Programming style

 

The goal for this lab is to provide an opportunity for practice of the C programming topics covered in Chapters 1–3 and parts of later chapters in Foster and Foster. These chapters will not be covered in detail in the 1320 class and it is assumed that the student is familiar with and can use all the concepts in those chapters. This assignment is designed to practice those concepts by creating a program. The format of this assignment is similar to the assignments that will be required for the rest of the semester so a student who is unsure of their skills can use this assignment to refresh them and to ask the instructor or TA about any concepts they are unsure of.

 

Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties. You may NOT use global variables, the exit command, goto, break (except in a switch), continue, structs, multiple dimension arrays, strings, passing by reference (except arrays), or linked lists.

 

-- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • --

 

Since we have just had the start of a new year, many people have made New Year’s resolutions and many of these resolutions are about living a healthy life. Your goal for this program will be to develop a system to track activities that contribute to good health starting with a program to track the user’s exercise.

 

Throughout the course of the semester you will work on this health tracking system. For this pre-lab you will be given a list of exercises that the user performs along with information such as how many repetitions they did of the exercise, how often, and other data such as amounts of weight used or machine settings. You will write the program to separate the data into various lists based on characteristics about the exercise data and then to determine certain information from each list you create. You will have to give the program’s user a set of choices that will then guide the program in what lists are created. You will also have to report to the user the results that the program determines and the lists that are created.

 

The tasks for this pre-lab assignment will be:

 

¨              Introduce the health tracking system to a new user.

¨              Create one-dimensional arrays to store each type of the exercise data in and then populate the arrays with data.

¨              Create and display a screen menu of the following choices for the user.

1) Using the data in the arrays,

      A)  Search for exercise choices and data by

      i.    Type of exercise to perform

      ii.   Average length of time to perform the exercise

      iii.  Type of equipment needed to perform exercise

      iv.  Body part exercised

B)  Calculate a total time to perform a certain set of exercises

C)  List all the exercises that meet a certain criteria

      i.    Strength

      ii.   Endurance

      iii.  Flexibility

2) Update the data in the arrays–this will take the user to a submenu for doing updates

3) End the program

 

 

Each of these tasks is described in more detail below. There are also a number of simplifying assumptions for this pre-lab. Many of these simplifications will be eliminated in later labs.

 

Simplifying assumptions for the pre-lab:

a) All exercises must be available at the MAC but do not have to be performed there.

b) A maximum number of exercises of each type will be given

c) All exercises will be uniquely named, i.e. there will not be a “Fly” exercise with free weights and a “Fly” exercise that is done on a machine – they would be “Fly free” and Fly machine” for example.

 

 

Task Descriptions:

 

¨              Introduce the health tracking system to a new user.

For this task your system must provide an introduction/welcome screen to the user. The screen should briefly describe what the system will do. You may have the welcome screen stay up for a fixed period of time or you may let the user press a key to continue on with the program. Make sure you tell the user what to do if you want them to press a key.

 

¨              Create one-dimensional arrays to store each type of the exercise data in and then populate the arrays with data.

For the pre-lab, the following data will be used:

 

1.   Type of exercise

2.   What type of exercise it is (strength, endurance, flexibility)

3.   What part of the body it is focused on (arms, torso, legs, back, cardio, whole body)

4.   What type of equipment is needed for the exercise (weight machine, free weights, stairs, bike, mat, other, none)

5.   What settings are needed

      a.   For the equipment (amount of weight, speed of machine, amount of resistance, other, none)

      b.   Most recent settings (number related to type of setting)

      c.   Target settings

6.   What measurement is needed

      a.   For the exercise (repetitions, laps, postures, other)

      b.   Most recent measurement (number related to type of measurement)

      c.   Target measurements

7.   Estimated time per one measurement (repetition, lap, etc.)

 

For the pre-lab, the exercise data will be stored in a set of eleven (11) one-dimensional arrays of 10 elements each which are described below. Do NOT use multi-dimensional arrays for this pre-lab. The eleven 1-dimensional arrays are as follows:

 

o               Exercise code – an integer array of ten elements that holds the numeric code associated with a particular exercise for a total of ten exercises. For this lab we aren’t using strings so we will simply have a fixed set of exercises that are coded by number (ex. Recumbent Exercise Bike = 004, Free Weight Fly = 132, Yoga Sun Salutation = 488, etc.) and that list would be displayed in the output as described below. For all the other pieces of data, the index [n] for some exercise code will refer to the same exercise for all other info as well. (See the exercise code list at the end of this assignment and you can add to it if desired.)

o               Type of exercise– a character array of ten elements that holds the letter code for the type of exercise. The valid codes are ‘S’ for strength, ‘E’ for endurance, ‘F’ for flexibility, and ‘U’ for unknown. The type of exercise [n] corresponds to exercise code [n]. Make sure that the code that is entered is valid.

o               Body part focus– a character array of ten elements that holds the letter code for the body part addressed by the exercise. The valid codes are ‘A’ for arms, ‘T’ torso, ‘L’ legs, ‘B’ back, ‘C’ cardio, ‘W’ whole body, and ‘U’ for unknown. The body [n] corresponds to exercise code [n]. Make sure that the code that is entered is valid.

o               Equipment needed– a character array of ten elements that holds the letter code for the type of equipment needed for the exercise. The valid codes are ‘W’ for weight machine, ‘F’ free weights, ‘S’ stairs, ‘B’ bike, ‘M’ mat, ‘O’ other, ‘N’ none, and ‘U’ for unknown.

o               Equipment setting– a character array of ten elements that holds the letter code for the type of equipment needed for the exercise. The valid codes are ‘W’ for weight amount, ‘S’ speed, ‘R’ resistance, ‘O’ other, ‘N’ none, and ‘U’ for unknown.

o               Recent setting– an integer array of ten elements that holds the value of the most recent setting used for that particular exercise. If no setting is needed or value is unknown, this value should be -1. Setting [n] corresponds to exercise equipment setting [n]. (Ex. Equipment setting [3] of ‘W’ might have a Recent setting [3] value of 70 to indicate that the most recent weight used was 70 units.) This value should always be positive except in cases where –1 indicates no setting.

o               Target setting– an integer array of ten elements that holds the value of the target setting for that particular exercise, i.e. the amount that would be the user’s goal for this exercise. If no setting is needed, this value should be -2. This value should always be positive except in cases where –2 indicates no setting.

o               Exercise measurement– a character array of ten elements that holds the letter code for the type of measurement needed for the exercise. The valid codes are ‘R’ for repetitions, ‘L’ laps, ‘P’ postures, ‘O’ other, and ‘U’ for unknown.

o               Recent measurement– an integer array of ten elements that holds the value of the most recent measurement recorded for that particular exercise. Measurement [n] corresponds to exercise [n]. (Ex. Exercise measurement [3] of ‘R’ might have a Recent measurement [3] value of 25 to indicate that the most recent record was 25 repetitions.) Check for valid values.

o               Target measurement– an integer array of ten elements that holds the value of the target measurement for that particular exercise, i.e. the amount that would be the user’s goal for this exercise.

o               Time per measurement– a float array of ten elements that holds the value of the average time in seconds (can indicate tenths and hundredths with decimal places) for ONE measurement for that particular exercise, i.e. the average amount of time for one repetition or lap or whatever for this exercise. This measure multiplied by the Recent measurement tells how long it takes to do this exercise.

 

For the pre-lab, you must implement at least two of the following three methods of input. The first method will prompt the user for each piece of data about an exercise individually, the second method will allow the user to input all needed pieces of data about one exercise on one line, and the third method is to read lines of exercise data from a data file. The three forms of the input and the input data file are described below.

 

For this lab the user must enter at least 7 exercises and no more than 10 exercises. Since the user has a choice, then the first piece of data that the program needs from the user is a count of how many exercises they are entering. The program should check to make sure this count is between 7 and 10. [Note for development: start with a smaller number of restaurants then increase to 7 when program is working well ] If the user’s number exceeds 10, the program should inform the user that 10 is the maximum number of inputs allowed and have them reenter the count. Then your program must loop for count number of times (index= 0, 1, …count-1) to read and store input in one of the three following ways: Individual data method, line of data input method, or file of lines input method.

 

Individual data method:

a.   Ask the user for the exercise code (don’t forget to supply a list of names and codes for them.) Read in their number, make sure it is a valid code and then store it in the Exercise code array at [index]

b.   Ask the user for the type of exercise using the single character description (don’t forget to supply a list of abbreviations for them.) Read in their char, make sure it is a valid abbreviation and then store it in the Type of exerise array at [index]

c.   For the remaining data values that are letter codes (Body part focus, Equipment needed, Equipment setting, Exercise measurement) Ask the user for the type of exercise using the single character description (don’t forget to supply a list of abbreviations for them.) Read in their char, make sure it is a valid abbreviation and then store it in the appropriate array at [index]

d.   Ask the user for the most recent setting value for the current exercise. Make sure it is a valid number and then store it in the Recent setting array at [index]. Do the same for Target setting, Recent measurement, and Target measurement.

e.   Ask the user for the average time for one measurement of the current exercise. Make sure it is a valid number and then store it in the Time per measurement array at [index].

 

Line of data input method:

Your program may ask the user to enter all the information for one exercise on the same line. This data would be an integer for exercise code, a char for type of exercise, body part focus, equipment needed, and equipment setting, an integer for recent setting and target setting, a char for exercise measurement, an integer for recent measurement and target measurement, and a floating point number for time per measurement. You must tell the user exactly how to enter the line of data. The data for a single exercise will be entered by the user as eleven values on one line as follows {there must be one space only between the values}:

 

> 053 S A W W 30 50 R 10 18 3.25

 

which represents the Machine Bicep Curl (053), a 'S'trength exercise for 'A'rms using a 'W'eight machine. Its setting is 'W'eight with a recent value of 30 and a target weight of 50. Its measurement is 'R'epetitions with a recent measurement of 10 reps and a target of 18. An average Machine Bicep Curl takes 3.25 seconds.

 

Your program will read the first number and store it in the exercise code array at some location index, then read and store the char into the corresponding location index in the exercise type array, then read and store the third number into location index in the body part focus array, and so on. Your program should read all the numbers and chars within a single input command. Your program should read in as many lines of input for exercises as were originally specified by the count up to the maximum of ten lines of input (exercises).

 

File of lines input method

You may create a file that contains between 7 and 10 lines of exercise data and you may read the data from this file. To do this will requires creating file variables, opening the file and linking it to the file variable, and then reading the data from the file variable in the same way that a line of data would be read from the screen. The first line of data in the file should have only one integer on it which is the count of the number of lines of exercise data which follow in the file. (File input may or may not be covered in class prior to this lab’s due date so you might have to learn this on your own if you wish to use it in the pre-lab. It will be covered and required for later labs in the class.)

 

 

Input verification:

When the user has entered count number of exercises, print out all the input exercise data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels. It is strongly suggested that this printing be written as a separate function that can be called at any time in the program to print the current contents of the arrays. It is also suggested that a small function be written which will print the name of an exercise given the exercise code as input. The function could have a switch or a bunch of if statements in it.

 

 

¨              Create and display a screen menu of the following choices for the user.

Once all the data is read into the arrays your program should give the user a screen menu with the following choices: (use any number scheme you wish)

 

i.    Search for a type of exercise to perform

ii.   Find the minimum average length of time to perform some exercise

iii.  Search for a type of equipment needed to perform exercise

iv.  Search for body part exercises

v.   Calculate a total time to perform a certain set of exercises

vi.  List all the exercises that meet a certain criteria of strength, endurance or flexibility

vii. List all the exercises and all their respective data

viii.Update the data in the arrays

ix.  End the program

 

The search for a type of exercise should let the user choose 'S'trength, 'E'ndurance, or 'F'lexibility and then look through the list to find an exercise that matches that type, then print the code and the name of the exercise.

 

The minimum average length looks through the array and finds the exercise with the shortest average time. It should print the exercise code and name and its average length in seconds.

 

The search for a type of exercise equipment should let the user choose ‘W’ for weight machine, ‘F’ free weights, ‘S’ stairs, ‘B’ bike, ‘M’ mat, ‘O’ other, ‘N’ none, and ‘U’ for unknown and then look through the list to find an exercise that matches that type, then print the code and the name of the exercise.

 

The search for a body part exercises should let the user choose ‘A’ for arms, ‘T’ torso, ‘L’ legs, ‘B’ back, ‘C’ cardio, ‘W’ whole body, and ‘U’ for unknown and then look through the list to find an exercise that matches that type, then print the code and the name of the exercise.

 

To calculate the total time for a certain set of exercises, the average time should be multiplied by recent measurement. Print the exercise and the total time.

 

The list by criteria function lets the user choose a criteria and then goes through the list and prints all exercises that meet that criteria.

 

The list exercises function is the same as the print function described for input verification.

 

The update option should take the user to a second screen to allow them to update information in the arrays. This screen should ask for a exercise code from the user and search for that exercise. Once the correct exercise is determined save its [index] and give the user a menu of the following options:

 

o               Change Type of exercise array at [index]

o               Change Body part exercised array at [index]

o               Change Kind of equipment array at [index]

o               Change Setting, recent setting or target setting array at [index]

o               Change Measurement, recent measurement or target measurement array at [index]

o               Change Time per measurement array at [index]

o               Return to main menu

 

For any change the user wishes to make, do the same error checking as in the original data entry section. After each change is made, print all of the exercise info for the exercise at [index].

 

 

When the user chooses “End the program” from the main menu, print a concluding message and then gracefully end the program.

 

Implementation requirements:

 

WRITE A DESIGN ON PAPER FIRST

 

The program should use the following data structures:

One dimensional integer, character, and floating point arrays

 

The program should use the following control structures:

Function calls to perform tasks

A while or for loop to read the input data

If, if-else, or nested ifs to error check the first number and implement the menu options

 

The program should NOT use:

structs

multiple dimension arrays

switch statements

global variables

exit

break

continue

pointers

            any topic not covered in class before the lab DUE date unless approved by the instructor

 

The program should be implemented as a set of functions with a main routine and at least one function for menu operations,two for getting input, one for a find function, and one for calculating total time. You may use more functions than this but you must use at least this many. It is suggested that you also have a function for printing the exercise data but these are not required.

 

The program should perform the following actions in the given order:

Declare and initialize the variables

Print a welcome screen for the user that introduces the system

Get the needed input value from the keyboard

Print the appropriate outputs

Let the user enter additional values until the user indicates that they are finished.

 

The program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program. If multiple files are used, each file should contain a similar header. See your instructor’s website for SPECIFIC instructions about the program header.

 

Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook. This header should include at least the function name, the purpose of the function, and its inputs and outputs.

 

This program must be run with two different sets of test data for the team member constant data. You must create one data set in addition to the one that I will give you and run your program with both of them. You may run it two times within a single execution or you may execute the program two different times so that you have a total of two different data sets. The sample data set that you create must meet the guidelines given in the problem definition.

 

The program output must be recorded in a script file from OMEGA using the gcc compiler. If you do not know how to create a script file, it is your responsibility to ask the TA, look for help on the class website, or OIT how to use this function.

 

Grading scale:

Code:   (61%)

Program header and function headers for all functions           (8 points)

Comments (line comments and block comments)       (6 points)

Modularity (division of the problem into small tasks, each one assigned to its own function and called from main() or from another function when appropriate--do not code the entire program in main!) (10 points)

Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.) (8 points)

Correct manipulation of the 1-dimensional arrays (9 points)

Correct use of required control structures (6 points)

Correct function structure as required (6 points)

Proper implementation of input error checking (8 points)

Output:      (39%)

            User clearly understands what is being requested for input (5 points)

            Search (find) tasks perform correctly (6 points)

            Calculate tasks perform correctly (5 points)

            Update tasks perform correctly (6 points)

            Input verification shows valid values and list of inputs correctly saved and printed (4 points)

            Output gives clear information to explain the values to the user (8 points)

            Output contains all the given test data and one additional data set (5 points)

 

 

Deductions:

            Use of global variables will result in an overall grade of 0 (zero)

            Use of the exit, break, or continue command will result in an overall grade of 0 (zero)

            Use of structs, multiple dimension arrays, strings, or linked lists will result in 50 (fifty) point deduction per use

            Late submission of softcopy of code and/or script file to appropriate TA will result in an overall grade of 0 (zero) without prior instructor approval

            Use of C language elements not yet discussed in class by the lab due date will result in potential deduction of points – discuss with instructor before using.

 

Miscellaneous:

 

Exercise code list:

Recumbent Exercise Bike = 004

Stairmaster = 005

Ski Machine = 006

Rowing Machine = 007

Exercise Bike = 008

Treadmill = 009

Incline Treadmill = 010

Machine Fly = 050

Machine Chest Press = 051

Machine Shoulder Press = 052

Machine Bicep Curl = 053

Machine Triceps Curl = 054

Machine Crunch = 05

Machine Back Extension = 055

Machine Leg Press = 056

Machine Hip Adduction = 057

Machine Hip Abduction = 058

Machine Ankle Extension = 059

Free Weight Fly = 132

Free Weight Chest Press = 133

Free Weight Shoulder Press = 133

Free Weight Bicep Curl = 134

Free Weight Triceps Curl = 135

Chin Up = 136

Push Up = 137

Crunch = 138

Run = 220

Walk = 221

Jog = 222

Stretch = 23

Yoga Sun Salutation = 487

Yoga Downward Dog = 488

Yoga Cobra = 489