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

C++ PROGRAMMING Functions Customer Receipt Write a program that calculates the r

ID: 3821442 • Letter: C

Question

C++ PROGRAMMING Functions
Customer Receipt
Write a program that calculates the receipt for a customer’s purchase.
1) Define the following functions:
• A function that prompts the user for an item name and cost.
Function prototype:
void GetItem(string &name, float &cost);
Input validation:
The cost cannot be less than 0.
• A function that calculates the subtotal of three items.
Function prototype:
float CalculateSubTotal(float cost1,float cost2,float cost3);
• A function that calculates and returns 6% of a float value.
Function prototype:
float CalculateTax(float sub);
• A function that displays a receipt as follows:
Items Cost
-----------------
sweater $25.00
shoes $37.00
pants $26.00

Subtotal: $88.00
Tax: $5.28
Total: $93.28
Function prototype:
void DisplayReceipt(string name1, string name2, string name3, float
cost1, float cost2, float cost3, float sub, float tax);
2)
In main():
• Declare the following variables:
item1Name1, item2Name, item3Name, item1Cost, item2Cost, item3Cost, subtotal
and totaltax
• Call the function GetItem three times to prompt for three item names and
costs.
• Call the function CalculateSubTotal to calculate the total of the three
items and store this value in subtotal.
• Call the function CalculateTax to calculate the sales tax and store this
value in totaltax.
• Call the function DisplayReceipt.

Explanation / Answer

#include <iostream>

using namespace std;
void GetItem(string &name, float &cost) {
cout<<"Enter the item name: ";
cin >> name;
cout<<"Enter the cost of an item: ";
cin >> cost;
}
float CalculateSubTotal(float cost1,float cost2,float cost3) {
return cost1 + cost2 + cost3;
}
float CalculateTax(float sub) {
return (sub*6)/100;
}
int main()
{
string item1Name, item2Name, item3Name;
float item1Cost, item2Cost, item3Cost, subtotal,totaltax;
GetItem(item1Name,item1Cost );
GetItem(item2Name,item2Cost );
GetItem(item3Name,item3Cost );
float subTotal = CalculateSubTotal(item1Cost, item2Cost, item3Cost);
float tax = CalculateTax(subTotal);
cout<<item1Name<<" $"<<item1Cost<<endl;
cout<<item2Name<<" $"<<item2Cost<<endl;
cout<<item3Name<<" $"<<item3Cost<<endl;
cout<<"SubTotal $"<<subTotal<<endl;
cout<<"Tax $"<<tax<<endl;
cout<<"Total $"<<(subTotal+tax)<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Enter the item name: sweater                                                                                                                                                                                                                                             

Enter the cost of an item: 25.00                                                                                                                                                                                                                                         

Enter the item name: shoes                                                                                                                                                                                                                                               

Enter the cost of an item: 37.00                                                                                                                                                                                                                                         

Enter the item name: pants                                                                                                                                                                                                                                               

Enter the cost of an item: 26.00                                                                                                                                                                                                                                         

sweater $25                                                                                                                                                                                                                                                              

shoes $37                                                                                                                                                                                                                                                                

pants $26                                                                                                                                                                                                                                                                

SubTotal $88                                                                                                                                                                                                                                                             

Tax $5.28                                                                                                                                                                                                                                                                

Total $93.28

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