Lab #1 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: Logical operators
Control structures
Multi-dimensional Arrays
Strings
Data types
Global constants
Searching and sorting
Algorithms
Error checking
Programming style
plus all topics from previous labs
The goal for this lab is to provide an opportunity for practice of the C programming topics covered in Chapters 1–6 in Foster and Foster. This assignment is designed to practice those concepts by creating a program.
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, 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 lab #1 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 a list based on characteristics about the exercise data and then to determine certain information from the 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 lab #1 assignment will be:
¨ Introduce the health tracking system to a new user.
¨ Create two-dimensional arrays to store the exercise data in and then populate the array with data.
¨ Create and display a screen menu of the following choices for the user.
1) Using the data in the array,
A) Sort the exercise data array by length of time
B) Search for exercise choices and data by
i. Type of exercise to perform
ii. Average length of time to perform any exercise
iii. Average time - to find an exercise that is closest to a given amount of time
iv. Body part exercise
C) Calculate a total time to perform a certain set of exercises
D) List all the exercises that meet a certain criteria
i. Strength
ii. Endurance
iii. Flexibility
E) Extra Credit – find a group of exercises that can be done within a given time
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 an integer two-dimensional array with 5 columns and 10 rows, a char two dimensional array with 5 columns and 10 rows, and a float one-dimensional array with 10 elements which are described below. The contents of the arrays are as follows:
o Exercise code – Column 0 of the integer array of ten elements 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– Column 0 of the character array of ten elements 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– Column 1 of the character array of ten elementsholds 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– Column 2 of the character array of ten elements 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– Column 3 of the character array of ten elements holds the letter code for the setting of the 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– Column 1 of the integer array of ten elements 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– Column 2 of the integer array of ten elements 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– Column 4 of the character array of ten elements holds the letter code for the type of measurement needed for the exercise. The valid codes are ‘R’ for repetitions, ‘L’ laps, ‘P’ postures, ‘M’ minutes, ‘O’ other, and ‘U’ for unknown.
o Recent measurement– Column 3 of the integer array of ten elements 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– Column 4 of the integer array of ten elements 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 lab #1, you must implement data file input and at least one of the other two methods of input. The first method is to read lines of exercise data from a data file, the second method will allow the user to input all needed pieces of data about one exercise on one line, and the third method will prompt the user for each piece of data about an exercise individually. 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 exercises 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. The program must allow data file input and either the individual data method or line of data 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 (one of the legal codes that they could choose from) and then store it in column 0 of the integer 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 column 0 of the character 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 each value 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 column of the char 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 correct column of the integer 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 float array at [index].
Line of data input method:
Instead of asking for each value separately, 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 column 0 of the integer array at some location index, then read and store the char into the corresponding location index in column 0 of the char array, then read and store the third number into location index in the char 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).
Data file (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.
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. You must write 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. Sort the exercise data array by length of time
ii. Search for a type of exercise to perform
iii. Calculate the average length of time to perform of all of the exercises
iv. Find an exercise whose average length of time is closest to a given amount of time using the sorted arrays
v. Search for body part exercises
vi. Calculate a total time to perform a certain set of exercises
vii. List all the exercises that meet a certain criteria of strength, endurance or flexibility
viii. Extra Credit – find a group of exercises that can be done within a given time
ix. List all the exercises and all their respective data
x. Update the data in the arrays
xi. End the program
The sort must be implemented with a bubble sort routine. Also, when you sort the float array you must ALSO correspondingly sort all of the columns of the other two arrays. For example, if one step in the sort is to swap element [3] and element [4] in the float array then element [3] in column 0 of char array should swap with element [4] of column 0 of the char array and so on for the five integer columns and the five char columns in the 2-D arrays.
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 average length takes an average of the time lengths in the float array. It should print the exercise average length in seconds.
Finding a time that is closest to a given time is a search. Ask the user for a time to search for. Searching a sorted array is much simpler and faster. Make sure that the arrays have been sorted before you run your search function. If two exercises are the same length of time and closest to the given time, return the one with the smaller code.
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.
Extra Credit - Finding a group of exercises that can be done within a given time means asking the user for a time amount (for example, five minutes, entered as 300 seconds) and then finding a list of exercises that can all be done once in the period of time (for example, a sun saluation for 112 seconds, a bicep curl for 2 seconds, a minute of walking for 60 seconds, a minute on the recumbent bike, plus a 65 second yoga pose would equal 299 seconds of exercise.)
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 at [index]
o Change Body part exercised at [index]
o Change Kind of equipment at [index]
o Change Setting, recent setting or target setting at [index]
o Change Measurement, recent measurement or target measurement at [index]
o Change Time per measurement 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:
Two dimensional integer and character arrays, and a floating point array
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
global variables
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 sorting, 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. You also need a function for printing the exercise data.
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 exercise 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: (58%)
Program header and function headers for all functions (6 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!) (7 points)
Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.) (5 points)
Correct manipulation of the 2-dimensional arrays (9 points)
Correct use of required control structures (5 points)
Correct function structure as required (5 points)
Proper implementation of input error checking (7 points)
Bubble sort correctly implemented (8 points)
Output: (42%)
User clearly understands what is being requested for input (4 points)
Search (find) tasks perform correctly (6 points)
Sort task performs correctly across all arrays and columns (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 (6 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 exit, break (not in a switch), or continue will result in an overall grade of 0 (zero)
Use of structs 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: (Codes should all be unique now. Ignore leading zeros when typing as input)
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 = 060
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 = 131
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