Advertisement
Adrita

task 1( oop lab 2) 3rd sem

Jan 22nd, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Calculator
  4. {
  5. private:
  6. int a;
  7. public:
  8. Calculator():a(0)
  9. {
  10.  
  11. }
  12. Calculator(int value):a(value)
  13. {
  14.  
  15. }
  16. int getValue()
  17. {
  18. return a;
  19. }
  20. void setValue(int value)
  21. {
  22. a=value;
  23. }
  24. void add(int value)
  25. {
  26. a=a+value;
  27. }
  28. void subtract(int value)
  29. {
  30. a=a-value;
  31. }
  32. void multiply(int value)
  33. {
  34. a=a*value;
  35. }
  36. void divideBy(int value)
  37. {
  38. a=a/value;
  39. }
  40. void clear()
  41. {
  42. a=0;
  43. }
  44.  
  45. };
  46. int main()
  47. {
  48. Calculator c1;
  49. Calculator c2(10);
  50.  
  51. cout<<"My first value is "<<c1.getValue()<<endl;
  52. cout<<"My second value is "<<c2.getValue()<<endl;
  53. c1.setValue(20);
  54. cout<<"My modified first value is "<<c1.getValue()<<endl;
  55. c1.add(10);
  56. cout<<"10 added to first value "<<c1.getValue()<<endl;
  57. c1.subtract(5);
  58. cout<<"5 subtracted from first value "<<c1.getValue()<<endl;
  59. c1.multiply(5);
  60. cout<<"5 multiplied to first value "<<c1.getValue()<<endl;
  61. c1.divideBy(5);
  62. cout<<"First value is divided by 5 "<<c1.getValue()<<endl;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement