Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. //main.cpp
  2.  
  3.  
  4. #include<iostream>
  5. #include "tips.h"
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. long double Tax1,
  12. Bill1,
  13. Grat1;
  14. int choice;
  15. choice = 0;
  16. Tips Ti;
  17. do
  18. {
  19. cout <<"Enter the following to calculate your total bill"<<endl;
  20. cout << endl;
  21.  
  22. Tax1 = 0.065;
  23. cout << "Tax Rate is "<< Tax1<<endl;
  24. Ti.setTaxRate(Tax1);
  25.  
  26. cout << endl;
  27. cout << "Enter your bill amount. "<<endl;
  28. cin >> Bill1;
  29. Ti.setBill(Bill1);
  30.  
  31. cout <<endl;
  32.  
  33. cout << "Enter the Gratuity Rate You'd like to use (in decimal form)" <<endl;
  34. cin >> Grat1;
  35. cout << endl;
  36.  
  37. Ti.setGratuity(Grat1);
  38. Ti.computeTip();
  39.  
  40. cout << "Would you like to calculate again? (Type 1 to repeat or 4 to quit) ";
  41. cin >> choice;
  42. cout << endl;
  43. cout << "-------------------------------------------------------"<<endl;
  44. cout << endl;
  45. }while(choice != 4);
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. //Tips.cpp
  58.  
  59.  
  60. #include "Tips.h"
  61. #include<iostream>
  62. #include<iomanip>
  63. #include<cstdlib>
  64. using namespace std;
  65.  
  66. void Tips::setTaxRate(double t)
  67. {taxRate = t;if(taxRate == 0)taxRate = 0.65;}
  68. void Tips::setBill(double b)
  69. {bill = b;if(bill<=0) {cout<<"Error! Your bill cannont be zero or less."<<endl; exit(0);}}
  70. void Tips::setGratuity(double g)
  71. {gratuity = g;if(gratuity<=0) {cout<<"Error! Your gratuity cannont be zero or less."<<endl; exit(0);}}
  72.  
  73. void Tips::computeTip()
  74. {
  75. double output;
  76.  
  77. output = ((taxRate * bill) + (bill) + (bill * gratuity));
  78.  
  79. cout << "You've entered: "<<endl;
  80. cout << endl;
  81. cout << fixed << showpoint << setprecision(2) << taxRate << endl;
  82. cout << fixed << showpoint << setprecision(2) << bill << endl;
  83. cout << fixed << showpoint << setprecision(2) << gratuity << endl;
  84. cout << "Your total bill is $ "<< fixed << showpoint << setprecision(2) << output <<endl;
  85. cout << endl;
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. //Tips.h
  95.  
  96. #include<iostream>
  97. #ifndef Tips_H
  98. #define Tips_H
  99. using namespace std;
  100.  
  101. class Tips
  102. {
  103. private:
  104. double taxRate,
  105. bill,
  106. gratuity;
  107.  
  108. public:
  109. Tips()
  110. {
  111. taxRate = 0;
  112. bill = 0;
  113. gratuity = 0;
  114. }
  115.  
  116. void setTaxRate(double t);
  117. void setBill(double b);
  118. void setGratuity(double g);
  119. void computeTip();
  120.  
  121. };
  122. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement