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

need help with this problem for a MAC Write a program, named lab02_p1.cpp, that

ID: 3706380 • Letter: N

Question

need help with this problem for a MAC

Write a program, named lab02_p1.cpp, that reads three integers from the keyboard and store the values into variables a, b, and c. Implement the instructions to compute the average of the three values and store the value into variable d. The program will print the values of each variables (a, b, c, and d). Example output s./lab02_pl Input value for A: 2 Input value for B: 11 Input value for C: 6 The average of 2, 11, 6 is 9.66666666667 Extra Credit A customer in a store is purchasing five items. The prices of the five items are: Price of item 1 = $12.95 Price of item 2 $24.95 Price of item 3 $6.95 Price of item 4 $14.95 Price of item 5 $3.95 Write a program, named lab02_p2.cpp, that holds the prices of the five items in five variables. Display each item's price, the subtotal of the sale, the amount of sales tax, and the total. Assume the sale tax is 11%

Explanation / Answer

The code for lab02_p1.cpp is :


#include <iostream>
using namespace std;
int main()
{
int a, b, c;
double d;
cout << "Input value for A: "; // taking the inputs
cin >> a;
cout << "Input value for B: ";
cin >> b;
cout << "Input value for C: ";
cin >> c;
d = (a + b + c) / 3.0; // computing the average
cout << "The average of " << a << ", " << b << ", " << c << " is " << d << endl; //printing the output
return 0;
}

Sample output :

Input value for A: 2
Input value for B: 11
Input value for C: 6
The average of 2, 11, 6 is 6.33333

// The output given in the question has the wrong average

The code for the extra credit question is :


#include <iostream>
using namespace std;
int main()
{
double two = 24.95, three = 6.95, four = 14.95, five = 3.95; //manual input
cout << "Price of item 1 = $" << one << endl; //printing the prices of the items
cout << "Price of item 2 = $" << two << endl;
cout << "Price of item 3 = $" << three << endl;
cout << "Price of item 4 = $" << four << endl;
cout << "Price of item 5 = $" << five << endl;
double subtotal = one + two +three +four + five; //calculating the subtotal
cout << "The subtotal is : $" << subtotal <<endl; //printing the subtotal
double tax = 0.11 * subtotal; // calculating the tax
cout << "The amount of sales tax is : $" << tax << endl; //printing the tax
double total = subtotal + tax; //calculating the total amount
cout << "The total is : $" << total <<endl; //printing the total amount
return 0;
}

Output :

Price of item 1 = $12.95
Price of item 2 = $24.95
Price of item 3 = $6.95
Price of item 4 = $14.95
Price of item 5 = $3.95
The subtotal is : $63.75
The amount of sales tax is : $7.0125
The total is : $70.7625