Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Enumerated types are useful, but safety is not always guaranteed. To illustrate, the following code would compile: Color c = 10; even though there is

Enumerated types are useful, but safety is not always guaranteed. To illustrate, the following code would compile: Color c = 10; even though there is no color corresponding to the integer 10. What happens if you call your getCost function using such a color? To prevent this, we will add additional code to detect and handle this type of error situation. 1. Add another enumerated type called Error that will recognize the following error types: No Error, Unavailable Selection Error, Invalid Argument Error, and Null Pointer Error (note: a good convention is to use all-caps with words separated by an underscore). 2. Add additional code and checks to your getCost function to check for valid input (on all the arguments). 3. Modify the getCost method to return one of your enumerated types based on the type of error encountered. 4. Modify your main program to check for the type of error returned and print an appropriate error message.

------------------------------------------------------------------Partial Code-------------------------------------------------------------------

#include

typedef enum { RED = 1, WHITE = 2 } Color;

typedef enum {Roses = 1, Lilies = 2, Daisies = 3} Flower;

typedef enum {Bouquet = 1, Vase = 2} Arrangement;

double getCost(Flower flower, Color color, Arrangement arr);

int main (void) {

Flower flower;

Color color;

Arrangement arr;

int cost;

printf(" Types of flowers ");

printf("1. Roses ");

printf("2. Lilies ");

printf("3. Daises ");

printf("Please enter the item number for your choice: ");

scanf("%d", &flower);

printf(" Color choices ");

printf("1. Red ");

printf("2. White ");

printf("Please enter the item number for your choice: ");

scanf("%d", &color);

printf(" Arrangements ");

printf("1. Bouquet ");

printf("2. Vase ");

printf("Please enter the item number for your choice: ");

scanf("%d", &arr);

cost = getCost(flower, color, arr);

printf("The total cost for the arrangement of flowers is %d", cost);

return 0;

}

double getCost(Flower flower, Color color, Arrangement arr){

int base_price =0;

int additional_cost = 0;

int arrangement_cost = 0;

int total_cost;

if(flower == Roses){

base_price = 30;

}

else if(flower == Lilies){

base_price = 20;

}

else{

base_price = 45;

}

if(flower == Roses && color == WHITE){

additional_cost = 10;

}

if(flower == Lilies && color == RED){

additional_cost = 5;

}

if(flower == Daisies && color == RED){

additional_cost = 5;

}

if(arr == Vase){

arrangement_cost = 10;

}

total_cost = base_price + additional_cost + arrangement_cost;

return total_cost;

}

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

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

help me please ! 123 0060 1313] bent. 123 0060 1313] bent

Answered: 1 week ago

Question

8. Measure the effectiveness of the succession planning process.

Answered: 1 week ago