Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class A
  4. {
  5. int a,b;
  6. public:
  7. A(int x,int y)
  8. {
  9. a=x;
  10. b=y;
  11. }
  12. A()
  13. {
  14.  
  15. }
  16. A operator -(A o4)
  17. {
  18. A o5;
  19. o5.a = a-o4.a;
  20. o5.b = b-o4.b;
  21. return o5;
  22. }
  23.  
  24. A operator +(A o4)
  25. {
  26. A o5;
  27. o5.a = a+o4.a;
  28. o5.b = b+o4.b;
  29. return o5;
  30. }
  31.  
  32. A operator *(A o4)
  33. {
  34. A o5;
  35. o5.a = a*o4.a;
  36. o5.b = b*o4.b;
  37. return o5;
  38. }
  39.  
  40. A operator /(A o4)
  41. {
  42. A o5;
  43. o5.a = a/o4.a;
  44. o5.b = b/o4.b;
  45. return o5;
  46. }
  47. void display()
  48. {
  49. cout<< "a = "<<a<<" b = "<<b;
  50. }
  51.  
  52. };
  53. int main()
  54. {
  55. A o1(10,30),o2(5,3),o3;
  56.  
  57. int ch;
  58. while(1)
  59. {
  60. cout<< "\n1. Add\n2. Substraction\n3. Multiplication\n4. Division\n5. Exit\n";
  61. cin>>ch;
  62. switch(ch)
  63. {
  64. case 1:
  65. o3=o1+o2;
  66. o3.display();
  67. break;
  68. case 2:
  69. o3=o1-o2;
  70. o3.display();
  71. break;
  72. case 3:
  73. o3=o1*o2;
  74. o3.display();
  75. break;
  76. case 4:
  77. o3=o1/o2;
  78. o3.display();
  79. break;
  80. case 5:
  81. exit(0);
  82. default:
  83. break;
  84.  
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment