Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- #define ll long long
- #define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0)
- class Money
- {
- public:
- double amount; // to store the value stored in
- Money() // constructor to initialize amount to zero
- {
- amount = 0;
- }
- Money(double a) // constructor to initialize amount to something
- {
- amount = a;
- }
- bool operator < ( Money const&m2) // Overloading of '<'
- {
- if(amount < m2.amount) return true;
- return false;
- }
- bool operator > ( Money const&m2) // Overloading of '>'
- {
- if(amount > m2.amount) return true;
- return false;
- }
- bool operator <= ( Money const&m2) // Overloading of '<='
- {
- if(amount <= m2.amount) return true;
- return false;
- }
- bool operator >= ( Money const&m2) // Overloading of '>='
- {
- if(amount >= m2.amount) return true;
- return false;
- }
- Money percent(int percentFigure) const; // function declaration
- };
- Money Money::percent(int percentFigure) const // function definition
- {
- Money mon;
- mon.amount = ((amount)*percentFigure)/100;
- return mon;
- }
- // Main function to try some example on above class
- int main()
- {
- Money m1(100.0);
- Money m2(150.0);
- if(m1<m2) cout<<"less"<<endl;
- if(m1<=m2) cout<<"less or equal"<<endl;
- m1.amount = 213.0;
- if(m1>m2) cout<<"greater"<<endl;
- if(m1>=m2) cout<<"greater or equal"<<endl;
- Money temp;
- temp = m1.percent(11);
- cout<<temp.amount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement