Você está na página 1de 2

CODE:

1. #include <iostream>
2. using namespace std;
3.
4. class Calculator {
5. public:
6. void add(int i, int a);
7. void subtract(int i, int a);
8. void mult(int i , int a);
9. void divide(int i, int a);
10. void modulo(int i , int a);
11. void menu();
12. void driver();
13. void driver2();
14. int a,x,y,result;
15. char choice;
16. };
17.
18. void Calculator::add(int i, int a) {
19. result = i + a;
20. cout << "Result:" << result << endl;
21. }
22.
23. void Calculator::subtract(int i, int a) {
24. result = i - a;
25. cout << "Result:" << result << endl;
26. }
27.
28. void Calculator::mult(int i, int a) {
29. result = i * a;
30. cout << "Result:" << result << endl;
31. }
32.
33. void Calculator::divide(int i, int a) {
34. result = i / a;
35. cout << "Result:" << result << endl;
36. }
37.
38. void Calculator::modulo(int i, int a) {
39. result = i % a;
40. cout << "Result:" << result << endl;
41. }
42.
43.
44. void Calculator::menu() {
45. cout<<"===============================================================\n";
46. cout<<" MENU \n";
47. cout<<"===============================================================\n";
48. cout<<" 1. Add\n";
49. cout<<" 2. Subtract\n";
50. cout<<" 3. Multiply\n";
51. cout<<" 4. Divide\n";
52. cout<<" 5. Modulo\n";
53.
cout<<"===============================================================\n\n";
54.
cout<<"===============================================================\n\n\n";
55. }
56.
57. void Calculator::driver() {
58. cout << "Enter your choice" << endl;
59. cin >> a;
60. cout << "Enter first number" << endl;
61. cin >> x;
62. cout << "Enter second number" << endl;
63. cin >> y;
64. switch(a){
65. case 1: add(x,y); break;
66. case 2: subtract(x,y); break;
67. case 3: mult(x,y); break;
68. case 4: divide(x,y); break;
69. case 5: modulo(x,y); break;
70. default: cout << "Invalid input. Try Again!" << endl;
71. }
72.
73. }
74.
75. void Calculator::driver2() {
76. do {
77. driver();
78.
79. cout << "Do you want to continue? Y/N" << endl;
80. cin >> choice;
81. }
82. while(choice == 'Y' || choice == 'y');
83. }
84.
85.
86. int main () {
87. Calculator imba;
88. imba.menu();
89. imba.driver2();
90. return 0;
91. }

Você também pode gostar