-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut42.cpp
293 lines (259 loc) · 7.89 KB
/
tut42.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include <iostream>
#include <cmath>
using namespace std;
/*
Create 2 classes:
1. SimpleCalculator - Takes input of 2 numbers using a utility function and perfoms +, -, *, / and displays the results using another function.
2. ScientificCalculator - Takes input of 2 numbers using a utility function and perfoms any four scientific operations of your chioice and displays the results using another function.
Create another class HybridCalculator and inherit it using these 2 classes:
Q1. What type of Inheritance are you using? ---> Multiple inheritance
Q2. Which mode of Inheritance are you using? ---> public SimpleCalculator, public ScientificCalculator
Q3. Create an object of HybridCalculator and display results of simple and scientific calculator.
Q4. How is code reusability implemented?
*/
void name()
{
cout << 'Author: Varun Gupta' << endl;
}
class Simple
{
protected:
int val1, val2;
int a,in;
public:
void Enter();
void Cal1()
{
int sum, mul, sub, mod;
float div;
do
{
cout << "Press the code according to the operation you want to execute " << endl;
cout << "1. Addition " << endl
<< "2. Multiplication " << endl
<< "3. Subtraction " << endl
<< "4. Division " << endl
<< "5. Modulus " << endl;
cin >> a;
switch (a)
{
case 1:
{
sum = val1 + val2;
cout << "The Sum of the values is :\n"
<< sum << endl;
// cin>>sum;
break;
}
case 2:
{
mul = val1 * val2;
cout << "The product of the values is:\n"
<< mul << endl;
break;
}
case 3:
{
cout << "The difference of the values is " << endl;
if (val1 > val2)
{
sub = val1 - val2;
cout << sub;
}
else
{
sub = val2 - val1;
cout << sub << endl;
}
break;
}
case 4:
{
div = val1 / val2;
cout << "The result after division of the two values is :\n"
<< div << endl;
}
case 5:
{
mod = val1 % val2;
cout << "The modulus of the entered values is :" << mod << endl;
break;
}
}
cout << "Press 1 for reexecution or 0 for exit :" << endl;
cin >> in;
}
while (in== 1)
;
{
switch (a)
;
}
}
};
void Simple ::Enter()
{
do{
cout << "Welcome to Simple Calculator !!!!!!!" << endl;
cout << "Enter the values ,you want to perform operation on " << endl;
cin >> val1 >> val2;
}
while(in==1);
{
switch(a);
}
}
class Scintific
{
protected:
int sqr, cbr;
int s, c, t, cosec1, sec1, cot1;
float s_r, c_r;
public:
int i;
int e;
int en;
void Entry_Data()
{
do
{
cout << "!!!!!!!Welcome to Scintific Calculator !!!!!!!" << endl;
// goto comeback;
cout << "Choose from the following the options the kind of operation you want to execute :" << endl;
cout << "1. Square" << endl
<< "2. Square Root " << endl
<< "3. Cube " << endl
<< "4. Cube Root " << endl
<< "5. Sin()" << endl
<< "6. Cos() " << endl
<< "7. Tan()" << endl
<< "8. Cosec()" << endl
<< "9. Sec()" << endl
<< "10. Cot()" << endl;
cin >> i;
switch (i)
{
case 1:
cout << "Enter the value you want to square" << endl;
cin >> sqr;
cout << "The square of the entered value is :\n"
<< pow(sqr, 2) << endl;
break;
case 2:
cout << "Enter the value you want to square root" << endl;
cin >> s_r;
cout << "The square root of the entered value is :\n"
<< sqrt(s_r) << endl;
break;
case 3:
cout << "Enter the value you want to cube" << endl;
cin >> cbr;
cout << "The cube of the entered value is :\n"
<< pow(cbr, 3) << endl;
break;
case 4:
cout << "Enter the value you want to cuberoot" << endl;
cin >> c_r;
cout << "The cube root of the entered value is :\n"
<< cbrt(c_r) << endl;
break;
case 5:
cout << "Enter the value you want to sin()" << endl;
cin >> s;
cout << "The sin the entered value is :\n"
<< sin(s) << endl;
break;
case 6:
cout << "Enter the value you want to cos()" << endl;
cin >> c;
cout << "The cos of the entered value is :\n"
<< cos(c) << endl;
break;
case 7:
cout << "Enter the value you want to tan()" << endl;
cin >> t;
cout << "The tan of the entered value is :\n"
<< tan(t) << endl;
break;
case 8:
cout << "Enter the value you want to cosec" << endl;
cin >> cosec1;
cout << "The cosec of the entered value is :\n"
<< asin(cosec1) << endl;
break;
case 9:
cout << "Enter the value you want to sec()" << endl;
cin >> sec1;
cout << "The sec of the entered value is :\n"
<< acos(sec1) << endl;
break;
case 10:
cout << "Enter the value you want to cot()" << endl;
cin >> cot1;
cout << "The cot of the entered value is :\n"
<< atan(cot1) << endl;
break;
}
cout << "Press 1 for reexeuction and 0 for exit :" << endl;
cin >> en;
} while (en == 1);
{
switch (i)
;
}
// comeback:
// cout<<"The reexection has been taken place: "<<endl;
}
};
class Hybrid : public Simple, public Scintific
{
protected:
int a;
public:
void show()
{
cout << "Press 1. for Simple calculator or 2.Scintific calculator " << endl;
cin >> a;
if (a == 1)
{
// void Enter();
// void Cal1();
Simple ::Enter(); //Solving ambiguity using scope resolution operator.
Simple ::Cal1(); ///Solving ambiguity rusing scope resolution operator.
}
else
{
Scintific::Entry_Data();
}
}
};
int main()
{
name();
int i1, e;
// Simple s1;
// s1.Enter();
// s1.Cal1();
// Scintific s1;
// s1.Entry_Data();
Hybrid h;
// cout<<"Press 1. Simple calculator or 2. Scintific Calculator :"<<endl;
// cin>>i1;
// if(i1==1)
// {
// h.Enter();
// h.Cal1();
// }
// else if (i1==2)
// {
// h.Entry_Data();
// }
h.show();
// cout<<"Press 1 for reexecution and 0 for exit "<<endl;
// cin>>e;
// if(e==1)
// {
// cout<<"The reexecution has taken place :"<<h.Entry_Data();
// }
return 0;
}