Question

Use C++, Modify the content so that it produces the required output.   /* Program uses the...

Use C++, Modify the content so that it produces the required output.  

/*
Program uses the cost of a meal to determine the total amount paid given 6% sales tax and a 20% tip
*/


// DEFINE THE FOLLOWING FUNCTIONS. Use the information provided for each function to determine
// the function header and the function body.

// return type: float
// Parameters: none
// Purpose: This function prompts the user for the cost of a meal, validates it and returns it.
// Input validation: The cost of the meal should be at least 0.
GetMealCost() {

}


// return type: float
// Parameters: float (mealCost)
// Purpose: This function calculates and returns 6% of the meal cost.
CalculateTax(mealCost) {

}


// return type: float
// Parameters: float (mealCost)
// Purpose: This function calculates and returns 20% of the meal cost.
CalculateTip(mealCost) {

}


// return type: float
// Parameters: 3 floats(mealCost, tax, tip)
// This function calculates and returns the total cost of the meal
CalculateTotalCost(mealCost, tax, tip) {

}


// return type: none
// Parameters: 4 floats(mealCost, tax, tip, total)
// This function displays a receipt as follows:
// Meal Receipt
// *****************
// Meal Cost: $20.00
// Tax: $1.20
// Tip: $4.00
// Total: $25.40
DisplayReceipt(mealCost, tax, tip, total) {

}


int main() {
// declare and initialize variables
float mycost, mytax, mytip, mytotal;
mycost = mytax = mytip = mytotal = 0.0;
  

// call a function to prompt for a meal cost and store the result in mycost
  


  
// call a function to calculate the tax for the meal and store the result in mytax
  

// call a function to calculate the tip for the meal and store the result in mytip
  



// call a function to calculate the total cost of the meal and store the result in mytotal
  


  
// invoke a function to display the receipt for the meal

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

// DEFINE THE FOLLOWING FUNCTIONS. Use the information provided for each function to determine
// the function header and the function body.

// return type: float
// Parameters: none
// Purpose: This function prompts the user for the cost of a meal, validates it and returns it.
// Input validation: The cost of the meal should be at least 0.
float GetMealCost()
{
// To store meal cost
float mealCost;

// Loops till valid meal cost entered by the user
do
{
// Accepts meal cost
cout<<"\n Enter meal cost: ";
cin>>mealCost;

// Checks if meal cost is less than 0 then display error message
// and asks again
if(mealCost < 0)
cout<<"\n The cost of the meal should be at least 0. \n Try again.";

// Otherwise valid meal cost. Return the cost
else
return mealCost;
}while(1);// End of do - while loop
}// End of function

// return type: float
// Parameters: float (mealCost)
// Purpose: This function calculates and returns 6% of the meal cost.
float CalculateTax(float mealCost)
{
return (mealCost * 0.06);
}// End of function

// return type: float
// Parameters: float (mealCost)
// Purpose: This function calculates and returns 20% of the meal cost.
float CalculateTip(float mealCost)
{
return (mealCost * 0.2);
}// End of function

// return type: float
// Parameters: 3 floats(mealCost, tax, tip)
// This function calculates and returns the total cost of the meal
float CalculateTotalCost(float mealCost, float tax, float tip)
{
return (mealCost + tax + tip);
}// End of function


// return type: none
// Parameters: 4 floats(mealCost, tax, tip, total)
// This function displays a receipt as follows:
// Meal Receipt
// *****************
// Meal Cost: $20.00
// Tax: $1.20
// Tip: $4.00
// Total: $25.40
void DisplayReceipt(float mealCost, float tax, float tip, float total)
{
cout<<"\n\n Meal Receipt";
cout<<"\n *****************";
cout<<"\n Meal Cost: $"<<mealCost;
cout<<"\n Tax: $"<<tax;
cout<<"\n Tip: $"<<tip;
cout<<"\n Total: $"<<total;
}// End of function

// main function definition
int main()
{
// declare and initialize variables
float mycost, mytax, mytip, mytotal;
mycost = mytax = mytip = mytotal = 0.0;

// Calls the function to prompt for a meal cost and store the result in mycost
mycost = GetMealCost();

// Call the function to calculate the tax for the meal and store the result in mytax
mytax = CalculateTax(mycost);

// Call the function to calculate the tip for the meal and store the result in mytip
mytip =CalculateTip(mycost);

// Call the function to calculate the total cost of the meal and store the result in mytotal
mytotal = CalculateTotalCost(mycost, mytax, mytip);

// Calls the function to display the receipt for the meal
DisplayReceipt(mycost, mytax, mytip, mytotal);
return 0;
}// End of main function

Sample Output:

Enter meal cost: -12

The cost of the meal should be at least 0.
Try again.
Enter meal cost: 100


Meal Receipt
*****************
Meal Cost: $100
Tax: $6
Tip: $20
Total: $126

Add a comment
Know the answer?
Add Answer to:
Use C++, Modify the content so that it produces the required output.   /* Program uses the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help programming this question using C language. This program uses input data entered in...

    I need help programming this question using C language. This program uses input data entered in command line at the same time when the command or .exe file is entered. They are called command-line arguments. Because everything entered in command line is taken as a string, these arguments including the command itself or the .exe file name are stored in an array of char pointers, each pointer points to the first character of a string (i.e., argument). The inputs can...

  • *In C language *Without using Strings Write a program that uses a for loop to calculate...

    *In C language *Without using Strings Write a program that uses a for loop to calculate the average cost of a dinner for a group of 10 people. Your program will use a function that will ask the user to enter in the price of each meal and return the value entered. Your program will calculate the total due for all 10 meals, the total tip using a defined constant of 20%, and the average price of a dinner. You...

  • Help with Flowgirthim . Use the flowgorithim app to answer. In this program you find the...

    Help with Flowgirthim . Use the flowgorithim app to answer. In this program you find the average of an array. You will need 4 functions in total. Main function: Just call the other functions and declare an empty array of size 5. Output the sum of the array, the average of the array, and output the array. inputArray(real array): Prompt the user for input and store information in the array and return the array. Make sure you make the parameter...

  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • Question 1 (1 point) Which of the following is a reason to use functions? Question 1...

    Question 1 (1 point) Which of the following is a reason to use functions? Question 1 options: To make it easier to read by keeping sections of code shorter. To avoid duplicating code. all of the above To make the code more organized. Question 2 (1 point) When the execution of a function ends, what Python code is executed next? Question 2 options: The function is automatically executed again. The line of code immediately after the end of the function....

  • need help with this python program NOTE: You are NOT permitted to use ANY global variables....

    need help with this python program NOTE: You are NOT permitted to use ANY global variables. The use of any global variables will result in a deduction of 20%. NOTE: There is NO input or printing anywhere other than main! Significant points will be deducted if you violate this constraint! The following UML diagrams specify three classes. The RC_Filter class has a composition relationship with the Resistor and Capacitor classes. Your job is to implement these three classes as specified...

  • The XYZ Company needs you to write a program that will allow them to enter the...

    The XYZ Company needs you to write a program that will allow them to enter the weekly sales for a salesperson and then the program will calculate things such as most sales (and what day on which they happened), least sales (and day on which they happened), total sales, and daily average. The program will need to do the following: • Validate the user input to ensure that it is not less than 0.0 (0.0 will be acceptable if there...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT