Friday, December 15, 2017

C++ Math Library Function Table

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

double sqrt (double x)
{
    return sqrt (x);
}
double Exp (double x)
{
    return exp (x);
}
double Log (double x)
{
    return log (x);
}
double Powa (double x)
{
    return pow(2,x);
}
double Logten (double x)
{
    return log10(x);
}
double Fabs (double x)
{
    return fabs(x);
}
double Ceil (double x)
{
    return ceil(x);
}
double Floor (double x)
{
    return floor(x);
}
double Sin (double x)
{
    return sin(x);
}
double Cos (double x)
{
    return cos(x);
}
float Tan (float x)
{
    return tan(x);
}

int main()
{
    cout << "Function" << setw(10) << "1" << setw(8) << "2" << setw(8) << "3" << setw(8)<< "4" << setw(8) << "5" << endl;
        cout << endl;

    cout << "sqrt()" << setw(12);
    for (int x = 1; x < 6; x++)
    {
        cout << setprecision(4) << sqrt(x) << setw(8);
    }

    cout << endl;

    cout << setw(0) << "exp()" << setw(13);
    for (int x = 1; x < 6; x++)
    {
        cout << setprecision(4) << Exp(x) << setw(8);
    }

    cout << endl;

    cout << setw(0) << "log()" << setw(13);
    for (int x = 1; x < 6; x++)
    {
        cout << setprecision(4) << Log(x) << setw(8);
    }

    cout << endl;

    cout << setw(0) << "Log10()" << setw(11);
    for (int x = 1; x < 6; x++)
    {
        cout << setprecision(4) << Logten(x) << setw(8);
    }

    cout << endl;

    cout << setw(0) << "pow()" << setw(13);
    for (int x = 1; x < 6; x++)
    {
        cout << setprecision(4) << Powa(x) << setw(8);
    }

    cout << endl;
    cout << endl;

    cout << "Function" << setw(10) << "-1.5" << setw(8) << "-0.04" << setw(8) << "0.70" << setw(8) << "1.8" << setw(8) << "2.90" << endl;
        cout << endl;

    cout << setw(0) << "fabs()" << setw(12);
    for (double x = 0; x < 5; x++)
    {
        double y = (-1.5) + (x * 1.1);
        cout << setprecision(4) << Fabs(y) << setw(8);
    }

    cout << endl;

    cout << setw(0) << "ceil()" << setw(12);
    for (double x = 0; x < 5; x++)
    {
        double y = (-1.5) + (x * 1.1);
        cout << setprecision(4) << Ceil(y) << setw(8);
    }

    cout << endl;

    cout << setw(0) << "floor()" << setw(11);
    for (double x = 0; x < 5; x++)
    {
        double y = (-1.5) + (x * 1.1);
        cout << setprecision(4) << Floor(y) << setw(8);
    }

    cout << endl;

    cout << endl;

    cout << "Function" << setw(10) << "-1.57" << setw(8) << "0.00" << setw(8) << "1.57" << setw(8) << "3.14" << setw(8) << "4.71" << endl;
        cout << endl;

    cout << setw(0) << "sin()" << setw(13);
    for (double x = 0; x < 5; x++)
    {
        double y = (-1.57) + (x * 1.57);
        cout << setprecision(2) << fixed << Sin(y) << setw(8);
    }
    cout << endl;

    cout << setw(0) << "cos()" << setw(13);
    for (double x = 0; x < 5; x++)
    {
        double y = (-1.57) + (x * 1.57);
        cout << setprecision(2) << fixed << Cos(y) << setw(8);
    }
    cout << endl;

    cout << setw(0) << "tan()" << setw(13);
    for(double x = 0; x < 5; x++)
    {
        double y = (-1.57) + (x * 1.57);
        cout << Tan(y) << setw(8);
    }

    cout << endl;

    return 0;

}

No comments:

Post a Comment