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

C++ programming challenge: Design a Tips class that calculates the gratuity on a

ID: 3759182 • Letter: C

Question

C++ programming challenge:

Design a Tips class that calculates the gratuity on a restaurant meal. Its only class member variable, taxRate, should be set by a one-parameter constructor to whatever rate is passed to it when a Tips object is created. If no argument is passed, a default tax rate of .065 should be used.   

The class should have just one public function, computeTips. This function needs to accept two arguments, the total bill amount and the tip rate. It should use this information to compute what the cost of the meal was before the tax was added. It should then apply the tip rate to just the meal cost portion of the bill to compute and return the tip amount.


Demonstrate the class by creating a program with a single Tips object, then loops multiple times to allow the program user to retrieve the correct tip amount using various bill totals and desired tip rates.

There needs to code to ensure that user input is validated for inappropriate values.

Explanation / Answer

#include <iostream>

using namespace std;

class Tips {

private:

double taxRate;

  

public:

Tips() {

taxRate = 0.065;

}

  

Tips(double t) {

taxRate = t;

}

  

double computeTips(double totalBillAmt, double tipRate) {

double costOfFood = (totalBillAmt/ (1 + taxRate));

return costOfFood*tipRate*100;

}

};

int main() {

Tips t(5.6);

  

while (true) {

double a,b;

cout<<"Enter bill amt: ";

cin>>a;

cout<<"Enter tip rate: ";

cin>>b;

  

if(a <= 0 || b <=0) {

cout<<"Sorry wrong input !!!!";

return 0;

}

cout<<"Tips is :"<<t.computeTips(a, b)<<" ";

  

cout<<" Enter 1 to continue: ";

int c;

cin>>c;

cout<<" ";

if(c != 1)

break;

}

  

cout<<" ";

return 0;

}

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