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
|
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
float x = 0.0f;
float y = 0.0f;
string operation_name = "";
float z = y / x;
float operation = 0.0f;
float atanf2(float y, float x)
{
float r;
r = atanf2(y, x);
return r;
}
int main()
{
bool quit = true;
while( quit )
{
int num = 0;
cout << "1) cos(x), 2) sin(x), 3) tan(x), 4) atan2(y, x), 5) sqrt(x), 6) x^y," << endl;
cout << "7) ln(x), 8) e^x, 9) |x|, 10) floor(x), 11) ceil(x), 12) Exit." << endl;
cin >> num;
if( num == 12)
{
cout << "Exiting..." << endl;
break;
}
cout << "Enter x: ";
cin >> x;
if ( num == 3 || num == 4 || num == 6 )
{
cout << "Enter y: ";
cin >> y;
}
switch( num )
{
case 1:
operation = cosf(x);
operation_name = "cos(x)";
break;
case 2:
operation = sinf(x);
operation_name = "sin(x)";
break;
case 3:
operation = tanf(x);
operation_name = "tan(x)";
break;
case 4:
operation = r;
operation_name = "atan2(y, x)";
break;
case 5:
operation = sqrtf(x);
operation_name = "sqrt(x)";
break;
case 6:
operation = powf(x, y);
operation_name = "x^y";
break;
case 7:
operation = logf(x);
operation_name = "ln(x)";
break;
case 8:
operation = expf(x);
operation_name = "e^x";
break;
case 9:
operation = fabsf(x);
operation_name = "|x|";
break;
case 10:
operation = floorf(x);
operation_name = "floor(x)";
break;
case 11:
operation = ceilf(x);
operation_name = "ceil(x)";
break;
/*default:
quit = false;
break;*/
}
cout << operation_name << " = " << operation << endl;
}
}
| |