Question

In: Computer Science

In C++ write an application that calculates total retail values for 5 different shoes entered by...

In C++ write an application that calculates total retail values for 5 different shoes entered by the user.

Shoe 1 $15.50
Shoe 2 $27.30
Shoe 3 $34.50
Shoe 4 $42.11
Shoe 5 $54.25

Application must read shoe number and quantity sold for each transaction stdin, compute the total value of that sale, and add the value of that sale to a grand total for that shoe. After all data has been entered, display the total value of each of the five shoe items. Must have driver and a class, must use a switch structure to which shoes sales to update, must use a sentinel controlled loop to determine when the program should stop looping and display result.
Data members
Product price
Total sales for product(in dollars)
Member Functions
One 1 argument constructor(representing the shoe price), set the value of the data member using this argument. Getters and setters for data member, and updateTotalSales method(uses one parameter representing quantity sold and does not return a value) . must use getter and setter methods to access the fields do not access them directly. It computes the total value of the current sale by multiplying the argument passed by the shoess price. It updates the shoes total Sales data member by adding the value calculated in the previous step to the shoes existing totalSales. Must use getter and setter functions. Do not access the data members directly.

Main function
Instantiate 5 separate objects of the class Shoe, passing the appropriate argument to each constructor. The Shoe class constructor requires the price of that instance of the shoe. The prices can be hard coded numbers.
Using Sentinel controlled loop
1.   Read the shoe number and the quantity sold for one transaction.
2.   Use a switch statement to determine which Shoe objects sales to update.
3.   Call the appropriate Shoe objects updateTotalSales function.
4.   Continue loop until user enters 0 for the shoe number.
5.   After the loop is complete display each shoe objects total sales, including the dollar sign, two decimal places with a field width of 10.

Sample run
Shoe number: 2
Quantity sold: 4
Shoe number: 1
Quantity sold: 3
Shoe Number: 5
Quantity sold: 2
Shoe number: 1
Quantity sold: 2
Shoe number: 5
Quantity sold: 3
Shoe Number: 4
Quantity sold: 2
Shoe Number: 0

Total Sales
Shoe 1 : $77.50
Shoe 2: $109.20
Shoe 3: $0
Shoe 4: $84.22
Shoe 5: $271.25

Solutions

Expert Solution

#include <bits/stdc++.h>
using namespace std;

class Shoe
{
private:
   double product_price, total_sale;

public:
   Shoe(double price)
   {
      product_price = price;
      total_sale = 0;
   }
   double getPrice()
   {
      return product_price;
   }
   void setPrice(double val)
   {
      product_price = val;
   }
   double getTotalSale()
   {
      return total_sale;
   }
   void setTotalSale(double val)
   {
      total_sale = val;
   }
   void updateTotalSale(int quantity)
   {

      double temp = getPrice() * quantity + getTotalSale();
      setTotalSale(temp);
   }
};

int main()
{

   Shoe Shoe_1 = Shoe(15.50);
   Shoe Shoe_2 = Shoe(27.30);
   Shoe Shoe_3 = Shoe(34.50);
   Shoe Shoe_4 = Shoe(42.11);
   Shoe Shoe_5 = Shoe(54.25);

   while (1)
   {

      int shoe_no, quantity;
      cout << "Shoe number: ";
      cin >> shoe_no;
      if(shoe_no==0){
         cout<<"Total Sale\n";
         printf("Shoe 1 : $%.2f\n",Shoe_1.getTotalSale());
         printf("Shoe 2 : $%.2f\n",Shoe_2.getTotalSale());
         printf("Shoe 3 : $%.2f\n",Shoe_3.getTotalSale());
         printf("Shoe 4 : $%.2f\n",Shoe_4.getTotalSale());
         printf("Shoe 5 : $%.2f\n",Shoe_5.getTotalSale());
         

         return 0;
      }
      cout << "Quantity sold: ";
      cin >> quantity;
      switch (shoe_no)
      {
      
      case 1:
         Shoe_1.updateTotalSale(quantity);
         break;
      case 2:
         Shoe_2.updateTotalSale(quantity);
         break;
      case 3:
         Shoe_3.updateTotalSale(quantity);
         break;

      case 4:
         Shoe_4.updateTotalSale(quantity);
         break;

      case 5:
         Shoe_5.updateTotalSale(quantity);
         break;

      default:
         cout << "Enter Valid Choice\n";
         break;
      }
   }
}

Related Solutions

In Java write an application that calculates total retail values for 5 different shoes entered by...
In Java write an application that calculates total retail values for 5 different shoes entered by the user. Shoe 1 $15.50 Shoe 2 $27.30 Shoe 3 $34.50 Shoe 4 $42.11 Shoe 5 $54.25 Application must read shoe number and quantity sold for each product stdin, compute the total value of that sale, and add the value of that sale to a grand total for that shoe. After all data has been entered, display the total value of each of the...
In C# Create a GUI application that calculates and displays the total travel expenses of a...
In C# Create a GUI application that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: Number of days on the trip Amount of airfare, if any Amount of car rental fees, if any Number of miles driven, if a private vehicle was used Amount of parking fees, if any Amount of taxi charges, if any Conference or seminar registration fees, if any Lodging charges, per...
Create a GUI application in C# that calculates and displays the total travel expenses of a...
Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of taxi charges, if any • Conference or seminar...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
How can we write an application that calculates connascence of an application?
How can we write an application that calculates connascence of an application?
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT