Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Aaron Lakely is going to the grocery store to buy some bananas and apples, bo

ID: 3667258 • Letter: 4

Question

4. 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

IPO chart for the program

----------------------------------------------------------------------------------------------------------
Input                                  Processing                                                 Output
----------------------------------------------------------------------------------------------------------
sales tax=0.03                                                                                             totalcost
bananas (in pounds)      
apples(in pounds)
POUND_BANANA=0.99
POUND_APPLE=1.89
                                            1.Enter bananas in pounds
            2.Read bananas
               3.Enter apples in pounds
         4.Read apples
            5.Calculate multiply the banans by POUND_BANANA
               and apples by POUND_APPLE and then sum.
               cost=banans*POUND_BANANA+apples*POUND_APPLE
         6. tax=cost*salesTax
            7. Find the total cost as sum of banans and apples withe sales tax
                totalcost=cost+tax
          

---------------------------------------------------------------------------------------------------------------------------------------------
First desk-check calculation

Number of bananas=2
Number of apples=3.5
cost=2*0.99+3.5*1.89
cost=1.98+6.615
cost=8.595
sales tax=0.257
totalcost=8.595+0.257
totalcost=8.852


Second desk-check calculation

Number of bananas=5
Number of apples=5.5
cost=5*0.99+5.5*1.89
cost=4.95+10.395
cost=15.345
sales tax=0.460
totalcost=15.345+0.460
totalcost=15.80535

------------------------------------------------------------------------------
//C++ program to find the total cost of the Aaron Lakely's purchase

//C++ declaration statements to find the total cost of the itesm purchased.
#include<iostream>
using namespace std;
int main()
{

   //declaration of constants
   const double SALESTAX=0.03;
   const double POUND_BANANA=0.99;
   const double POUND_APPLE=1.89;
  
   double tax=0;
   double cost=0;
   double totalcost=0;
   double bananas_in_pounds;
   double apples_in_pounds;
  


   cout<<"Enter number of bananas( in pounds) : ";
   //read bananas in pounds
   cin>>bananas_in_pounds;

   cout<<"Enter number of apples( in pounds) : ";
   //read apples in pounds
   cin>>apples_in_pounds;

   //calculate the cost
   cost=bananas_in_pounds*POUND_BANANA+apples_in_pounds*POUND_APPLE;

   //calculate tax
   tax=cost*SALESTAX;


   //print total cost
   cout<<"Total cost : $"<<(cost+tax)<<endl;


   system("pause");
   return 0;
}

--------------------------------------------------------------------------------------------------------------------------------
Sample output:
Enter number of bananas( in pounds) : 2
Enter number of apples( in pounds) : 3.5
Total cost : $8.85285

sample run2:
Enter number of bananas( in pounds) : 5
Enter number of apples( in pounds) : 5.5
Total cost : $15.8053

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote