5K Walk/Run Program

 

Your customer hires you to write a program. The customer wants to keep track of participants in 5k run/walk they are planning.  The program will need to create a tab delineated file that will contain information on each participant.  Each row in the file will have one participant’s information that includes: name, age, email address, age grouping and the word run or walk.  If the file contains run as the last item in a row, the participant is running the race.  If the file contains walk as the last item in a row, the participant is walking the race.  The program itself will have to figure out a participant’s age group before writing it to the file.  Age groups are separated by the following divisions:  Division 1 = participants under age 12, Division 2 = age 12 and less than age 18, Division 3 = age 18, but less than age 30, Division 4 = age 30 but less than age 45, Division 5 = age 45 but less than age 60, Division 6 = age 60 and over.  The program must also keep track of the total number of runners, total number of walkers, and total number of participants in the 5k.  All three of these total numbers need to be displayed to the user immediately after each person’s information is entered.  After each participant’s information is entered, the program will ask the user if they wish to continue entering user information. 

 

What is the purpose of this program?

1)      Program gathers information about participants in a 5k run/walk.

2)      The user will be asked to enter each participant’s information one at a time. 

3)      The program will gather the following information about each participant: name, age, email address and if the participant will be running or walking the 5k.

4)      The program will create a tab delineated file that will contain information on each participant.

5)      Each row in the file will have one participant’s information in the following order: name, age, email address, age grouping and the word run or walk.

6)      If the file contains run as the last item in a row, the participant is running the race.  If the file contains walk as the last item in a row, the participant is walking the race.

7)      The program will figure out a participant’s age group before writing it to the file.

Age groups are separated by the following divisions: 

Division 1 = participants under age 12,

Division 2 = age 12 and less than age 18,

Division 3 = age 18, but less than age 30,

Division 4 = age 30 but less than age 45,

Division 5 = age 45 but less than age 60,

Division 6 = age 60 and over

8)      The program will keep track of the total number of runners, total number of walkers, and total number of participants in the 5k.   These totals will be displayed to the user immediately after each person’s information is entered.

9)      After the totals from part 8 above are shown to the user, the program will ask the user if they wish to continue entering user information. 

 

What variables will be needed in this program?  What are the comments each variable will need?  What is the range of each variable?

Look at the program request above.  Several words are underlines.  Do you notice each of these words or groups of words would make good variable names?

            FiveKRunWalk.C

            string name; //holds a participant’s full first and last name

            unsigned int age ; //holds a participant’s age, range = 0 to 125

string emailAddress; //holds a participant’s email address, range = any valid email address

string ageGrouping; //holds a participant’s age grouping in the 5k

                                      // range = {Division 1, Division 2, Division 3, Division 4, Division 5, Division 6}

string runOrWalk; //holds a if a participant will be running or walking the 5k

      //range = {walk, run}

            unsigned int totalNumberOfRunners = 0; //holds total number of runners signed up for the 5k

//range = 0 to 65,535

unsigned int totalNumberOfWalkers = 0; //holds total number of walkers signed up for the 5k

//range = 0 to 65,535

unsigned int totalNumberOfParticipants = 0; //holds total number of people signed up for the 5k

//range = 0 to 65,535

            char continue; //used to evaluate if user wishes to add another participant’s information or quit

                                    //adding information, range = {y, n, Y, N}

            ifstream participantFile; //object used to create, open and store 5K participant information

                        ** note: we do NOT include a range for ofstream variables

            ***Note: there are more variables needed for this program, but we will not be going thru them here

 

What are the special cases in this program???

            Start by asking if there is any alternative follow in the program. 

            Then look at the range of our variables and see if a range creates a special case.

1)      The order of entry for participant’s name is First Name, one blank space, then Last Name.  Although user is prompted to enter this information in this order, no error checking is done.

2)      Valid age range is 0 to 125 years.  If user enters a value out of range, program continues to prompt user for a valid age until one is entered.

3)      Email address need to be valid addresses, but no error checking is done.

4)      If user does not enter a, b, A, or B when prompted if a participant is walking or running the 5k, the program continues to prompt user for a valid character until one is entered.

5)      If user does not enter y, n, Y, or N when prompted if they wish to continue entering participant information, the program will continue to prompt user for a valid character until one is entered.

 

What are the error cases in this program??

1)      If user enters non-numeric data for a participants age.

2)      If the data file is not created and opened for any reason.

 

What type of programming methods can be used in this program?

1)      Does it look like a switch statement would handle the age grouping nicely??

a.       Where would you place the breaks???

b.      What would be a good default value????

2)      We already know the algorithm and code to add up numbers.

3)      A while loop that encompasses all the code after the program explanation would handle the “want to continue” part of the program.  The last thing asked for and received in the while loop would be if the user wished to continue or not.  After we break out of the while loop, we would still need to have the last 5 lines of Template.C that end all out programs.

4)      A while loop would easily handle all the user restrictions we needed to place on entering valid data.

5)      We already know how to use an if statement to handle if a file opens or not.