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: 3824612 • Letter: C

Question

C++ PROGRAMMING FUNCTIONS

Customer Receipt
Write a program that calculates the receipt for a customer’s purchase.

I. Define the following functions:
1. 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.
2. A function that calculates the subtotal of three items.
Function prototype:
float CalculateSubTotal(float cost1,float cost2,float cost3);
3. A function that calculates and returns 6% of a float value.
Function prototype:
float CalculateTax(float sub);
4. 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);
II. In main():
1. Declare the following variables:
item1Name1, item2Name, item3Name, item1Cost, item2Cost, item3Cost, subtotal and totaltax
2. Call the function GetItem three times to prompt for three item names and costs.
3. Call the function CalculateSubTotal to calculate the total of the three items and store this value in subtotal.
4. Call the function CalculateTax to calculate the sales tax and store this value in totaltax.
5. Call the function DisplayReceipt.

Explanation / Answer

Hi, Please find my implementation.

#include <iostream>
using namespace std;

void GetItem(string &name, float &cost);
float CalculateSubTotal(float cost1,float cost2,float cost3);
float CalculateTax(float sub);
void DisplayReceipt(string name1, string name2, string name3, float cost1, float cost2,
   float cost3, float sub, float tax);

int main(){

   string item1Name1, item2Name, item3Name;
   float item1Cost, item2Cost, item3Cost, subtotal, totaltax;

   GetItem(item1Name1, item1Cost);
   GetItem(item2Name, item2Cost);
   GetItem(item3Name, item3Cost);

   subtotal = CalculateSubTotal(item1Cost, item2Cost, item3Cost);
   totaltax = CalculateTax(subtotal);

   DisplayReceipt(item1Name1, item2Name,item3Name,item1Cost, item2Cost,item3Cost, subtotal, totaltax);

   return 0;
}

// function defination
void GetItem(string &name, float &cost){

   cout<<"Enter customer name: ";
   getline(cin, name);

   cout<<"Enter cost(> 0) : ";
   cin>>cost;

   while(cost < 0){
       cout<<"Enter cost(> 0) : ";
       cin>>cost;
   }
}

float CalculateSubTotal(float cost1,float cost2,float cost3){
   return (cost1 + cost2 + cost3);
}

float CalculateTax(float sub){
   return (sub*0.1);
}

void DisplayReceipt(string name1, string name2, string name3, float cost1, float cost2,
   float cost3, float sub, float tax){

   cout<<"Items Cost"<<endl;
   cout<<"--------------------------------"<<endl;
   cout<<name1<<" $"<<cost1<<endl;
   cout<<name2<<" $"<<cost2<<endl;
   cout<<name3<<" $"<<cost3<<endl;
   cout<<"Subtotal: $"<<sub<<endl;
   cout<<"Tax: $"<<tax<<endl;
   cout<<"Total: $"<<(sub+tax)<<endl;
}

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