Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include<iostream>
- #include "tips.h"
- using namespace std;
- int main()
- {
- long double Tax1,
- Bill1,
- Grat1;
- int choice;
- choice = 0;
- Tips Ti;
- do
- {
- cout <<"Enter the following to calculate your total bill"<<endl;
- cout << endl;
- Tax1 = 0.065;
- cout << "Tax Rate is "<< Tax1<<endl;
- Ti.setTaxRate(Tax1);
- cout << endl;
- cout << "Enter your bill amount. "<<endl;
- cin >> Bill1;
- Ti.setBill(Bill1);
- cout <<endl;
- cout << "Enter the Gratuity Rate You'd like to use (in decimal form)" <<endl;
- cin >> Grat1;
- cout << endl;
- Ti.setGratuity(Grat1);
- Ti.computeTip();
- cout << "Would you like to calculate again? (Type 1 to repeat or 4 to quit) ";
- cin >> choice;
- cout << endl;
- cout << "-------------------------------------------------------"<<endl;
- cout << endl;
- }while(choice != 4);
- }
- //Tips.cpp
- #include "Tips.h"
- #include<iostream>
- #include<iomanip>
- #include<cstdlib>
- using namespace std;
- void Tips::setTaxRate(double t)
- {taxRate = t;if(taxRate == 0)taxRate = 0.65;}
- void Tips::setBill(double b)
- {bill = b;if(bill<=0) {cout<<"Error! Your bill cannont be zero or less."<<endl; exit(0);}}
- void Tips::setGratuity(double g)
- {gratuity = g;if(gratuity<=0) {cout<<"Error! Your gratuity cannont be zero or less."<<endl; exit(0);}}
- void Tips::computeTip()
- {
- double output;
- output = ((taxRate * bill) + (bill) + (bill * gratuity));
- cout << "You've entered: "<<endl;
- cout << endl;
- cout << fixed << showpoint << setprecision(2) << taxRate << endl;
- cout << fixed << showpoint << setprecision(2) << bill << endl;
- cout << fixed << showpoint << setprecision(2) << gratuity << endl;
- cout << "Your total bill is $ "<< fixed << showpoint << setprecision(2) << output <<endl;
- cout << endl;
- }
- //Tips.h
- #include<iostream>
- #ifndef Tips_H
- #define Tips_H
- using namespace std;
- class Tips
- {
- private:
- double taxRate,
- bill,
- gratuity;
- public:
- Tips()
- {
- taxRate = 0;
- bill = 0;
- gratuity = 0;
- }
- void setTaxRate(double t);
- void setBill(double b);
- void setGratuity(double g);
- void computeTip();
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement