The program assists a shopkeeper in calculating the cost of a customer\'s shoppi
ID: 3746960 • Letter: T
Question
The program assists a shopkeeper in calculating the cost of a customer's shopping cart. The shop sells six items: Asparagus Brussels Sprouts Lettuce Watermelons » Corn . Pumpkins When the program is run, it should first prompt the user for the number asparagus packages being purchased and accept input from the user with that number. The program should then prompt the user for the price of each asparagus package and accept input from the user with that number. Next, the program should do the same for Brussels sprouts. Then for corn, lettuce, pumpkins, and watermelon in turn. After inputting the number of watermelons being purchased and the price of each watermelon, the program should display a summary describing the number of each vegetable and the price of each vegetable. The program should then calculate and display a subtotal for the cost of all the vegetables being purchased The program should then calculate the sales tax on the vegetable purchase, assuming an 8.25% tax rate and print the tax. Finally, the program should display a final total consisting of the sum of the subtotal and the tax In all cases, the costs should be displayed with two decimal places. In addition, the costs should all be aligned so the decimal points line up vertically. You can assume the cart will not contain more than 99 of any particular vegetable and you can assume that no vegetable purchase will total more than $999,999.99.Explanation / Answer
C++ Program:-
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#define NO_ITEMS 6
int main(){
string items[] = {"asparagus", "brussels sprouts", "corn", "lettuce", "pumpkins", "watermelons"};
int no_items[NO_ITEMS] = {0};
double costs[NO_ITEMS] = {0};
for(int i=0; i<NO_ITEMS; i++){
cout<<" Please enter the number of "<<items[i]<<" in the cart: ";
cin>>no_items[i];
cout<<"Please enter the cost of each"<<items[i]<<": ";
cin>>costs[i];
}
cout<<setprecision(2)<<fixed;
double sub_total = 0;
for(int i=0; i<NO_ITEMS; i++){
string print_label = "The cart contains "+to_string(no_items[i])+" "+items[i]+" that each cost ";
cout<<setw(60)<<left<<print_label<<"$"<<setw(10)<<costs[i]<<endl;
sub_total += costs[i]*no_items[i];
}
double tax = sub_total * 0.0825;
cout<<setw(60)<<left<<"The subtotal of the cart is "<<"$"<<setw(10)<<sub_total<<endl;
cout<<setw(60)<<left<<"The tax is "<<"$"<<setw(10)<<tax<<endl;
cout<<setw(60)<<left<<"The total is"<<"$"<<setw(10)<<(sub_total+tax)<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.