Question

In: Computer Science

Remember that great app you wrote for Yogurt Yummies (Lab 10-2). They want you to enhance...

Remember that great app you wrote for Yogurt Yummies (Lab 10-2). They want you to enhance the C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Now they need to process multiple sales. Do not change any logic for handling a single sale. Make the following enhancements:

          ● Add "v2" to the application output header and close.

          ● Declare and initialize overall totals including:

                    ü Number of sales.

                    ü Overall number of yogurts sold.

                    ü Overall sale amount after discount.

                    ü Overall tax paid.

                    ü Overall sale total.

          ● Enclose the logic for a single sale with a sentinel loop that continues to process sales until the user enters 'n'.

          ● After calculating sale totals, update overall totals.

          ● When the user enters the sentinel value ('n'), print overall totals using formatted output manipulators (setw, left/right). Run the program with invalid and valid inputs, and at least three sales. The output should look like this:

Welcome to Yogurt Yummies, v2

-----------------------------

Enter another yogurt purchase (y/n)? y

Sale 1

----------------------------------------

Enter the number of yogurts purchased (1-9): 11

Error: '11' is an invalid number of yogurts.

Enter the number of yogurts purchased (1-9): 2

Enter the percentage discount (0-20): 22

Error: '22.00' is an invalid percentage discount.

Enter the percentage discount (0-20): 4

Yogurts:                             2

Yogurt cost ($):                  3.50

Discount (%):                     4.00

Subtotal ($):                     7.00

Total after discount ($):         6.72

Tax ($):                          0.40

Total ($):                        7.12

Enter another yogurt purchase (y/n)? y

Sale 2

----------------------------------------

Enter the number of yogurts purchased (1-9): 5

Enter the percentage discount (0-20): 10

Yogurts:                             5

Yogurt cost ($):                  3.50

Discount (%):                    10.00

Subtotal ($):                    17.50

Total after discount ($):        15.75

Tax ($):                          0.94

Total ($):                       16.70

Enter another yogurt purchase (y/n)? y

Sale 3

----------------------------------------

Enter the number of yogurts purchased (1-9): 7

Enter the percentage discount (0-20): 20

Yogurts:                             7

Yogurt cost ($):                  3.50

Discount (%):                    20.00

Subtotal ($):                    24.50

Total after discount ($):        19.60

Tax ($):                          1.18

Total ($):                       20.78

Enter another yogurt purchase (y/n)? n

Overall totals

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

Sales:                               3

Yogurts:                            14

Total after discount ($):        42.07

Tax ($):                          2.52

Total ($):                       44.59

End of Yogurt Yummies, v2

This is from yogurt Yummies V1

Welcome to Yogurt Yummies

-------------------------

Enter the number of yogurts purchased (1-9): 12

Error: '12' is an invalid number of yogurts.

Enter the number of yogurts purchased (1-9): 4

Enter the percentage discount (0-20): 30

Error: '30.00' is an invalid percentage discount.

Enter the percentage discount (0-20): 10

Yogurts:                             4

Yogurt cost ($):                  3.50

Discount (%):                    10.00

Subtotal ($):                    14.00

Total after discount ($):        12.60

Tax ($):                          0.76

Total ($):                       13.36

End of Yogurt Yummies

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

#include <iostream>
#include <iomanip>
#define COST 3.50
#define TAX 0.06
using namespace std;

// Function to accept number of yogurts from the user and validates
// returns the number of yogurts by using pass by reference
void acceptNumberOfYogurts(int &numberOfYogurts)
{
  // Loops till valid number of yogurts entered by the user
  do
  {
    // Accepts number of yogurts
    cout << "\n Enter the number of yogurts purchased (1-9): ";
    cin >> numberOfYogurts;

    // Checks if number of yogurts is greater than or equals to 1
    // and number of yogurts is less than or equals to 9
    if (numberOfYogurts >= 1 && numberOfYogurts <= 9)
      // Come out of the loop for valid data
      break;
    // Otherwise invalid data display error message
    else
      cout << "\n Error: \'" << numberOfYogurts << "\' is an invalid number of yogurts.";
  } while (1); // End of do - whil loop
} // End of function

// Function to accept percentage discount from the user and validates
// returns the percentage discount by using pass by reference
void acceptPercentageDiscount(double &percentageDiscount)
{
  // Loops till valid percentage discount entered by the user
  do
  {
    // Accepts percentage discount
    cout << "\n Enter the percentage discount (0 - 20): ";
    cin >> percentageDiscount;

    // Checks if percentage discount is greater than or equals to 0
    // and percentage discount is less than or equals to 20
    if (percentageDiscount >= 0 && percentageDiscount <= 20)
      // Come out of the loop for valid data
      break;
    // Otherwise invalid data display error message
    else
      cout << "\n Error: \'" << percentageDiscount << "\' is an invalid percentage discount.";
  } while (1); // End of do - whil loop
} // End of function

// main function definition
int main()
{
  int numberOfYogurtsPurchased;
  double percentageDiscount;

  int countSales = 0;
  int totalYogurts = 0;

  double subTotal = 0.0;
  double afterDiscount = 0.0;
  double tax = 0.0;
  double total = 0.0;

  double totalAfterDiscount = 0.0;
  double totalTax = 0.0;
  double overalTotal = 0.0;
  char choice;
  cout<<"Welcome to Yogurt Yummies, v2\n-----------------------------\n";
  // Loops till user choice is not equals to 'n' or 'N'
  do
  {
    // Accepts user choice
    cout << "\n Enter another yogurt purchase (y/n)? ";
    cin >> choice;

    // Checks if user choice is equals to 'n' or 'N' then come out of the loop
    if (choice == 'n' || choice == 'N')
      break;

    // Displays sales counter
    cout << "\n Sales: " << ++countSales;
    cout << "\n ----------------------------------------";
    // Calls the function to accept number of yogurts purchased
    acceptNumberOfYogurts(numberOfYogurtsPurchased);
    // Calls the function to accept percentage discount
    acceptPercentageDiscount(percentageDiscount);

    // Calculates to total number of yogurts purchased
    totalYogurts += numberOfYogurtsPurchased;
    // Calculates sub total by multiplying number of yogurts purchased with cost per of yogurts purchased
    subTotal = numberOfYogurtsPurchased * COST;
    // Calculate amount after discount
    afterDiscount = subTotal - (subTotal * percentageDiscount) / 100.0;
    // Calculates tax
    tax = (afterDiscount * TAX);
    // Calculates total
    total = afterDiscount + tax;

    // Displays current purchase report
    cout << left << setw(28) << "\n Yogurts: " << right << numberOfYogurtsPurchased;
    cout << left << setw(28) << "\n Yogurt cost ($): " << right << fixed << setprecision(2) << COST;
    cout << left << setw(28) << "\n Discount (%): " << right << percentageDiscount;
    cout << left << setw(28) << "\n Subtotal ($): " << right << subTotal;
    cout << left << setw(28) << "\n Total after discount ($): " << right << afterDiscount;
    cout << left << setw(28) << "\n Tax ($): " << right << tax;
    cout << left << setw(28) << "\n Total ($): " << right << total;

    // Calculates total of after discount
    totalAfterDiscount += afterDiscount;
    // Calculates total tax
    totalTax += tax;
    // Calculates overall total
    overalTotal += total;

  } while (1); // End of do - while loop

  // Displays overall report
  cout << "\n Overall totals";
  cout << "\n ========================================";
  cout << left << setw(28) << "\n Sales: " << right << countSales;
  cout << left << setw(28) << "\n Yogurts: " << right << totalYogurts;
  cout << left << setw(28) << "\n Total after discount ($): " << right << totalAfterDiscount;
  cout << left << setw(28) << "\n Tax ($): " << right << setprecision(2) << totalTax;
  cout << left << setw(28) << "\n Total ($): " << right << setprecision(2) << overalTotal;
  return 0;
} // End of function

Related Solutions

Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and...
Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:           ● Subtotal using a cost of $3.50 per yogurt. ● Subtotal...
For this portion of the lab, you will reuse the program you wrote before. That means...
For this portion of the lab, you will reuse the program you wrote before. That means you will open the lab you wrote in the previous assignment and change it. You should NOT start from scratch. Also, all the requirements/prohibitions from the previous lab MUST also be included /omitted from this lab. Redesign the solution in the following manner: 1. Create a menu and ask the user which of the following conversions they wish to perform: a. Miles to kilometers...
For this portion of the lab, you will reuse the Python program you wrote before. That...
For this portion of the lab, you will reuse the Python program you wrote before. That means you will open the lab you wrote in the previous assignment and change it. You should NOT start from scratch. Also, all the requirements/prohibitions from the previous lab MUST also be included /omitted from this lab.    Redesign the solution so that some portions of the code are repeated. In lab 4 you validated input to ensure that the user entered inputs within...
Business Scenario: You have a great idea for a new mobile app. You do not have...
Business Scenario: You have a great idea for a new mobile app. You do not have any technical expertise to create one, however, nor do you have any idea on how to attract the money you need to get your idea off the ground or marketed. You are partway through your diploma at BCIT and have a couple of friends in your class who have some of the skills and connections you think you need. You talk to them at...
17.1 Lab Lesson 10 (Part 1 of 2) Part of lab lesson 10 There are two...
17.1 Lab Lesson 10 (Part 1 of 2) Part of lab lesson 10 There are two parts to lab lesson 10. The entire lab will be worth 100 points. Bonus points for lab lesson 10 There are also 10 bonus points. To earn the bonus points you have to complete the Participation Activities and Challenge Activities for zyBooks/zyLabs unit 16 (Gaddis Chapter 7). These have to be completed by the due date for lab lesson 10. For example, if you...
I want you guys to rewrite this lab procedure, and it is fine if it was...
I want you guys to rewrite this lab procedure, and it is fine if it was shorter than this. An air track was fitted with two photocell bridges, one on each side of the collision region. Each bridge was operating in a gate mode timer that allows the collection of time intervals before and after collision. To ensure that friction and gravity have minimal effects, the track was leveled. Before starting the experiment, we ensured that loss in velocity was...
In this lab, I want you to take in a numeric grade as an integer and...
In this lab, I want you to take in a numeric grade as an integer and then print a letter grade per the table below: 90 or above is an A 80 or above is a B 70 or above is a C 60 or above is a D Below a 60 is an F You must use a branching statement that prints the appropriate letter grade based on the user input2. Please comment your code
Lab 14 - Krazy Karl's Pizza Order App You have been hired by Krazy Karl’s as...
Lab 14 - Krazy Karl's Pizza Order App You have been hired by Krazy Karl’s as a freelance application (app) developer. They have asked you to build an app that customers can use to order pizza. The app will ask the user for their name, pizza type, size, and number of pizzas. Then provide the user with an order confirmation, which must include the total cost. In this lab, you will practice using String format() and switch statements. Additionally, you...
MAT 152 Lab 4    Show your work, where appropriate. Remember that you do not have...
MAT 152 Lab 4    Show your work, where appropriate. Remember that you do not have to show any work for what you enter into your graphing calculator. CITY is the city fuel consumption in miles per gallon and HWY is the highway fuel consumption in miles per gallon. Car City (x) Hwy (y) Acura RL 18 26 Audi A6 21 29 Buick LaCrosse 20 30 Chrysler 300 17 25 Infiniti M35 18 25 Mazda 3 26 32 Mercury Gr...
2) You want to buy a house for $400,000 with 10% down payment. You take two...
2) You want to buy a house for $400,000 with 10% down payment. You take two mortgages to over the $360,000 needed to buy the house. They are: • Loan 1: Loan amount $160,000, fully amortizing 30-year fixed rate mortgage for 4.2%. This loan has 2 points and 1% pre-payment penalty. • Loan 2: Loan amount $200,000, fully amortizing 15-year, 5-year ARM with reset every five years. Initial interest rate is 3.6%. Margin set at 2% over prime rate. Expected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT