Advertisement
Syndragonic

Lab 5 CS311

Oct 1st, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. #define ll long long
  6. #define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0)
  7.  
  8. class Money
  9. {
  10. public:
  11. double amount; // to store the value stored in
  12.  
  13. Money() // constructor to initialize amount to zero
  14. {
  15. amount = 0;
  16. }
  17.  
  18. Money(double a) // constructor to initialize amount to something
  19. {
  20.  
  21. amount = a;
  22. }
  23.  
  24. bool operator < ( Money const&m2) // Overloading of '<'
  25. {
  26. if(amount < m2.amount) return true;
  27. return false;
  28.  
  29. }
  30.  
  31. bool operator > ( Money const&m2) // Overloading of '>'
  32. {
  33. if(amount > m2.amount) return true;
  34. return false;
  35.  
  36. }
  37.  
  38. bool operator <= ( Money const&m2) // Overloading of '<='
  39. {
  40. if(amount <= m2.amount) return true;
  41. return false;
  42.  
  43. }
  44.  
  45. bool operator >= ( Money const&m2) // Overloading of '>='
  46. {
  47. if(amount >= m2.amount) return true;
  48. return false;
  49.  
  50. }
  51.  
  52. Money percent(int percentFigure) const; // function declaration
  53.  
  54. };
  55.  
  56. Money Money::percent(int percentFigure) const // function definition
  57. {
  58. Money mon;
  59. mon.amount = ((amount)*percentFigure)/100;
  60.  
  61. return mon;
  62.  
  63. }
  64.  
  65. // Main function to try some example on above class
  66. int main()
  67. {
  68.  
  69. Money m1(100.0);
  70. Money m2(150.0);
  71.  
  72. if(m1<m2) cout<<"less"<<endl;
  73.  
  74. if(m1<=m2) cout<<"less or equal"<<endl;
  75.  
  76. m1.amount = 213.0;
  77. if(m1>m2) cout<<"greater"<<endl;
  78.  
  79. if(m1>=m2) cout<<"greater or equal"<<endl;
  80.  
  81.  
  82. Money temp;
  83.  
  84. temp = m1.percent(11);
  85. cout<<temp.amount;
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement