Skip to content

Commit aef574b

Browse files
authored
Add files via upload
1 parent 0191cd0 commit aef574b

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int arithmetic(int num1, int num2, char op);
5+
double sothuc(char op, double num);
6+
int main(int argc, char* argv[])
7+
{
8+
if (argc == 4)
9+
{
10+
int num1, num2; char op;
11+
num1 = atoi(argv[1]);
12+
op = argv[2][0];
13+
num2 = atoi(argv[3]);
14+
cout << arithmetic(num1, num2, op) << endl;
15+
return 0;
16+
}
17+
else if (argc == 3)
18+
{
19+
double num;
20+
char op;
21+
num = atoi(argv[2]);
22+
op = argv[1][0];
23+
cout << sothuc(op, num) << endl;
24+
return 0;
25+
}
26+
else {
27+
cout << "Invalid" << endl;
28+
return 0;
29+
}
30+
}
31+
32+
int arithmetic(int num1, int num2, char op)
33+
{
34+
switch (op)
35+
{
36+
case '+':
37+
return num1 + num2;
38+
case '-':
39+
return num1 - num2;
40+
case 'x':
41+
return num1 * num2;
42+
case '/':
43+
if (num2 == 0)
44+
{
45+
cout << "Invalid divisor" << endl;
46+
exit(1);
47+
}
48+
else
49+
return num1 / num2;
50+
case '%':
51+
if (num2 == 0)
52+
{
53+
cout << "Invalid divisor" << endl;
54+
exit(1);
55+
}
56+
else
57+
return num1 % num2;
58+
default:
59+
cout << "Invalid operator" << endl;
60+
exit(1);
61+
}
62+
}
63+
double sothuc(char op, double num)
64+
{
65+
switch (op)
66+
{
67+
case 'c':
68+
return cos(num);
69+
case 's':
70+
if (num < 0)
71+
{
72+
cout << "Invalid number" << endl;
73+
exit(1);
74+
}
75+
else
76+
return sqrt(num);
77+
default:
78+
cout << "Invalid operator" << endl;
79+
exit(1);
80+
}
81+
}

0 commit comments

Comments
 (0)