-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW3.cpp
194 lines (165 loc) · 2.83 KB
/
HW3.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
#include<iostream>
#include<cmath>
using namespace std;
void Basic();
void Advanced();
void SuperAdvanced();
void Sum();
void Sub();
void Multi();
void Division();
void All_In_One();
void Sin();
void Cos();
void Pow();
void Sqrt();
int main()
{
cout << "Welcome to Magic Calculator!" << endl;
cout << "1)Basic Calculation" << endl << "2)Advanced Calculation" << endl << "3)Super Advanced Calculation" << endl;
cout << "Choose your option please:";
int n;
cin >> n;
if (n == 1)
{
Basic();
}
if (n == 2)
{
Advanced();
}
if (n == 3)
{
SuperAdvanced();
}
return 0;
}
void Basic()
{
cout << " 1)Summation \n 2)Subtract \n 3)Multiply \n 4)Division \n 5)All in One \n";
int m;
cin >> m;
if (m == 1)
Sum();
else if (m == 2)
Sub();
else if (m == 3)
Multi();
else if (m == 4)
Division();
else if (m == 5)
All_In_One();
else
cout << "Error! \n";
}
void Sum()
{
float x, y;
cout << "Enter two Numbers: \n";
cin >> x >> y;
cout << "x + y = " << x + y << endl;
}
void Sub()
{
float x, y;
cout << "Enter two Numbers: \n";
cin >> x >> y;
cout << "x - y = " << x - y << endl;
}
void Multi()
{
float x, y;
cout << "Enter two Numbers: \n";
cin >> x >> y;
cout << "x * y = " << x*y << endl;
}
void Division()
{
float x, y;
cout << "Enter two Numbers: \n";
cin >> x >> y;
cout << "x / y = " << x / y << endl;
}
void All_In_One()
{
float x, y;
cout << "Enter two Numbers: \n";
cin >> x >> y;
cout << "x + y = " << x + y << endl;
cout << "x - y = " << x - y << endl;
cout << "x * y = " << x*y << endl;
cout << "x / y = " << x / y << endl;
}
void Advanced()
{
cout << " 1)Sin(x) \n 2)Cos(x) \n 3)x^y \n 4)Sqrt(x) \n";
int k;
cin >> k;
if (k == 1)
Sin();
else if (k == 2)
Cos();
else if (k == 3)
Pow();
else if (k == 4)
Sqrt();
else
cout << "Error! \n";
}
void Sin()
{
float x;
cout << "Enter the angle:";
cin >> x;
cout << "sin(x)=" << sin(x) << endl;
}
void Cos()
{
float x;
cout << "Enter the angle:";
cin >> x;
cout << "cos(x)=" << cos(x) << endl;
}
void Pow()
{
float x , y;
cout << "Enter the Base:";
cin >> x;
cout << "Enter the Power:";
cin >> y;
cout << "x ^ y =" << pow(x, y) << endl;
}
void Sqrt()
{
float x;
cout << "Enter a Number:";
cin >> x;
cout << "Sqrt(x)=" << sqrt(x) << endl;
if (x < 0)
{
cout << "Error! Enter a positive Number. \n";
}
}
void SuperAdvanced()
{
cout << "Enter whatever you want and press '=' !!! \n";
int x, Result = 0;
char ch;
cin >> x;
cin >> ch;
Result = x;
while (ch != '=')
{
cin >> x;
if (ch == '+')
{
Result += x;
}
else if (ch == '-')
{
Result -= x;
}
cin >> ch;
}
cout << endl << "Result= " << Result << endl;
}