Question

Write a program that emulates a simple shopping cart. a. Calculate and display the subtotal, tax...

Write a program that emulates a simple shopping cart. a. Calculate and display the subtotal, tax and total cost. b. Use a constant variable to set a fixed tax rate of 8.875. c. Use escape characters for column alignment. d. Display correct dollar values (2 decimal places, use cout precision). e. Align data using the iomanip library column width commands. Example Output (input in bold italics )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// PLEASE LIKE THE SOLUTION All parts are Done

// For this example lets take 5 items 1.Toffee 2.Biscuit 3.Banana 4.Apple 5.Soap

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


int main(){
  
   // Part-2 storing tax rate in a variable
   string items[5] = {"Toffee","Biscuit","Banana","Apple","Soap"};

   double taxRate = 8.875;

   // Part-1 Calculate subtotal Tax Total Cost

   // First asking user to get quantity of eah item
  

   int i,j,k;
   int itemQuantity[5];
   for(i=0; i<5; i++){
       cout<<"Enter the quantity of "<<items[i]<<" ";
      
       cin>>itemQuantity[i];
   }
  
   // Set item price per unit in same order
   int itemPricePerUnit[5] = {8,5,20,40,50};

   long int subTotal=0;
  
   double tax;
  
   long int totalPerItem[5];
   for(i=0; i<5; i++){
       totalPerItem[i] = itemPricePerUnit[i] * itemQuantity[i];
   }
  
   // calculate subtotal
   for(i=0; i<5; i++){
       subTotal = subTotal + totalPerItem[i];
   }
   //calaculate tax
tax = ((double)(subTotal*taxRate/100));
  
   cout<<endl;

  

   //Printing the table using escape sequence and functions iomanip
  
   //set seperator and width

   char separator = ' ';
   cout << left << setw(5) <<"S.N."<<setfill(separator) << setw(15) <<"ItemName"<<setfill(separator)<< setw(25) <<"PricePerUnit($)"<<setfill(separator)<<setw(15) <<"Total($)"<<setfill(separator)<<endl;

   for(i=0; i<5; i++){
       cout << left << setw(5) <<(i+1)<<setfill(separator) << setw(15) <<items[i]<<setfill(separator)<< setw(25) <<itemPricePerUnit[i]<<setfill(separator)<<setw(15) <<totalPerItem[i]<<setfill(separator)<<endl;
   }

   // Printing subtotal and tax
   cout<<endl;
   cout<<"SubTotal is "<<subTotal<<"$"<<endl;

  

   // setting precision
   cout<<"Tax "<<setprecision(4)<<tax<<"$"<<endl;
  
   cout<<"Total Cost "<<setprecision(5)<<(subTotal+tax)<<"$"<<endl;

   return 0;
}
  

//Output Terminal

Add a comment
Know the answer?
Add Answer to:
Write a program that emulates a simple shopping cart. a. Calculate and display the subtotal, tax...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • Write a C program which will display the contents of a file in base-16 (hexadecimal) and...

    Write a C program which will display the contents of a file in base-16 (hexadecimal) and in ASCII. Complete the following tasks: Obtain the name of the input file from the command line. If the command-line is “./hexdump xxx.bin” then argv[1] will contain “xxx.bin”. Open the file for binary input Print the entire file, 16-bytes per line. Each line should begin with an 8-digit hexadecimal offset into the file. This is the count of the bytes that you have already...

  • Hi Guys, Need help on python questions Question 3. At the Singapore Zoo, each adult ticket...

    Hi Guys, Need help on python questions Question 3. At the Singapore Zoo, each adult ticket costs $ 39, each child (>= 3 years old, <= 12 years old) ticket costs $26.50 and each young child (< 3 years old) ticket is free. Write a program to ask the user to enter the number of tickets for each type and then display the ticket information. Your code must work exactly like the following example (the text in bold indicates the...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT