#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;
 
string centerize(string what, unsigned width)
{
    bool front = true;
    while(what.size() < width)
    {
        if (front)
            what.insert(what.begin(), ' ');
        else
            what.push_back(' ');
        front = !front;
    }
    return what;
}
 
double sinus (double x);                   //Funktions Prototype
double cosinus (double x);                 //Funktions Prototype
double hoch (double x);                    //Funktions Prototype
double durchlauf (double x, double y, double z, int a); //Funktions Prototype
 
int main () {
   
    int sigziffern;
    double schritte, startwert, endwert;
   
     
     cout << "Bitte Startwert fuer x eingeben: ";
     cin >> startwert;
     cout << "\n\n";
     
     cout << "Bitte Endwert fuer x eingeben: ";
     cin >> endwert;
     cout << "\n\n";
     
     cout << "Bitte Schrittweite fuer x eingeben: ";
     cin >> schritte;
     cout << "\n\n";
     
     cout << "Wieviele signifikante Ziffern sollen angezeigt werden: ";
     cin >> sigziffern;
     cout << "\n\n";
     
     // Wir können nicht sicher sagen, wie viele Stellen der Exponent bei scientific hat.
     // Daher etwas umständlich:
     unsigned length;
     {
         stringstream s;
         s << left << showpos << scientific  << setprecision(sigziffern) << 1.0;
         length = s.str().size();
     }
     cout << centerize("x", length) <<'|' << centerize("sin(x)", length) << '|'
          << centerize("cos(x)", length) << '|' << centerize("x^2", length) << "|\n";
     
     durchlauf (startwert, endwert, schritte, sigziffern);
     
     return 0;
       
}
 
 
double durchlauf (double x, double y, double z, int a) {                        // while Schleife fuer den Durchlauf der einzelnen Felder
       
       while (x<y || x==y) {
           cout << left << showpos << scientific << setprecision(a) << x << "|"
           << left << showpos << scientific  << setprecision(a) << sinus(x) << "|"
           << left << showpos << scientific  << setprecision(a) << cosinus(x) << "|"
           << left << showpos << scientific  << setprecision(a) << hoch(x) << "|"
           << "\n";
           x = x+z;
       }      
       
}
       
double sinus (double x) {                    //Funktion für Sinus Berechnung
       return sin(x);
       }
       
double cosinus (double x) {                  //Funktion für Cosinus Berechnung
       return cos(x);
       }
       
double hoch (double x) {                     //Funktion für Hoch Berechnung
       return x*x;
       }