IPC144 Workshop #3-Simple validation on a series of user input values Solved

44.99 $

Description

5/5 - (1 vote)

 

Introduction
In this workshop, you will code a C language program that implements simple validation on a series of user input values, and then analyzes the data to provide a statistical summary.
Topic(s)
• Computations: Logic (sequence, selection, iteration, flags, nesting)

Learning Outcomes
Upon successful completion of this workshop, you will have demonstrated the abilities:
• to create a simple interactive program
• to code a decision using a selection construct
• to code repetitive logic using an iteration construct
• to nest a logical block within another logical block

Submission Policy

All files you create or modify MUST contain the following 4 pieces of information; your:
1. Full name
2. Student Number
4. Section Information Code

Notes
• You are responsible for backing up your work regularly

If any Part-1, Part-2, or Reflection portions are missing, the mark will be ZERO.

Part-1 (10%)
Instructions

1. Review the “Part-1 Output Example” (next section) to see how this program is expected to work
IMPORTANT: Do NOT use arrays in this workshop!
2. Code your program in the file named “w3p1.c”
3. After the system library #include, and before the main function, define two (2) macros:
#define MIN_YEAR 2010
4. Inside the main function, declare two (2) unmodifiable integer variables “JAN” and “DEC” representing the first and last months of the year respectively (initialize “JAN” to 1 and “DEC” to 12)
5. Display the title for the well-being log application
6. Nest inside an iteration construct the following:
a) Display the following message:
>Set the year and month for the well-being log (YYYY MM): <
b) Read from standard input (keyboard) the year and month (entered on the same line with a space between) assigning the input values to two integer variables (having meaningful names representing the data they store)
c) Apply what you have learned about selection to define the necessary logic that will validate the values entered for the year and month.
o The entered year value must be between MIN_YEAR and MAX_YEAR inclusive o The entered month value must be between JAN and DEC inclusive o If any of the above validations fail, the respective error message(s) should be displayed
(see example output to see what each error message should display)
7. Step #6 should continue to iterate until a valid year and month value is entered
YYYY: The year as 4-digits
MMM: First 3-characters of the month name
DD: The 2-digit day

Note: The log will start on the 1st day of the month entered by the user

Hint: You need to implement alternative/multiple selection to map the month integer value to the respective 3-character month representation. There are a couple of constructs available to you that will make this possible!
Part-1 Output Example (Note: Use this data for submission)

General Well-being Log
======================
2009 1
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
2009 0
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
Set the year and month for the well-being log (YYYY MM):

Part-1 Submission
1. Upload (file transfer) your source file “w3p1.c” to your matrix account
2. Login to matrix in an SSH terminal and change directory to where you placed your workshop source code.
3. Manually compile and run your program to make sure everything works properly:
gcc -Wall w3p1.c -o w3 <ENTER>
If there are no error/warnings are generated, execute it: w3 <ENTER>
~profName.proflastname/submit 144w3/NAA_p1 <ENTER>
5. Follow the on-screen submission instructions

Part-2 (40%)
Instructions
In a new source code file “w3p2.c”, upgrade the solution to Part-1 to include data input for a specified number of days that records the user’s self-diagnosed “wellness” rating for the morning and evening periods of each day. The application will end with a summary of statistics about the data entered.

1. Review the “Part-2 Output Example” (next section) to see how the program is expected to work
2. Add another macro to define the maximum days (3) of data to collect from the user:
#define LOG_DAYS 3
Note: This program must be coded in such a manner that it will work no matter what value is set for LOG_DAYS, from 3 – 28.
3. Continuing from Part-1, use a for iteration construct to loop the necessary number times based on the defined LOG_DAYS
Note: You will need to create additional variables. Be sure to place them at the beginning of the main function so all variables are organized and grouped together and in one place
4. Nest inside the for construct, the following:
The day value must be derived from a variable and not hard-coded, and remember the log always begins on the 1st day of the month
b) For each day, you need to read two (2) double floating-point user input values that represent a morning and an evening self-diagnosis rating value
c) Display a prompt to get the user input value for the “morning” diagnosis. This is a value that should be between 0.0 and 5.0 inclusive (refer to the example output)
d) Validate the rating value entered by the user. An incorrect value that is out of range, should display the appropriate error message and prompt again for a value and repeat as many times as is necessary until a valid value is entered
e) Repeat the same logic from step: c) above only for the “evening” diagnosis.
f) Repeat from step #4 until the number of desired days is reached
5. After all the data is entered by the user, a summary should be displayed consisting of the following:
• The sum of all the valid values entered for the morning ratings
• The sum of all the valid values entered for the evening ratings
• The sum of all the valid values entered for the combined morning and evening ratings o Note: Display all sums to 3-decimal precision points
• The average morning rating based on the number of LOG_DAYS of data entered
• The average evening rating based on the number of LOG_DAYS of data entered
• The average combined morning and evening rating based on the number of LOG_DAYS of data entered o Note: Display all averages to 1-decimal precision point

Part-2 Output Example (Note: Use this data for submission)
General Well-being Log
2009 1
======================
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
2009 0
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
Set the year and month for the well-being log (YYYY MM):
ERROR: Jan.(1) – Dec.(12)
Set the year and month for the well-being log (YYYY MM):

-0.9
Morning rating (0.0-5.0):
5.01
ERROR: Rating must be between 0.0 and 5.0 inclusive! Morning rating (0.0-5.0):
ERROR: Rating must be between 0.0 and 5.0 inclusive!
4.25
-0.9
Morning rating (0.0-5.0):
Evening rating (0.0-5.0):
5.01
ERROR: Rating must be between 0.0 and 5.0 inclusive! Evening rating (0.0-5.0):
ERROR: Rating must be between 0.0 and 5.0 inclusive! Evening rating (0.0-5.0): 5

Morning rating (0.0-5.0): 0
Evening rating (0.0-5.0): 4.9

Morning rating (0.0-5.0): 5
Evening rating (0.0-5.0): 0

Summary
=======
Morning total rating: 9.250
Evening total rating: 9.900
—————————-
Overall total rating: 19.150

Average morning rating: 3.1
Average evening rating: 3.3
—————————-
Average overall rating: 3.2
Reflection (50%)
Instructions
• Create a text file named “reflect.txt”
• Record your answers in the reflect.txt file for each of the following:

1. Mapping the month integer value to the first three characters of the month name could have been accomplished using one of two possible selection constructs. What are they, and provide a short example of how each would be written in C to display the first two months?
2. The logic applied to validate the values entered by the user required iteration. What are the 3
types of iteration constructs? What one did you use for the validation routines, and briefly explain why?
3. Describe what you did to test and debug your program. How did you go about finding where the problems were located?

Part-2 Submission

1. Upload your source file “w3p2.c” to your matrix account
2. Upload your reflection file “reflect.txt” to your matrix account (to the same directory)
3. Login to matrix in an SSH terminal and change directory to where you placed your workshop source code.
4. Manually compile and run your program to make sure everything works properly:
gcc -Wall w3p2.c -o w3 <ENTER>
If there are no error/warnings are generated, execute it: w3 <ENTER>
~profName.proflastname/submit 144w3/NAA_p2 <ENTER>
6. Follow the on-screen submission instructions

  • WS03-qrorab.zip