forked from Open-Source-Community/iusegit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
135 lines (125 loc) · 2.39 KB
/
main.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
#include <iostream>
#include <sstream>
#include <string>
#include "operations.h"
#include <math.h>
#define PI 3.14159265
using namespace std;
float str_to_float(string str)
{
istringstream iss(str);
float value;
if (iss >> value)
return value;
else
return NULL;
}
int main(int argc, char* argv[])
{
if (argc <= 2)
{
cerr << "too few arguments" << endl;
return 1;
}
else if (argc == 3)
{
string operation = argv[1];
float num1 = str_to_float(argv[2]);
if (num1 == NULL)
{
cerr << "invalid input" << endl;
return 1;
}
if (operation == "absolute")
{
cout << absolute(num1) << endl;
}
else if (operation == "negate")
{
cout << negate(num1) << endl;
}
else if (operation == "root")
{
// cout << root(num1) << endl;
}
else if (operation == "log")
{
cout << _log(num1) << endl;
}
else if (operation == "ln")
{
cout << ln(num1) << endl;
}
else if (operation == "factorial")
{
cout << factorial(num1) << endl;
}
else if (operation == "sin")
{
cout << _sin(num1) << endl;
}
else if (operation == "cos")
{
cout << cos ( num1 * PI / 180.0 ) ;
}
else if (operation == "tan")
{
cout << _tan (num1);
}
else
{
cerr << "invalid input" << endl;
return 1;
}
}
else if (argc == 4)
{
string operation = argv[1];
float num1 = str_to_float(argv[2]);
float num2 = str_to_float(argv[3]);
if (num1 == NULL || num2 == NULL)
{
cerr << "invalid input" << endl;
return 1;
}
if (operation == "add")
{
// cout << add(num1, num2) << endl;
}
else if (operation == "subtract")
{
cout << subtract(num1, num2) << endl;
}
else if (operation == "multiply")
{
// cout << multiply(num1, num2) << endl;
}
else if (operation == "divide")
{
cout << divide(num1, num2) << endl;
}
else if (operation == "power")
{
cout << powerfunction(num1, num2) << endl;
}
else if (operation == "root")
{
// cout << root(num1, num2) << endl;
}
else if (operation == "log")
{
cout << _log(num1, num2) << endl;
}
else
{
cerr << "invalid input" << endl;
return 1;
}
}
else
{
cerr << "too many arguments" << endl;
return 1;
}
return 0;
}