Lab #4 Assignment , CSE 1320-002 Spring 2009
Due Date: Lab #4 is
due absolutely no later than 8 pm Friday May 15th
Extra Credit for early submission as
follows:
Turned in before 11:59pm Monday May 11 40 extra points
Turned in before 11:59pm Tuesday May 12 30 extra points
Turned in before 11:59pm Wednesday May 13 20 extra points
Turned in before 11:59pm Thursday May 14 10 extra points
(see instructions on website for how to turn this in)
Grade value; 10% of total class grade.
Topic objectives: Classes and objects
Accessor and mutator functions
Constructors and destructors
C++ input and output
Bool data type
Searching and sorting
Algorithms
Error checking
Programming style
The goal for this lab is to provide an opportunity for practice of the C++ programming topics covered in Chapters 12 in Foster and Foster. This assignment is designed to practice those concepts by creating a program. This program must be compiled on omega using the g++ compiler and run on omega.
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), or continue.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Since we have just had the start of a new year, many people have made New Years 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 users exercise.
Throughout the course of the semester you will work on this health tracking system. In lab #4 you are going to be looking at and manipulating your exercise data from an object-oriented perspective. Primarily you will be moving from structs to classes and then you will be manipulating your objects to perform some of the tasks from your earlier labs. You will still 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 one or more class definitions that will hold the exercise information and the functions that will be associated with that data. You will create an array of objects of this class and you will manipulated the array to perform the requested tasks. You will have to give the programs 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 #4 assignment will be:
¨ Introduce the health tracking system to a new user.
¨
Define a class to hold the exercise
data and associated functions. The
members of this class should include:
Private
data members for all the exercise data that was in the struct
in lab #3
Appropriate
accessor and mutator
functions to use all the private data members
At
least one constructor and one destructor function
A private member function that calculates potential results reduction if overdone using the same algorithm as in lab #3 and stores the results in appropriate data members of the object
¨ Create an array of objects to store the exercise data in.
¨ 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 list by exercise code (any algorithm)
B) Search for exercise choices and data by
i. Type of exercise to perform
ii. Average time - to find an exercise that is closest to a given amount of time
C) Calculate
i. Total time to perform a certain set of exercises
ii. Average length of time to perform any one exercise
2) Update the data in the listthis will take the user to a submenu for doing updates
3) End the program
¨
Write
the program in such a way to use multiple physical files with a minimum of:
One file for the class definition
One file for the class functions
One file for the main routine
Each of these tasks is described in more detail below. There are also some simplifying assumptions for this lab. Many of these simplifications will be eliminated in later labs.
Simplifying assumptions for the lab:
a) All exercises must be available at the MAC but do not have to be performed there.
b) 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.
c) Exercise names are always only one word as a string. This word will likely have underscores in it as shown in b)
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.
¨
Define a class to hold the exercise
data and associated functions.
The
members of this class should include:
Private data members for all the
exercise data that was in the struct in lab #3 (the
list is below)
Appropriate accessor
and mutator functions to use all the private data
members
At least one constructor and one
destructor function
A private member function that
calculates potential results reduction if
overdone using the same algorithm as in lab #3 and stores the results in
appropriate data members of the object
A public member function that displays all the exercise data for one exercise
For the lab #4, the following data should be put in the private section of the class definition. You must create the class definition to hold all the information described in detail below and all of the functions that will be needed to access and modify the data. The data will be input from a file. Each line of the file will contain the data below.
o Exercise code The integer numeric code associated with a particular exercise. For this lab we are using strings but we will also still have exercises that are coded by number (ex. Recumbent Exercise Bike = 004, Free Weight Fly = 132, Yoga Sun Salutation = 488, etc.). All the other pieces of data associated with this exercise are also declared in the struct.
o Exercise name The name as a string associated with a particular exercise. For this lab we are using strings which will be one word with no blanks or punctuation other than underscores. The struct for the exercise should have a char pointer for the name string. The string should be read in from the file to a temporary buffer (an array used to hold the string temporarily) and then you should malloc space for the string and assign it to the char pointer in the struct. [This was done as an example in class on Mar. 9th.]
o Type of exercise The single character to hold 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. Make sure that the code that is entered is valid. (Dont error check for wrong data types those will give errors in runtime. Check for invalid char values.)
o Body part focus The character to hold 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. Make sure that the code that is entered is valid.
o Equipment needed The character to hold 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 The character 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 The integer 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. This value should always be positive except in cases where 1 indicates no setting.
o Target setting The integer value of the target setting for that particular exercise, i.e. the amount that would be the users 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 An enumerated type listing each type of measurement that is valid. The valid enumerated type values should be are repetitions, laps, postures, minutes, other, and unknown. Use the following enumerated type definition: enum Exmsmt {Repetitions, Laps, Postures, Minutes, Other, Unknown};
o Recent measurement The value of the most recent measurement recorded for that particular exercise. This value should be stored in a union based on the enumerated type of the exercise measurement as follows: Reprtitions and postures should have integer counts, laps should have a float distance, minutes should have a double value, and other and unknown should have integer values. Check for valid values.
o Target measurement The value of the target measurement for that particular exercise. This value should be stored in a union based on the enumerated type of the exercise measurement as above.
o Time per measurement The double 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.
o Max effective length A double value indicating the maximum length of time that this exercise should be performed during one workout
o Over max increment A float percentage indicating time increments over max that actually lead to reduced results (this would be some fraction of max effective length like 10% so if max effective length is 20 minutes, over max increment might be 2 minutes)
o Over max dropoff A float percentage indicating amount of dropoff results per each over max increment (for example, going 2 minutes over max might result in a 5% drop off of effectiveness)
o
Recent
exercise length This double value is time per measurement times recent
measurement This value must be calculated by a private member function
whenever time per measurement or recent measurement is modified.
o
Recent
results reduction This double percentage must be calculated automatically
by a private member function whenver a new time per measurement is entered (as long
as max effective length, over max increment,and over max dropoff
are available).
o Target results reduction This double percentage must be calculated automatically by a private member function whenver a new time per measurement is entered (as long as max effective length, over max increment,and over max dropoff are available).
Along
with the data members, your class definition must include member functions to
access and modify the private data members, to calculate values, and to display
the values.
Each
private data member must be accessible through at least two functions: one that allows the data to be changed and
one that returns the current value of the data.
As an example, the Time per
measurement data member should have at least the following two public
functions associated with it:
An accessor
function, e.g. Get_Time_per_msmt(), that would
return the current value of that data member, and
A mutator
function, e.g. Set_Time_per_msmt( double tpm), that would take in a double value, verify that
the value was a legal value for this data member (for example making sure it
was a positive amount instead of a negative amount), and if it is OK, then
saving the value into the data member and returning some indication (possibly a
bool) that indicates if the value was set.
It
is OK to have functions that get and return groups of values (like getting the Exercise measurement, Recent measurement, and Target measurement
all together) but do not include more than three data members for access or
modification in the same function.
You must write a constructor function for your class that
initializes the data members. You must
write a destructor function for your class that cleans up any allocated space
such as the name. You must write a
display function for your class that prints out all the exercise data that is
included in an object.
Another member function must calculate the Recent exercise length. It must be called by the mutator functions for time per measurement
and recent measurement so that Recent exercise length will change when either
of them change.
Another member function should calculate the potential
results reduction (recent results
reduction and target results
reduction) as done with the following algorithm which requires a comparison
function and a recursive calculation function.
This is the same as was done for lab #3 but it should be included as a
private member function and it should be called as part of the function that
saves or modifies the time per
measurement value.
The inputs to the comparison function would be the Max effective length , Over max increment , Over max dropoff, Recent measurement, Target measurement, and Time per measurement.
First, compare the (recent measurement * time per measurement) against the max effective length. If recent msmt is less than max effective length then print a message that recent msmt will give effective results. Then do the same comparison for target msmt and print a message if target is less than max.
Else if either is greater than max, then if recent msmt * time per msmt is greater than max effective length then subtract the difference and store in over max recent. Then call the recursive calculation function described below to calculate the amount of negative results derived from the most recent measurement. Print the results from the recursive calculation indicating that they are a reduction in results by X% from optimal AND save them in the object in recent results reduction.
If the target msmt * time per msmt is greater than max effective length then subtract the difference and store in over max target. Call the recursive calculation passing in this value and print output as above for over max recent and store in target results reduction.
Recursive calculation: This function will take as input the over max ___ value, the max effective length, the over max increment, and the over max dropoff. The function returns a percentage of total dropoff value which should be stored in the object. The algorithm is:
Calculate the time of the increment by over max increment * max effective length.
Subtract the time increment from the over max ___ value and save result as new over max value.
If (new over max value > 0)
Increment a total dropoff value by adding over max dropoff to total dropoff value and call the recursive funtion with new over max value, the max effective length, the over max increment, and the over max dropoff.
Else
Return total dropoff value of 0 (zero).
¨ Create an array of objects to store the exercise data in.
For the lab #4, you must implement data file input. For this lab the user must enter at least 12 exercises. There is no maximum amount of data. For file input, your program should read until it reaches the end of the file (EOF). For user input by line of data or pieces of data, you must tell the user what to enter that will tell the program that input is complete.
As the data for each exercise is read in, it should be stored into one object in the array that you have declared.
Data file (File of lines) input method:
You may create a file that contains 12 or more lines of exercise data and you may read the data from this file. You may pass the file name into the program as a command line parameter but it is not required. 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 will simply be the first record of data in the file.
Input verification:
When all of the exercise input has been read in, 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 list.
Since the name of the exercise is now recorded in the struct you will no longer need the name printing function. You should print the string from the struct as needed.
¨ Create and display a screen menu of the following choices for the user.
Once all the data is read into the list your program should give the user a screen menu with the following choices: (use any number scheme you wish)
i. Order the list by exercise code
ii. Find an exercise whose average length of time is closest to a given amount of time in the list
iii. Search for body part exercises
iv. Calculate a total time to perform a certain set of exercises
v. Calculate the average length of time to perform of all of the exercises
vi. List all the exercises and all their respective data
vii. Update the data in the list
viii. End the program
The sort (i) may be implemented with any algorithm to sort based on the code only. The program should then sort the array and print the sorted list.
The searches (ii. iii) for an exercise may use any search algorithm. A submenu should ask the user if they wish to search for the exercise closest to a given time (closest match), or search for an exercise by body part. For whichever type of search is chosen, the user must enter the data they wish to search for. The search function should search to return the first matching element, if any, printing the code and the name of the exercise. For the given time search, if two exercises are the same length of time and closest to the given time, return the one with the smaller code.
To calculate (iv) 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 average length calculation (v) takes an average of the time lengths of all the exercises. It should print the exercise average length in seconds.
The list exercises function (vi) is the same as the print function described for input verification.
The update option (vii) should take the user to a second screen to allow them to update information in the list. This screen should ask for a exercise code from the user and search for that exercise. Once the correct exercise is determined. give the user a menu of the following options:
o Change Type of exercise
o Change Name of exercise
o Change Body part exercised
o Change Kind of equipment
o Change Setting, recent setting or target setting
o Change Measurement, recent measurement or target measurement
o Change Time per measurement
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 object that was changed.
When the user chooses End the program from the main menu, print a concluding message and then gracefully end the program.
¨
Write
the program in such a way to use multiple physical files
Your program must have one file for the class definition
that should be name with the same name as the class followed by .h . For example, if
your class is Elmo then your filename for the class definition should be elmo.h . Your program should use a second file for all
of the function definitions for the member functions of your class. The name of this file should be the same as
the class definition file with the suffix .cpp . (Ex. elmo.cpp) Your main routine and any functions that are
not part of the class should be in another file that is named using the regular
class naming structure of xxx1234blahblah with the suffix of .cpp instead of .c after the name. You may split your main routine and other
non-class functions into separate files if desired but it is not required.
Implementation requirements:
WRITE A DESIGN ON PAPER FIRST
The program should use the following:
A class defined to hold data about an exercise in its private area and functions to access that data in its public area
A main routine in a separate file from the class definition
The program should NOT use:
global variables
any topic not covered in class before the lab DUE date unless approved by the instructor
The program should perform the following actions in the given order:
Instantiate the array of objects
Print a welcome screen for the user that introduces the system
Get the needed input value from the file and 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 instructors website for SPECIFIC instructions about the program header.
Each programmer-defined class should have a class header similar to those used in the examples in the textbook. This header should include at least the purpose of the class, and its expected use.
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 g++ 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: (68%)
Program, class, and function headers for all functions (3 points)
Comments (line comments and block comments) (3 points)
Modularity and Style (5 points)
Correct syntactical definition of class giving class name, indicating the public section and the private section, and correct syntax for member function prototypes (5 pts)
Correct
inclusion of data members in the private section of the class (5 pts)
Correct
definition of accessor functions for all data members
(8 pts)
Correct
definition of mutator functions for all data members
with proper input error checking (15 pts)
Correct
definition of recursive results reduction private member function and recent exercise
length function (4 pts)
Correct
definition of constructor and destructor functions (4 pts)
Correct definition
of display function (3 pts)
Correct input to object members using data file (3 pts)
Correct creation of the array of objects (3 points)
Correct sort of array (4 points)
Correct search of array (3 points)
Output: (22%)
User clearly understands what is being requested for input (2 points)
Search (find) tasks perform correctly using accessor functions to compare (3 points)
Sort task performs
correctly using accessor functions to compare (3
points)
Calculate tasks
perform correctly using member functions (3 points)
Update tasks
perform correctly using member functions (3 points)
Input
verification shows valid values and list of inputs correctly saved and printed
(2 points)
Output gives clear information to explain the values to the user (2 points)
Output contains
all the given test data and one additional data set (3 points)
Object orientation:
(10%)
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)
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