-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatingCode.cpp
More file actions
274 lines (253 loc) · 7.17 KB
/
Copy pathcalculatingCode.cpp
File metadata and controls
274 lines (253 loc) · 7.17 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include <iostream>
#include <cmath>
#include <stdlib.h>
// #include <conio.h>
using namespace std;
// class 1
class StandardCalc
{
public:
static double add(double, double);
static double sub(double, double);
static double div(double, double);
static double mul(double, double);
// static double mod(double, double);
};
double StandardCalc::add(double a, double b)
{
return (a + b);
}
double StandardCalc::sub(double a, double b)
{
return (a - b);
}
double StandardCalc::div(double a, double b)
{
return (a / b);
}
double StandardCalc::mul(double a, double b)
{
return (a * b);
}
// double StandardCalc::mod(double a, double b)
// {
// double mo = a % b;
// return mo;
// }
// class 2
class ScientificCalc
{
public:
static double sqt(double);
static double sq(double);
static double cub(double);
// static double powr(double, double);
// static double fact(double, double);
};
double ScientificCalc::sqt(double a)
{
double root1 = sqrt(a);
// sqrt is a keyword
return root1;
}
double ScientificCalc::sq(double a)
{
double num1 = a * a;
return num1;
// return (a*a);
}
double ScientificCalc::cub(double a)
{
double num2 = a * a * a;
return num2;
}
// double ScientificCalc::powr(double a, double b)
// {
// return (a + b);
// }
// int type;
// void askType(){
// int type;
// cout<<"\n\n\t\t\t ~ ~ ~ ~ TYPES OF CALCULATORS ~ ~ ~ ~ \t\t\t\n\n";
// cout<<"1.Standard Calculator\n2.Scientific Calculator\n\nEnter your Choice : ";
// cin>>type;
// // clrscr();
// }
int main()
{
// void clrscr(void);
// void askType(int type);
StandardCalc obj1;
ScientificCalc obj2;
cout << "\n\n\t\t\t ~ ~ ~ ~ TYPES OF CALCULATORS ~ ~ ~ ~ \t\t\t\n\n";
cout << "1.Standard Calculator\n2.Scientific Calculator\n\nEnter your Choice : ";
int type;
cin >> type;
// clrscr();
cout << "\n\n";
if (type == 1)
{
int t;
do
{
cout << "\n\n\t\t ~ ~ ~ Operations for Standard Calculator ~ ~ ~ \t\t\n\n";
cout << "1.Addition\n2.Subraction\n3.Multiplication\n4.Division\n5.Modulus\n6.Go Back\n\nEnter your Choice : ";
cin >> t;
// void clrscr();
cout << "\n\n";
switch (t)
{
case 1:
{
double n1, n2;
cout << "Enter the number 1 : ";
cin >> n1;
cout << "Enter the number 2 : ";
cin >> n2;
double ans1;
ans1 = obj1.add(n1, n2);
cout << "Addition is " << ans1 << endl;
break;
}
case 2:
{
double n1, n2;
cout << "Enter the number 1 : ";
cin >> n1;
cout << "Enter the number 2 : ";
cin >> n2;
double ans2;
ans2 = obj1.sub(n1, n2);
cout << "Subtraction is " << ans2;
break;
}
case 3:
{
double n1, n2;
cout << "Enter the number 1 : ";
cin >> n1;
cout << "Enter the number 2 : ";
cin >> n2;
double ans2;
ans2 = obj1.mul(n1, n2);
cout << "Multiplication is " << ans2;
break;
}
case 4:
{
double n1, n2;
cout << "Enter the number 1 : ";
cin >> n1;
cout << "Enter the number 2 : ";
cin >> n2;
double ans2;
ans2 = obj1.div(n1, n2);
cout << "Division is " << ans2;
break;
}
case 5:
{
int n1, n2;
cout << "Enter the number 1 : ";
cin >> n1;
cout << "Enter the number 2 : ";
cin >> n2;
// double ans2;
// ans2 = obj1.mod(n1, n2);
// cout << "Modulus is " << ans2;
int modul;
modul = n1 % n2;
cout << "The modulus of " << n1 << " and " << n2 << " is " << modul << endl;
break;
}
case 6:
cout << "\nThankyou!\n\n";
break;
default:
cout << "\nPlease Enter a valid choice no.! ( between 1 to 6 only) ";
break;
}
} while (t != 6);
}
else if (type == 2)
{
int n;
do
{
cout << "\n\n\t\t ~ ~ ~ Operations for Scientific Calculator~ ~ ~ \t\t\n\n";
cout << "1.Sqaure Root\n2.Square\n3.Cube\n4.Power\n5.Factorial\n6.Sine function\n7.Cos Function\n8.Tan Function\n9.Go Back\n\nEnter yourChoice : ";
cin >> n;
// void clrscr();
cout << "\n\n";
switch (n)
{
case 1:
{
double n1;
cout << "Enter the number : ";
cin >> n1;
double ans1;
ans1 = obj2.sqt(n1);
cout << "The square root of " << n1 << " is " << ans1 << endl;
break;
}
case 2:
{
double n1;
cout << "Enter the number : ";
cin >> n1;
double ans1;
ans1 = obj2.sq(n1);
cout << "The square of " << n1 << " is " << ans1 << endl;
break;
}
case 3:
{
double n1;
cout << "Enter the number : ";
cin >> n1;
double ans1;
ans1 = obj2.cub(n1);
cout << "The cube of " << n1 << " is " << ans1 << endl;
}
break;
case 4:
double base, exponent, result;
cout << "Enter the base: ";
cin >> base;
cout << "Enter the exponent: ";
cin >> exponent;
result = pow(base, exponent);
// using the pow() function from cmath library
cout << base << " raised to the power of " << exponent << " is " << result << endl;
break;
case 5:
{
int num;
int factorial = 1;
cout << "Enter a positive integer: ";
cin >> num;
for (int i = 1; i <= num; i++)
{
factorial = factorial * i; // multiplying the previous factorial by i
}
cout << "The factorial of " << num << " is " << factorial << endl;
}
break;
case 9:
cout << "\nThankyou!\n\n";
break;
default:
cout << "\nPlease Enter a valid choice no.! ( between 1 to 9 only) ";
break;
}
}
while (n != 9);
}
else
{
cout << "\nPlease Enter 1 or 2 only ! ";
cin >> type;
}
return 0;
}