Maruf_Hasan

Calculator

May 19th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Calculator
  5. {
  6. public:
  7. void addition(double a,double b)
  8. {
  9. cout<<"The result of addition "<<a+b<<endl;
  10. }
  11. void subtraction(double a,double b)
  12. {
  13. cout<<"The result of subtraction "<<a-b<<endl;
  14. }
  15. void multiplication(double a,double b)
  16. {
  17. cout<<"The result of multiplication "<<a*b<<endl;
  18. }
  19. void division(double a,double b)
  20. {
  21. if(b==0)
  22. {
  23. cout<<"Undefined"<<endl;
  24. }
  25. else
  26. {
  27. cout<<"The result of division "<<a/b<<endl;
  28. }
  29. }
  30.  
  31. };
  32.  
  33.  
  34. int main()
  35. {
  36.  
  37. while(true)
  38. {
  39. Calculator calc;
  40. char c;
  41. cout<<"Enter your choice"<<endl;
  42. cout<<"+ for addition"<<endl;
  43. cout<<"- for subtraction"<<endl;
  44. cout<<"* for multiplication"<<endl;
  45. cout<<"/ for division"<<endl;
  46. cout<<"e/E for Exit"<<endl;
  47. cin>>c;
  48. if(c=='+')
  49. {
  50. cout<<"Enter two numbers"<<endl;
  51. double a,b;
  52. cin>>a>>b;
  53. calc.addition(a,b);
  54. }
  55. else if(c=='-')
  56. {
  57. cout<<"Enter two numbers"<<endl;
  58. double a,b;
  59. cin>>a>>b;
  60. calc.subtraction(a,b);
  61. }
  62. else if(c=='*')
  63. {
  64. cout<<"Enter two numbers"<<endl;
  65. double a,b;
  66. cin>>a>>b;
  67. calc.multiplication(a,b);
  68. }
  69. else if(c=='/')
  70. {
  71. cout<<"Enter two numbers"<<endl;
  72. double a,b;
  73. cin>>a>>b;
  74. calc.division(a,b);
  75. }
  76. else if(c=='e' || c=='E')
  77. {
  78. break;
  79. }
  80. else
  81. {
  82. cout<<"Invalid choice"<<endl;
  83. cout<<"Enter again"<<endl;
  84. }
  85. }
  86. return 0;
  87. }
Add Comment
Please, Sign In to add comment