-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathmain.cpp
48 lines (41 loc) · 1.05 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
#include <iostream>
#include <string>
#include <cmath>
#include "calculus.h"
using std::string;
using std::cout;
using std::endl;
using std::stod;
const string PREFIX = "lib_";
double callFunction(string func, double x);
int main(int argc, char* argv[])
{
if (argc != 3) {
cout << "Invalid arguments" << endl;
return 1;
}
string func = argv[1];
double x = stod(argv[2]);
cout << "Computed by this program: " << callFunction(func, x) << endl;
cout << "Computed by C/C++ library: " << callFunction(PREFIX + func, x) << endl;
return 0;
}
double callFunction(string func, double x)
{
if (func == "cos") {
return myCos(x);
} else if (func == "sin") {
return mySin(x);
} else if (func == "sqrt") {
return mySqrt(x);
} else if (func == PREFIX + "cos") {
return cos(x);
} else if (func == PREFIX + "sin") {
return sin(x);
} else if (func == PREFIX + "sqrt") {
return sqrt(x);
} else {
cout << "Invalid function" << endl;
exit(1);
}
}