Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your job is to create a program that will help someone calculate how much a customer will pay once they are done ordering. They may
Your job is to create a program that will help someone calculate how much a customer will pay once they are done ordering. They may order one or more items.
You will need to obtain some information from the user:
Each item they want to order. This includes the cost of the item using a floating point value and optionally include a name using a string
If they have another item to their order. If yes, then get that information and add to the total cost. If no then go to the next step.
They may want to add a tip as well. Prompt them to enter the tip amount and add this to the final total.
Some discounts may apply for larger orders. If the total including the tip is greater than $ they get a discount, and if the total is greater than $ and less than $ they get a discount.
You must have functions to do the following:
void welcome This function prints a welcome message to the user.
void displayMenu This function prints the menu to the user. Your menu must have items Place an order and quit. Here is an example:
Place an order
Quit
void readOptionint &option
This function will read an option and return to the called function through the reference parameter.
Call the readInt function to do this. You must catch all invalid data such as characters, negative numbers etc.
You must also do validation to make sure that the number is or and nothing other than that. Use a while loop to do this.
void readIntstring prompt, int &numnew for this level
This function should be used any time you read any integers from the user. Use this function to read the menu option from the user.
It takes a string prompt, outputs it reads a number from the user, validates and returns the num by reference.
See Sampleacpp for the function. You may use the function in the sample.
You must catch all invalid data such as characters, negative numbers etc.
void readDoublestring prompt, double &numnew for this level
This function should be used any time you read any floats or doubles from the user. Use this function to read the cost of the item, tip, etc from the user.
It takes a string prompt, outputs it reads a number from the user, validates and returns the num by reference.
Write it exactly like the readInt but declare a double or float instead of an int.
You must catch all invalid data such as characters, negative numbers etc.
void placeOrderdouble &cost
Call this function if the user selects from the menu.
This function will go through a loop and ask the user to enter item names and their cost until the user answers n to the question Do you want another item? yn: You must validate to make sure the user enters yn for this question it should not be case sensitive must accept both uppercase and lowercase Use a while loop to do this.
The total cost must be returned through the reference parameter and be printed in main
Call the readDouble function to do this. You must catch all invalid data such as characters, negative numbers etc.
Do not print anything in this function. The tip, discount, and final total must be printed in main
double tipDiscountdouble &tip, double &discount, double cost
This function takes the cost by value, and the tip and discount by reference.
The function prompts the user to enter a tip amount, and reads into the tip parameter. This will be used to calculate the total, and it will also go back to main so it can be printed in main
Call the readDouble function to do this. You must catch all invalid data such as characters, negative numbers etc.
It then calculates the discount based on the total including the tip and returns the final total to main The discount amount goes back by reference to be printed in main See sample run.
Do not print anything inside the function.
int main
Declare all variables needed.
Call the displayMenu function.
Call the readOption function.
There must be a dowhile loop in main that will keep repeating the menu until the user enters
When the user enters call the placeOrder function.
Then call the tipDiscount function that will calculate the final total and return the value. It will also receive the tip and discount amount by reference.
Print the tip, discount and final total when it comes back. Repeat the menu and continue until the user enters option
Print dollar amounts with a $ sign and output to decimal places.
When the user enters quit the program after printing a thank you message.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started