Question

In: Computer Science

This assignment is For a C++ class , I am having difficulty with getting the boolean...

This assignment is For a C++ class , I am having difficulty with getting the boolean statements the most; getting them set up properly inside the int main() area.

You have been asked to define a tip-calculating function named calcTip that could be integrated into a larger piece of software designed to improve guest service at a restaurant. As a result, you must conform to the function specification used throughout the rest of the project's code:

double calcTip(double checkAmount, bool postTax, bool round);

This function, when called, calculates and returns a tip amount in U.S. dollars determined by the values of its two boolean parameters. Any extra comments with guidance will be very apprectiated, thank you so much!
----

tipCalc's parameters:

checkAmount:

The amount of a check in U.S. dollars with tax included.
Ex. a value of 15.00 represents $15.00 USD.

postTax:

The value of the postTax parameter determines whether the function calculates a tip before or after the tax has been added to a check amount.

A value of true means that the calculated tip will be based off the entire check amount.

A value of false indicates that tax must be removed from the check amount before a tip is calculated.

round:

The value of the round parameter determines whether or not the tip amount is rounded up before being returned. A value of true indicates that the value will be rounded up.


----


Assume that the tax rate for meals is a fixed 7.8% regardless of the geographical region in which
this software may be used. Also, in the interest of elevating the standard of what constitutes a
good tip, the tip rate is a fixed 20%.

As examples, a tip calculated for an entire $20.00 check (which includes tax) without rounding would be $4.00. A tip calculated for only the pre-tax amount of a $20.00 check without rounding would be $3.69.


Implementation


You must not make any changes to the calcTip's return type or parameters.


----


In main, you must prompt for and accept user input that will be used as arguments for a calcTip function call.

You have the freedom to structure main as you see fit, provided that I can execute your program and specify the following before a call to calcTip is made:

1.) the amount of the check after tax has been applied (e.g. I can enter $20.00 or similar)
2.) whether or not I want my tip to be calculated off the full check (i.e. including tax)
3.) whether or not I want to round up my tip to the nearest U.S. dollar

You must not prompt for this input inside calcTip().


----


Once this is done, a function call to calcTip must be made inside main; its return value
will be output.


Results

Output the following text in main after making the call to calcTip:

Your tip amount is $[TIP AMOUNT]

In order to verify program correctness, you should run the program four times under the following conditions:

1.) The user wants a 20% tip on a $15 check before tax with no rounding.
2.) The user wants a 20% tip on a $15 check after tax with no rounding.
3.) The user wants a 20% tip on a $15 check before tax with rounding.
4.) The user wants a 20% tip on a $15 check after tax with rounding.

Solutions

Expert Solution

Thanks for the question.


Here is the completed code for this problem.

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution,

please rate the answer. Thanks


===========================================================================

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

double calcTip(double checkAmount, bool postTax, bool round);


double calcTip(double checkAmount, bool postTax, bool round){
  
   const double TAX_RATE = 0.078; // constant rates
   const double TIP_RATE = 0.2; // constant rates
  
   double tipAmount;
  
   // postTax is true then we first need to calculate the total amount
   // and then apply the tip rate on that total amount
   if(postTax){
       tipAmount = TIP_RATE*(checkAmount/(1+TAX_RATE));
   }else{
       // if post tax is false, then we apply the tip rate on the check amount
       tipAmount = TIP_RATE*checkAmount;
   }
  
   // if the round is true we use the next largest integer
   if(round)return ceil(tipAmount);
   // else we simply return the calculated tip amount withoout rounding off
   else return tipAmount;
  
  
  
}
int main() {
  
   double checkAmount;
   cout<<"Enter check amount: "; cin>>checkAmount;
   int choice;
  
   cout<<"Type 1-Post Tax, Type 2-Pre Tax: "; cin>>choice;
   bool postTax = choice==1;
   cout<<"Type 1-Round, Type 2-Do not Round: "; cin>>choice;
   bool round = choice==1;
  
   double tip = calcTip(checkAmount,postTax,round);
   cout<<fixed<<showpoint<<setprecision(2);
   cout<<"\nTip Amount: $"<<tip<<endl;
  
}

===============================================================

Let me know in case you have any questions. or need any help;


Related Solutions

Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I...
Hello, I am having difficulty with this assignment. I chose Amazon as my stock, but I am confused on what they're asking :             Choose a stock that interests you. Utilizing Bloomberg (or other financial websites) as a source of data, collect the following      information:                         a. The stock’s Beta                         b. The rate of return on the market (S&P 500 Index)                         c. The risk-free rate (rRF)                         d. The last dividend paid (D0)...
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting...
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting access to the vectors so that I can compare the guesses with the random numbers. I’ve been working on this for several days and don't feel any closer to a solution and could really use some help as I really don't know how to get this to work. Thank you! The assignment is: Design an ADT for a one-person guessing game that chooses 4...
I am having a hard time getting started on how to do this assignment. I would...
I am having a hard time getting started on how to do this assignment. I would like some ideas on how to start the MEMO. and maybe some ideas on what you would include. But I don't necessarily need the assignment completed for me. just need ideas!!! One routine negative message in the form of an internal memo. 400-500 word message. Single-spaced, with 1-inch margins on all sides. Objective: To announce organizational restructuring, one routine negative message addressed to employees....
I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I am having problems getting the second button part of this to work. this is for...
I am having problems getting the second button part of this to work. this is for visual basic using visual studio 2017. Please help. Create an application named You Do It 4 and save it in the VB2017\Chap07 folder. Add two labels and two buttons to the form. Create a class-level variable named strLetters and initialize it to the first 10 uppercase letters of the alphabet (the letters A through J). The first button’s Click event procedure should use the...
I am having a lot of difficulty on problem 2 I dont know how to use...
I am having a lot of difficulty on problem 2 I dont know how to use switch. Branching and looping Objectives: 1. Write a program that uses branching and a while loop. 2. Using boolean expressions and primitive variable types. Note: if you don’t have a laptop, work with another person. When you are done with the exercise, show your TA that you both worked on the assignment together and you will both get credit for the work. Problem 1:...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
These are the correct answers but I am having difficulty figuring out how these figures were...
These are the correct answers but I am having difficulty figuring out how these figures were reached. On March ​1, 2018​, Nailtique Nail Salons issued $450,000 of 15​-year, 5 percent bonds payable. The bonds were sold for $432,000. The bonds pay interest each August 31 and February 28​, and any discount or premium is amortized using​ straight-line amortization. Requirement 1. Fill in the blanks to complete each statement. a. Nailtique Nail Salons' bonds are priced at (express the price as...
I am having difficulty figuring out the rest of this problem, primarily with regards to calculating...
I am having difficulty figuring out the rest of this problem, primarily with regards to calculating APIC and Retained earnings for Stock Dividends. Also, I need assistance with the fourth problem, how to calculate the total value of shareholders' equity. Could you please help show me how to solve? Accounting for Share Transactions The shareholders' equity section of the consolidated balance sheet of Wilson Industries appeared as follows at the beginning of the year: Shareholders' Equity Class A common stock,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT