Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The language is in C...not C++ C Programming A flower shop sells various arrange

ID: 3796593 • Letter: T

Question

The language is in C...not C++

C Programming

A flower shop sells various arrangements of a dozen flowers (roses, lilies, daisies) in two colors each (red or white) with a choice of bouquet or vase. You are given an (incomplete) source file, florist.c, of a program that takes the order for a flower arrangement from the user and displays the cost. The program uses three enumerated types to define the type of flowers, color and flower arrangement. Your task is to complete the program and implement the getCost function to compute the cost based on the following rules.

1. The base price for each of the flowers is described in the following table.

Flower Price

Roses $30

Lilies $20

Daisies $45

2. Red Lilies and Red Daisies have an added cost of $5 and White Roses have an added cost of $10. There is no additional cost for other flower/color combinations

3. Bouquets are free of charge while vases add an additional $10 charge to the total

To complete the program, perform the following tasks.

1. Insert the required items in the 3 enumerated types. The Color enumerated type has already been completed for you. Note: the rest of the program assumes that all enumerated types begin with 1, you should keep this assumption so that you don’t need to change the block of printf and scanf menu statements.

2. After taking input from the user, the program calls the function getCost to determine the cost. This function takes three input parameters, the flower type, the color and the arrangement and returns the cost (a double).

(a) The function prototype has been completed for you. Implement the definition of this function to return the cost of a given arrangement using the costs shown on the price list.

(b) In the main function, declare the other required variable(s), complete the function call with appropriate arguments and print the cost.

----Partially Completed Program----

Due to a harsh winter, Red Daisies are no longer available. We will make the appropriate changes to the getCost function to accommodate this change and to communicate errors through the function's return type. The cost will be communicated to the calling function by reference rather than as its return value. Change the signature of the getCost function to: int getCost (double *cost, Flower flower Color color Arrangement arr Change the definition of the function to do the following: If given invalid arguments, it returns a value of 1 (indicating an error) If given valid arguments, it returns a value of 0 (indicating no error) and places the cost in the cost variable (which is passed by reference) In the main function, make other necessary changes to accommodate the above In addition, you should check the return value of the getCost function and print an error message in the case that it results in an error. Name the program as florist1.c Test your changes and demonstrate them to a lab instructor.

Explanation / Answer

Please find the completed code below. Appropriate comments were given beside the code to understand easily.

Please feel free to come back for any queries.

/* 1. Insert the required items in the other 2 enumerated types*/
typedef enum { RED = 1, WHITE = 2 } Color;
typedef enum {Roses =1, Lilies = 2, Daisies = 3} Flower; // Added enum type for flowers
typedef enum {Bouquet =1, Vase = 2} Arrangement; // Added enum type for the arrangements

/*Function prototype */
double getCost(Flower flower, Color color, Arrangement arr);

int main (void) {

//You can declare variables that hold your enums just like regular variables
Flower flower;
Color color;
  
   //Declared variable for arrangement enum type
   Arrangement arr;
/* 3. Declare the other required variable(s)*/

   // cost variable for storing the total cost returned by the function getCost
   int cost;
  
//DO NOT CHANGE THIS BLOCK OF printf AND scanf STATEMENTS   
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);
  
/*4 complete the function call and print the cost*/
  
   // Added the parameter to the function
cost = getCost(flower, color, arr);

   // Printed the total cost returned by the getCost method
printf("The total cost for the arrangement of flowers is $%d", cost);
  
return 0;
}

/* 2. Implement the function get_cost*/
double getCost(Flower flower, Color color, Arrangement arr){

   int base_price =0;       // base_price variable stores the price of the flower chosen
   int additional_cost = 0;   // additional_cost stores the additional cost for the color of the flower chosen if applicable
   int arrangement_cost = 0;   // arrangement_cost stores the cost for the chosen arrangement of the flowers
   int total_cost;           // total_cost stores the total cost which is the sum of the above three variables

//you can use your enum in expressions
//Possible example: if(flower == Rose) {...}

//TODO: Compute the base price here

   if(flower == Roses)
       base_price = 30;
   else if(flower == Lilies)
       base_price = 20;
   else
       base_price = 45;
  
//TODO: add additional color-flower costs here
      
   if(flower == Roses && color == WHITE)
       additional_cost = 10;
   if(flower == Lilies && color == RED)
       additional_cost = 5;
   if(flower == Daisies && color == RED)
       additional_cost = 5;
  
//TODO: add additional cost for vases
   // if the vase arrangement is chosen, then arrangement_cost is $10 otherwise it remains 0 for bouquet arrangement

   if(arr == Vase)
       arrangement_cost = 10;
//TODO: return the total cost here


   //total cost is the sum of all the three costs evaluated as above
   total_cost = base_price + additional_cost + arrangement_cost;

   return total_cost;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote