Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, can someone please do part 2 of this code in C. I have part 1 already PROGRAM for part 1 /* w4p1.c file -

Hi, can someone please do part 2 of this code in C. I have part 1 already

image text in transcribedimage text in transcribedimage text in transcribed

PROGRAM for part 1

/* w4p1.c file - Wish List Forecaster using parallel arrays */

/*including header files */

#include

/*declaring MACRO for defining symbolic constants

for Minimum and Maximum Values of Wish List */

#define MINWISHLIST 1

#define MAXWISHLIST 10

/*main function */

int main()

{

/* declaring constants for data validation purpose */

const double minNET=500.00; /* constant for validating minimum NET */

const double maxNET=400000.00; /* constant for validating maximum NET */

const double minCost=100.00; /* constant for validating minimum cost */

/* declaring parallel arrays */

double wishListCosts[10]; /* holds cost of wish list items */

int wishListPriority[10]; /* holds priority of wish list items */

char wishListFinanceOption[10]; /* holds finance option of wish list items */

/* other variable declarations */

double monthlyIncome; /* holds monthly income */

int noOfWishListItems; /* holds number of wish list items */

/* display welcome message */

printf(" +--------------------------------------------+");

printf(" + W I S H L I S T F O R E C A S T E R +");

printf(" +--------------------------------------------+");

/* get NET Income and validate the input data */

do

{

printf(" Enter Your Monthly NET Income: $");

scanf("%lf", &monthlyIncome);

if(monthlyIncome

printf("ERROR: You must have a consistent monthly income of at least $%.2lf.", minNET);

else if(monthlyIncome>maxNET)

printf("ERROR: Liar! I'll believe you if you enter a value no more than $%.2lf", maxNET);

}

while(monthlyIncomemaxNET);

/* get number of wish list items and validate the input data */

do

{

printf(" How Many Wish List Items Do You Want to Forecast? ");

scanf("%d", &noOfWishListItems);

if(noOfWishListItemsMAXWISHLIST)

printf("ERROR: List is Restricted Between %d and %d", MINWISHLIST, MAXWISHLIST);

}

while(noOfWishListItemsMAXWISHLIST);

/* get wish list item details */

for(int i=0; i

{

printf(" Item - %d Details:", i+1);

/* get wish list item cost and validate the input data */

do

{

printf(" Item Cost: $");

scanf("%lf",&wishListCosts[i]);

if(wishListCosts[i]

printf("ERROR: Cost must be at least $%.2lf",minCost);

}

while(wishListCosts[i]

/* get wish list item priority and validate the input data */

do

{

printf(" How Important is it to You [1=Must Have, 2=Important, 3-Want]: ");

scanf("%d",&wishListPriority[i]);

if(wishListPriority[i]3)

printf("ERROR: Value Must Between 1 and 3");

}

while(wishListPriority[i]3);

/* get wish list item finance option and validate the input data */

do

{

printf(" Do this item have a Financing Option [y]: ");

scanf(" %c",&wishListFinanceOption[i]);

if(wishListFinanceOption[i]!='y' && wishListFinanceOption[i]!='n')

printf("ERROR: Must be a Lowercase 'y' or 'n'");

}

while(wishListFinanceOption[i]!='y' && wishListFinanceOption[i]!='n');

}

/* display wish list item details */

printf(" Item Priority Financed Cost");

printf(" --------------------------------------------- ");

float totalCost=0;

for(int i=0; i

{

printf(" %3d %5d %5c %11.2lf ",i+1,wishListPriority[i],

wishListFinanceOption,wishListCosts[i]);

totalCost+=wishListCosts[i];

}

printf(" ---------------------------------------------");

printf(" Total Cost: $ %11.2lf",totalCost);

printf(" ---------------------------------------------");

printf(" Best of Luck in All Your Future Endeavors!");

return 0;

}

I need the exact output for part 2 according to the outlined instructions below:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

O . . . . . 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: 1 = a must-have item 2 = important to have item 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 O O O 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 orn 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.21f ", 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.21f ", ... 9. Finally, before ending the application, display an exit message Part-1 Output Example (Note: Use this data for submission) Wish List Forecaster Enter your monthly NET income: $0 ERROR: You must have a consistent monthly income of at least $500.00 Enter your monthly NET income: $500000 ERROR: Liar! I'll believe you if you enter a value no more than $400000.00 Enter your monthly NET income: $6500.50 How many wish list items do you want to forecast?: O ERROR: List is restricted to between 1 and 10 items. How many wish list items do you want to forecast?: 11 ERROR: List is restricted to between 1 and 10 items. How many wish list items do you want to forecast?: 3 Item-1 Details: Item cost: $39030.15 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 ERROR: Must be a lowercase 'y' or 'n' Does this item have financing options? [y]: Y ERROR: Must be a lowercase 'y' or 'n' Does this item have financing options? [y]: k ERROR: Must be a lowercase 'y' or 'n' Does this item have financing options? [y]: n Item-2 Details: Item cost: $99.99 ERROR: Cost must be at least $100.00 Item cost: $1200000 How important is it to you? [1=must have, 2=important, 3=want]: 3 Does this item have financing options? [y]: y Item-3 Details: Item cost: $350500.25 How important is it to you? [1=must have, 2=important, 3=want]: 2 Does this item have financing options? [y]: n Item Priority Financed Cost n 1 2 3 1 3 2 n 39030.15 1200000.00 350500.25 $ 1589530.40 Best of luck in all your future endeavours ! 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 O 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 atements 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.21f ", ... 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 1 Enter your monthly NET income: $0 ERROR: You must have a consistent monthly income of at least $500.00 Enter your monthly NET income: $500000 ERROR: Liar! I'll believe you if you enter a value no more than $400000.00 Enter your monthly NET income: $6225.88 How many wish list items do you want to forecast?: O ERROR: List is restricted to between 1 and 10 items. How many wish list items do you want to forecast?: 11 ERROR: List is restricted to between 1 and 10 items. How many wish list items do you want to forecast?: 5 Item-1 Details: Item cost: $39030.15 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 ERROR: Must be a lowercase 'y' or 'n Does this item have financing options? [y]: Y ERROR: Must be a lowercase 'y' or 'n' Does this item have financing options? [y]: k ERROR: Must be a lowercase 'y' or 'n' Does this item have financing options? [y]: n Item-2 Details: Item cost: $99.99 ERROR: Cost must be at least $100.00 Item cost: $1200000 How important is it to you? [1=must have, 2=important, 3=want]: 3 Does this item have financing options? [y]: y Item-3 Details: Item cost: $350500.25 How important is it to you? [1=must have, 2-important, 3=want]: 2 Does this item have financing options? [y]: n Item-4 Details: Item cost: $15500.75 How important is it to you? [1=must have, 2=important, 3=want]: 1 Does this item have financing options? [y]: y Item-5 Details: Item cost: $6575.55 How important is it to you? [1=must have, 2=important, 3=want]: 3 Does this item have financing options? [y]: n Item Priority Financed Cost n 1 2 3 4 5 1 3 2 1 3 n 39030.15 1200000.00 350500.25 15500.75 6575.55 n $ 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: Amount: by priority (3) $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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions