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

14. Gratulty Calculator Design a Tips class that calculates the gratuity on a re

ID: 3606827 • Letter: 1

Question

14. Gratulty Calculator 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, computeTip. This function needs to accept two arguments, the total bill amount and the tip rate. It should use this information to compute the meal cost before any 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 that creates 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. Input Validation: If a tax rate of less than 0 is passed to the constructor, use the default rate of.065. Do not allow the total bill or the tip rate to be less than 0. arch

Explanation / Answer

#include<iostream>
#include<iomanip>

using namespace std;

class Tips{
   private:
      double tax_rate;
   public:
      Tips (double a){
          if (a > 0)
             tax_rate = a;
          else
             tax_rate = 0.065;
      }
      double computeTip(double bill, double tip_rate){
           double meal_cost = bill - tax_rate * bill;
           return tip_rate * meal_cost;
      }
};

int main(){

   Tips tip(0.075);
   string ch;
   double bill,tip_rate;

   while(1){
        cout << "Enter total bill amount, tip_rate :";
        cin >> bill >> tip_rate;
        cout << "Tip amount : " << fixed << setprecision(2) << tip.computeTip(bill,tip_rate) << endl;
        cout << "Do you want to quit? (y/n) :";
        cin >> ch;
        if (ch[0] == 'n')
           break;
   }
   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