Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Calculator
- {
- private:
- int a;
- public:
- Calculator():a(0)
- {
- }
- Calculator(int value):a(value)
- {
- }
- int getValue()
- {
- return a;
- }
- void setValue(int value)
- {
- a=value;
- }
- void add(int value)
- {
- a=a+value;
- }
- void subtract(int value)
- {
- a=a-value;
- }
- void multiply(int value)
- {
- a=a*value;
- }
- void divideBy(int value)
- {
- a=a/value;
- }
- void clear()
- {
- a=0;
- }
- };
- int main()
- {
- Calculator c1;
- Calculator c2(10);
- cout<<"My first value is "<<c1.getValue()<<endl;
- cout<<"My second value is "<<c2.getValue()<<endl;
- c1.setValue(20);
- cout<<"My modified first value is "<<c1.getValue()<<endl;
- c1.add(10);
- cout<<"10 added to first value "<<c1.getValue()<<endl;
- c1.subtract(5);
- cout<<"5 subtracted from first value "<<c1.getValue()<<endl;
- c1.multiply(5);
- cout<<"5 multiplied to first value "<<c1.getValue()<<endl;
- c1.divideBy(5);
- cout<<"First value is divided by 5 "<<c1.getValue()<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement