Aaron Lakely is going to the grocery store to buy some bananas and apples, both
ID: 3890190 • Letter: A
Question
Aaron Lakely is going to the grocery store to buy some bananas and apples, both of which are sold by the pound. He wants a program that calculates and displays the total cost of his order, including a 3% sales tax. First, create an IPO chart for this problem, and then desk-check the algorithm twice. For the first desk-check, use 2 and 3.5 as the number of pounds of bananas and apples, respectively. And use $0.99 and $1.89 as the price per pound of bananas and apples, respectively. For the second desk-check, use your own set of data. After desk-checking the algorithm, list the input, processing, and output items in a chart similar to the one shown in Figure 3-25, and then enter the appropriate C++ declaration statements.
Explanation / Answer
Given below is the C++ program for the question. The question asks to make an IPO chart similar to fig 3-25, which is not uploaded in the question.
Input bananas_qty
Input apples_qty
Set BANANAS_COST_PER_POUND = 0.99
Set APPLES_COST_PER_POUND = 1.99
Set SALES_TAX_RATE = 0.03
Calculate
bananas_cost = bananas_qty * BANANAS_COST_PER_POUND
apples_cost = apples_qty * APPLES_COST_PER_POUND
total = bananas_cost + apples_cost
sales_tax = total * SALES_TAX_RATE
total = total + sales_tax
Print bananas_cost, apples_cost, sales_tax and total
bananas_cost
apples_cost
sales_tax
total
You can use const keyword (if you have taught in class) for the variables BANANAS_COST_PER_POUND, APPLES_COST_PER_POUND, SALES_TAX_RATE . Was not sure if its covered for you in class.
const double BANANAS_COST_PER_POUND = 0.99;
const double APPLES_COST_PER_POUND = 1.89;
const double SALES_TAX_RATE = 0.03 ; // 3% sales tax
===========================
The full program and its output is given below
#include <iostream>
using namespace std;
int main()
{
double BANANAS_COST_PER_POUND = 0.99;
double APPLES_COST_PER_POUND = 1.89;
double SALES_TAX_RATE = 0.03 ; // 3% sales tax
//quantity of bananas and apples in pounds
double bananas_qty, apples_qty;
double bananas_cost, apples_cost, tax;
cout << "How many pounds of bananas? " ;
cin >> bananas_qty;
cout << "How many pounds of apples? " ;
cin >> apples_qty;
//calculate total cost
double total = 0;
bananas_cost = bananas_qty * BANANAS_COST_PER_POUND;
apples_cost = apples_qty * APPLES_COST_PER_POUND;
total = bananas_cost + apples_cost;
tax = SALES_TAX_RATE * total;
total = total + tax; //add tax
//display the order
cout << "Order details " << endl;
cout << "Bananas: " << bananas_qty << " pounds @ $" << BANANAS_COST_PER_POUND << " per pound = $" << bananas_cost << endl;
cout << "Apples: " << apples_qty << " pounds @ $" << APPLES_COST_PER_POUND << " per pound = $" << apples_cost << endl;
cout << "Sales Tax @ 3% = $" << tax << endl;
cout << "Total = $" << total << endl;
}
output
How many pounds of bananas? 2
How many pounds of apples? 3.5
Order details
Bananas: 2 pounds @ $0.99 per pound = $1.98
Apples: 3.5 pounds @ $1.89 per pound = $6.615
Sales Tax @ 3% = $0.25785
Total = $8.85285
============
Hope it helped. If it did, please do rate the answer . Thank you very much.
Input Processing OutputInput bananas_qty
Input apples_qty
Set BANANAS_COST_PER_POUND = 0.99
Set APPLES_COST_PER_POUND = 1.99
Set SALES_TAX_RATE = 0.03
Calculate
bananas_cost = bananas_qty * BANANAS_COST_PER_POUND
apples_cost = apples_qty * APPLES_COST_PER_POUND
total = bananas_cost + apples_cost
sales_tax = total * SALES_TAX_RATE
total = total + sales_tax
Print bananas_cost, apples_cost, sales_tax and total
bananas_cost
apples_cost
sales_tax
total
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.