In: Computer Science
Write a program that computes the tax and tip on a restaurant bill for a patron with $44.50 meal charge. The tax should be 6.75% of the meal cost. The tip should be 15% of the total after adding tax. Display the meal cost, tax amount, tip amount, and total bill on the screen. (I need this to be in OOP using C++)
#include <iostream>
using namespace std;
class Bill
{
private:
double mealCharge;
double tax;
double tip;
public:
Bill(double mealCharge,double tax)
{
this->mealCharge = mealCharge;
this->tax = tax;
}
double calculateTip()
{
return (mealCharge + mealCharge*tax)*0.15;
}
void displayBill()
{
cout<<"Meal Cost :
$"<<mealCharge<<endl;
cout<<"Tax :
$"<<tax*mealCharge<<endl;
cout<<"Tip :
$"<<calculateTip()<<endl;
cout<<"Total Bill : $"<<(mealCharge
+tax*mealCharge+ calculateTip());
}
};
int main() {
Bill b(44.5,0.0675);
b.displayBill();
return 0;
}
Output:
Meal Cost : $44.5 Tax : $3.00375 Tip : $7.12556 Total Bill : $54.6
Do ask if any doubt. Please upvote.