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