Starting from:

$29.99

IPC144 Workshop #4 Solution

Introduction
In this workshop, you will code and execute a C language program that implements a simple validation on a series of user input values that are stored to arrays and later analyzed to produce a variety of summary reports. The program will ask for the user’s monthly income and then ask for the price and priority of a series of items the user would like to purchase in the future. It will store this information and allow the user to view predictions on how long it will take to save enough money to purchase their wish list items.
Topic(s)
• Computations: Arrays
Learning Outcomes
Upon successful completion of this workshop, you will have demonstrated the abilities:
• to store data of common/primitive type using an array structure
• to associate related data using parallel arrays
• to process the elements of an array using an iteration construct


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. Carefully review the “Part-1 Output Example” (next section) to see how this program is expected to work
2. Code your program in the file named “w4p1.c”
3. Begin by prompting the user for their NET monthly income
• The monthly income must be at least $500.00, and not more than $400,000.00
• The minimum and maximum values should be stored in unmodifiable variables and used in the validation logic accordingly
• Display an appropriate error message if the entered value is outside this range
• Validation must be nested in an iteration construct and repeat until a valid value is entered
4. Next, prompt the user to specify the number of wish list items they want to use in the forecast
Note
• The maximum number of items should be limited to 10 (define a macro to help with this)
• Display an appropriate error message if the entered value is outside this range
• Validation must be nested in an iteration construct and repeat until a valid value is entered
5. Now you are ready to store the wish list item details. Use an iteration construct to Iterate the number of times necessary to obtain the number of wish list item details specified by the user (from step #5)
6. The item details are made-up of three (3) related pieces of information and must be stored in matching (parallel) arrays: a) Cost
- A double floating-point value representing the value of the item
- The entered value must be at least $100.00 (use an unmodifiable variable to help with the validation logic accordingly)
- Display an appropriate error message if the entered value is invalid
- Validation must be nested in an iteration construct repeating until a valid value is entered b) Priority
- An integer value representing the priority of the item
- The entered value must be between 1 and 3 inclusive where:
o 1 = a must-have item o 2 = important to have item o 3 = want to have item
- Display an appropriate error message if the entered value is out of range
- Validation must be nested in an iteration construct repeating until a valid value is entered

c) Finance Options
- A character value representing if an item has financing options (don’t need to pay entire value up-front)
- The entered value can only be a lowercase y or n
- Display an appropriate error message if the entered value is not a y or n
- Validation must be nested in an iteration construct repeating until a valid value is entered
7. After storing the data to parallel array’s, display a formatted table of the data entered
• Use the following printf statements for the table header:
printf("Item Priority Financed Cost "); printf("---- -------- -------- ----------- ");
• Use the following printf formatting to display each wish list item record:
printf("%3d %5d %5c %11.2lf ", ...
8. After all the data is displayed, summarize it with the total of all the item costs. Use the following printf statement to properly align it with the appropriate Cost column:
printf("---- -------- -------- ----------- "); printf(" $%11.2lf ", ...
9. Finally, before ending the application, display an exit message Part-1 Output Example (Note: Use this data for submission)
+--------------------------+
+ Wish List Forecaster |
+--------------------------+

500000
Enter your monthly NET income: $0 ERROR: You must have a consistent monthly income of at least $500.00
Enter your monthly NET income: $
6500.50
ERROR: Liar! I'll believe you if you enter a value no more than $400000.00
Enter your monthly NET income: $

How many wish list items do you want to forecast?: 0 ERROR: List is restricted to between 1 and 10 items.
11

How many wish list items do you want to forecast?: ERROR: List is restricted to between 1 and 10 items.

How many wish list items do you want to forecast?: 3

39030.15
Item-1 Details:
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 0
ERROR: Value must be between 1 and 3
How important is it to you? [1=must have, 2=important, 3=want]: 4
ERROR: Value must be between 1 and 3
How important is it to you? [1=must have, 2=important, 3=want]: 1
Does this item have financing options? [y/n]: N
ERROR: Must be a lowercase 'y' or 'n'
Does this item have financing options? [y/n]: Y ERROR: Must be a lowercase 'y' or 'n'
Does this item have financing options? [y/n]: k
ERROR: Must be a lowercase 'y' or 'n'
Does this item have financing options? [y/n]: n

99.99
Item-2 Details:
Item cost: $
1200000
ERROR: Cost must be at least $100.00
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 3
Does this item have financing options? [y/n]: y

350500.25
Item-3 Details:
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 2
Does this item have financing options? [y/n]: n

Item Priority Financed Cost
---- -------- -------- -----------
1 1 n 39030.15
2 3 y 1200000.00
3 2 n 350500.25
---- -------- -------- -----------
$ 1589530.40

Best of luck in all your future endeavours!

Part-1 Submission
1. Upload (file transfer) your source file “w4p1.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 w4p1.c -o w4 <ENTER>
If there are no error/warnings are generated, execute it: w4 <ENTER>
~profName.proflastname/submit 144w4/NAA_p1 <ENTER>
5. Follow the on-screen submission instructions


Part-2 (40%)
Instructions
In a new source code file “w4p2.c”, upgrade the solution to Part-1 to include an analysis of the entered data and provide the forecasted number of years and months it will take to save enough to purchase the wish list items.

1. Review the “Part-2 Output Example” (next section) to see how the program is expected to work
2. Display a menu with three (3) options:
1. All Items (no filter)
2. By priority 0. Quit/Exit Note:
• Prompt for a menu selection; where valid values are from 0 to 2
• The menu should be in an iteration construct and only exit / end the program when 0 is entered by the user
3. If 0 is entered, the program should display the exit message and end
• DO NOT use spaghetti code tactics by forcing the iteration to jump out of the iteration using statements like break, exit(), or goto
• Use a control variable (flag) to control the flow
4. If an invalid value is entered (that is not a 1, 2, or 0), then display an appropriate error message and continue to iterate and prompt for a valid menu selection
5. When option 1 is entered, iterate all wish list items and:
• Accumulate (total) each item cost
• Check if the item has financing options (value will be ‘y’) and make note if it (this will be used later to show an additional “note” in the summary output)
6. When option 2 is entered:
• This will follow the same directions as described in #5 only you will not accumulate (total) all the items, but will only consider items that match on the user entered priority value
• Therefore, before iterating, you must prompt the user to specify a priority level to filter by
(valid values are 1 to 3) o Display an appropriate error message if the entered value is out of range o Validation must be nested in an iteration construct repeating until a valid value is entered
• Just as described in #5, accumulate the item cost and check for financing options (only for the items that match on the specified priority level)
7. After menu options 1 or 2, display a forecast summary:
• The summary should be wrapped (first and last line) with a double line. Use the following:
printf("==================================================== ");

• Display the appropriate filter used to generate the results (based on option 1 or option 2):
printf("Filter: All items "); // [option-1] printf("Filter: by priority (%d) "... // [option-2]
• Display the total cost of the items (derived from the filtering option selected)
printf("Amount: $%1.2lf ", ...
• Display the forecasted number of years and months it will take to save enough to purchase the items. Hint: The modulus operator will help you greatly with this!
• Display an extra “Note” only if any of the items had financial options to indicate that a shorter time is likely possible

Part-2 Output Example (Note: Use this data for submission)
+--------------------------+
+ Wish List Forecaster |
+--------------------------+

500000
Enter your monthly NET income: $0 ERROR: You must have a consistent monthly income of at least $500.00
Enter your monthly NET income: $
6225.88
ERROR: Liar! I'll believe you if you enter a value no more than $400000.00
Enter your monthly NET income: $

How many wish list items do you want to forecast?: 0 ERROR: List is restricted to between 1 and 10 items.
11

How many wish list items do you want to forecast?: ERROR: List is restricted to between 1 and 10 items.

How many wish list items do you want to forecast?: 5

39030.15
Item-1 Details:
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 0
ERROR: Value must be between 1 and 3
How important is it to you? [1=must have, 2=important, 3=want]: 4
ERROR: Value must be between 1 and 3
How important is it to you? [1=must have, 2=important, 3=want]: 1
Does this item have financing options? [y/n]: N
ERROR: Must be a lowercase 'y' or 'n'
Does this item have financing options? [y/n]: Y
ERROR: Must be a lowercase 'y' or 'n'
Does this item have financing options? [y/n]: k
ERROR: Must be a lowercase 'y' or 'n'
Does this item have financing options? [y/n]: n


Item-2 Details:
99.99
Item cost: $
1200000
ERROR: Cost must be at least $100.00
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 3
Does this item have financing options? [y/n]: y

350500.25
Item-3 Details:
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 2
Does this item have financing options? [y/n]: n

15500.75
Item-4 Details:
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 1
Does this item have financing options? [y/n]: y

6575.55
Item-5 Details:
Item cost: $
How important is it to you? [1=must have, 2=important, 3=want]: 3
Does this item have financing options? [y/n]: n

Item Priority Financed Cost
---- -------- -------- -----------
1 1 n 39030.15
2 3 y 1200000.00
3 2 n 350500.25
4 1 y 15500.75
5 3 n 6575.55
---- -------- -------- -----------
$ 1611606.70

How do you want to forecast your wish list?
1. All items (no filter)
2. By priority
0. Quit/Exit
Selection: 3

ERROR: Invalid menu selection.

How do you want to forecast your wish list?
1. All items (no filter)
2. By priority
0. Quit/Exit
Selection: 1

====================================================

Filter: All items
Amount: $1611606.70
Forecast: 21 years, 7 months
NOTE: Financing options are available on some items. You can likely reduce the estimated months.
====================================================

How do you want to forecast your wish list?
1. All items (no filter)
2. By priority
0. Quit/Exit
Selection: 2

What priority do you want to filter by? [1-3]: 1

====================================================
Filter: by priority (1)
Amount: $54530.90
Forecast: 0 years, 9 months
NOTE: Financing options are available on some items. You can likely reduce the estimated months.
====================================================

How do you want to forecast your wish list?
1. All items (no filter)
2. By priority
0. Quit/Exit
Selection: 2

What priority do you want to filter by? [1-3]: 2

====================================================
Filter: by priority (2)
Amount: $350500.25
Forecast: 4 years, 9 months
====================================================

How do you want to forecast your wish list?
1. All items (no filter)
2. By priority
0. Quit/Exit
Selection: 2

What priority do you want to filter by? [1-3]: 3

====================================================
Filter: by priority (3)
Amount: $1206575.55
Forecast: 16 years, 2 months
NOTE: Financing options are available on some items. You can likely reduce the estimated months.
====================================================

How do you want to forecast your wish list?
1. All items (no filter)
2. By priority
0. Quit/Exit
Selection: 0

Best of luck in all your future endeavours!



Reflection (50%)
Instructions
• Create a text file named “reflect.txt”
• Record your answer in the reflect.txt file for each of the following:

1. Parallel arrays provide us the ability to group related data. Using what you coded in this workshop, briefly explain how you linked related data for any given item in the dataset? What was the ‘key’ used to accomplish this?
2. Why do you think it is common practice to iterate arrays initializing the iterator variable to zero and not to a value of one? Justify your answer using an example from this workshop.




Part-2 Submission

1. Upload your source file “w4p2.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 w4p2.c -o w1 <ENTER>
If there are no error/warnings are generated, execute it: w4 <ENTER>
~profName.proflastname/submit 144w4/NAA_p2 <ENTER>
6. Follow the on-screen submission instructions

More products