-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathScientific_calc.cpp
279 lines (245 loc) · 5.78 KB
/
Scientific_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
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
275
276
277
278
279
#include <bits/stdc++.h>
#include <dos.h>
#include <iostream>
using namespace std;
class Simple_Cacl
{
protected:
int i, j;
public:
int sum = 0, mul = 1, div = 1, sub = 0;
void setdataS(int a, int b)
{
i = a;
j = b;
}
void Addition()
{
sum = i + j;
cout << i << " + " << j << " = " << sum;
}
void Subtraction()
{
sub = i - j;
cout << i << " - " << j << " = " << sub;
}
void division()
{
div = i / j;
cout << i << " / " << j << " = " << div;
}
void multiplication()
{
mul = i * j;
cout << i << " * " << j << " = " << mul;
}
};
class scientific_calc
{
protected:
int i, j;
public:
void setdataSC(int a, int b)
{
i = a;
j = b;
}
float logs = 0, e = 0, sq = 0;
int logrithm()
{
logs = log(i);
cout << "log(" << i << ") = " << logs;
return 0;
}
void exponential()
{
e = exp(i);
cout << "exp(" << i << ") = " << e;
}
void squareRoot()
{
sq = sqrt(i);
cout << "The squareRoot of a number is = " << sq;
}
};
class Hybrid_Calc : public Simple_Cacl, public scientific_calc
{
public:
void display_Simple_Calc();
void display_Scientific_Calc();
void Matrix();
};
void Hybrid_Calc::Matrix()
{
int n, m, h, k, i, j;
cout << "Enter the Rows and Coloumn of 1st Matrix :-\n";
cin >> n >> m;
cout << "Enter the Rows and Coloumn of 2nd Matrix :- \n";
cin >> h >> k;
int a[100][100];
int b[100][100];
int sum[100][100];
int mul[100][100];
cout << "Enter the 1st matrix :-\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
cin >> a[i][j];
}
cout << "Enter the 2nd matrix :-\n";
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
cin >> b[i][j];
}
cout << "If you want to Add Two matrix press (+)\n";
cout << "If you want to Subtract Two matrix press (-)\n";
cout << "If you want to Multiply Two matrix press (*)\n";
cout << "If you want Transpose Matrix press (T)\n";
char c;
cin >> c;
if (c == '+')
{
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
sum[i][j] = a[i][j] + b[i][j];
}
cout << "The Resultant matrix is :\n\n";
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
cout << sum[i][j] << " ";
cout << "\n";
}
}
else if (c == '-')
{
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
sum[i][j] = a[i][j] - b[i][j];
}
cout << "The Resultant matrix is :\n\n";
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
cout << sum[i][j] << " ";
cout << "\n";
}
}
else if (c == '*')
{
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
{
mul[i][j] = 0;
for (int v = 0; v < k; v++)
mul[i][j] += a[i][j] * b[i][j];
}
}
cout << "The Resultant matrix is :\n\n";
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
cout << mul[i][j] << " ";
cout << "\n";
}
}
else if (c == 'T')
{
char cx;
cout << "For matrix 1 press (A) and for 2 press (B) \n";
cin >> cx;
if (cx == 'A' or cx == 'a')
{
for (int i = 0; i < h; ++i)
for (int j = 0; j < k; ++j)
sum[j][i] = a[i][j];
}
if (cx == 'B' or 'b')
{
for (int i = 0; i < h; ++i)
for (int j = 0; j < k; ++j)
sum[j][i] = b[i][j];
}
cout << "The Resultant matrix is :\n\n";
for (i = 0; i < h; i++)
{
for (j = 0; j < k; j++)
cout << sum[i][j] << " ";
cout << "\n";
}
}
else
cout << "Wrong value entered";
}
void Hybrid_Calc ::display_Scientific_Calc()
{
char choice;
cout << "1.For Logrithmic value Press(1)\n";
cout << "2.For Exponetial value Press(2)\n";
cout << "3.For Square Root Press(3)\n";
cin >> choice;
if (choice == '1')
logrithm();
else if (choice == '2')
exponential();
else if (choice == '3')
squareRoot();
}
void Hybrid_Calc ::display_Simple_Calc()
{
char choice;
cout << "What you want to do \n\n";
cout << "1.For Addition Press (+)\n";
cout << "2.For Subtraction Press(-)\n";
cout << "3.For Multiplication Press(*)\n";
cout << "4.For Division Press(/)\n";
cin >> choice;
if (choice == '+')
Addition();
else if (choice == '-')
Subtraction();
else if (choice == '*')
multiplication();
else if (choice == '/')
division();
else
cout << "Wrong value entered";
}
int main()
{
Hybrid_Calc h;
int a, b, c;
cout << "-------- SCIENTIFIC CALCULATOR --------\n\n";
cout << "If you want to perform (+,-,/,*)\n";
cout << "Then press ( 1 )\n\n";
cout << "If you want to perform log,exp,sqrt\n";
cout << "Then press(2)\n\n";
cout << "If you Want to do operations in matrix \n";
cout << "Then press(3)\n\n";
cin >> c;
if (c == 1)
{
cout << "Enter two numbers\n";
cin >> a >> b;
h.setdataS(a, b);
h.display_Simple_Calc();
}
else if (c == 2)
{
cout << "Enter one numbers\n";
cin >> a;
h.setdataSC(a, b = 0);
h.display_Scientific_Calc();
}
else if (c == 3)
h.Matrix();
else
{
cout << "Wrong value entered";
}
return 0;
}