-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path41exerciseclass.cpp
More file actions
169 lines (164 loc) · 3.49 KB
/
Copy path41exerciseclass.cpp
File metadata and controls
169 lines (164 loc) · 3.49 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
#include <iostream>
#include <math.h>
using namespace std;
class SimpleCalculator
{
protected:
float value1, value2;
public:
void setData_simple(float a, float b)
{
value1 = a;
value2 = b;
}
float sum()
{
return value1 + value2;
}
float difference()
{
return value1 - value2;
}
float product()
{
return value1 * value2;
}
float division()
{
return value1 / value2;
}
};
class ScientificCalculator
{
protected:
float value3, value4;
public:
void setData_scientific(float a, float b)
{
value3 = a;
value4 = b;
}
float sinfx()
{
return sin(value3);
}
float sinfy()
{
return sin(value4);
}
float cosfx()
{
return cos(value3);
}
float cosfy()
{
return cos(value4);
}
float powAB()
{
return pow(value3, value4);
}
float powBA()
{
return pow(value4, value3);
}
};
class HybridCalculator : public SimpleCalculator, public ScientificCalculator
{
public:
void simpleAdd()
{
cout << "Sum of given values = " << sum() << endl;
}
void simpleSub()
{
cout << "Difference of given values = " << difference() << endl;
}
void simpleProduct()
{
cout << "Product of given values = " << product() << endl;
}
void simpleDiv()
{
cout << "Division of given values = " << division() << endl;
}
void scientificSin()
{
cout << "Sine function of the first and second given value is = " << sinfx() << " , " << sinfy() << endl;
}
void scientificCos()
{
cout << "Cosine function of the first and second given value is = " << cosfx() << " , " << cosfy() << endl;
}
void scientificPow1()
{
cout << " Power of the first given value to the second is = " << powAB() << endl;
}
void scientificPow2()
{
cout << "Power of the second given value to the first is = " << powBA() << endl;
}
};
int main()
{
float num1, num2;
int n, m;
cout << "Enter 2 numbers : " << endl;
cin >> num1 >> num2;
HybridCalculator calc;
cout << "Choose between simple(1) or scientific(0) calculation : " << endl;
cin >> n;
if (n == 1)
{
calc.setData_simple(num1, num2);
cout << "Choose operation : Add(1), Subtract(2), Multiply(3), Division(4)" << endl;
cin >> m;
switch (m)
{
case 1:
calc.simpleAdd();
break;
case 2:
calc.simpleSub();
break;
case 3:
calc.simpleProduct();
break;
case 4:
calc.simpleDiv();
break;
default:
cout << "Invalid input...Quiting" << endl;
break;
}
}
else if (n == 0)
{
calc.setData_scientific(num1, num2);
cout << "Choose scientific operation Sin(1), Cos(2), PowerA^B(3), PowerB^A(4)" << endl;
cin >> m;
switch (m)
{
case 1:
calc.scientificSin();
break;
case 2:
calc.scientificCos();
break;
case 3:
calc.scientificPow1();
break;
case 4:
calc.scientificPow2();
break;
default:
cout << "Invalid input...Quiting" << endl;
break;
}
}
else
{
cout << "Invalid input...Quiting" << endl;
}
return 0;
}