fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <string>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. string centerize(string what, unsigned width)
  9. {
  10. bool front = true;
  11. while(what.size() < width)
  12. {
  13. if (front)
  14. what.insert(what.begin(), ' ');
  15. else
  16. what.push_back(' ');
  17. front = !front;
  18. }
  19. return what;
  20. }
  21.  
  22. double sinus (double x); //Funktions Prototype
  23. double cosinus (double x); //Funktions Prototype
  24. double hoch (double x); //Funktions Prototype
  25. double durchlauf (double x, double y, double z, int a); //Funktions Prototype
  26.  
  27. int main () {
  28.  
  29. int sigziffern;
  30. double schritte, startwert, endwert;
  31.  
  32.  
  33. cout << "Bitte Startwert fuer x eingeben: ";
  34. cin >> startwert;
  35. cout << "\n\n";
  36.  
  37. cout << "Bitte Endwert fuer x eingeben: ";
  38. cin >> endwert;
  39. cout << "\n\n";
  40.  
  41. cout << "Bitte Schrittweite fuer x eingeben: ";
  42. cin >> schritte;
  43. cout << "\n\n";
  44.  
  45. cout << "Wieviele signifikante Ziffern sollen angezeigt werden: ";
  46. cin >> sigziffern;
  47. cout << "\n\n";
  48.  
  49. // Wir können nicht sicher sagen, wie viele Stellen der Exponent bei scientific hat.
  50. // Daher etwas umständlich:
  51. unsigned length;
  52. {
  53. stringstream s;
  54. s << left << showpos << scientific << setprecision(sigziffern) << 1.0;
  55. length = s.str().size();
  56. }
  57. cout << centerize("x", length) <<'|' << centerize("sin(x)", length) << '|'
  58. << centerize("cos(x)", length) << '|' << centerize("x^2", length) << "|\n";
  59.  
  60. durchlauf (startwert, endwert, schritte, sigziffern);
  61.  
  62. return 0;
  63.  
  64. }
  65.  
  66.  
  67. double durchlauf (double x, double y, double z, int a) { // while Schleife fuer den Durchlauf der einzelnen Felder
  68.  
  69. while (x<y || x==y) {
  70. cout << left << showpos << scientific << setprecision(a) << x << "|"
  71. << left << showpos << scientific << setprecision(a) << sinus(x) << "|"
  72. << left << showpos << scientific << setprecision(a) << cosinus(x) << "|"
  73. << left << showpos << scientific << setprecision(a) << hoch(x) << "|"
  74. << "\n";
  75. x = x+z;
  76. }
  77.  
  78. }
  79.  
  80. double sinus (double x) { //Funktion für Sinus Berechnung
  81. return sin(x);
  82. }
  83.  
  84. double cosinus (double x) { //Funktion für Cosinus Berechnung
  85. return cos(x);
  86. }
  87.  
  88. double hoch (double x) { //Funktion für Hoch Berechnung
  89. return x*x;
  90. }
Success #stdin #stdout 0s 2992KB
stdin
0 1 0.1 8
stdout
Bitte Startwert fuer x eingeben: 

Bitte Endwert fuer x eingeben: 

Bitte Schrittweite fuer x eingeben: 

Wieviele signifikante Ziffern sollen angezeigt werden: 

       x       |     sin(x)    |     cos(x)    |      x^2      |
+0.00000000e+00|+0.00000000e+00|+1.00000000e+00|+0.00000000e+00|
+1.00000000e-01|+9.98334166e-02|+9.95004165e-01|+1.00000000e-02|
+2.00000000e-01|+1.98669331e-01|+9.80066578e-01|+4.00000000e-02|
+3.00000000e-01|+2.95520207e-01|+9.55336489e-01|+9.00000000e-02|
+4.00000000e-01|+3.89418342e-01|+9.21060994e-01|+1.60000000e-01|
+5.00000000e-01|+4.79425539e-01|+8.77582562e-01|+2.50000000e-01|
+6.00000000e-01|+5.64642473e-01|+8.25335615e-01|+3.60000000e-01|
+7.00000000e-01|+6.44217687e-01|+7.64842187e-01|+4.90000000e-01|
+8.00000000e-01|+7.17356091e-01|+6.96706709e-01|+6.40000000e-01|
+9.00000000e-01|+7.83326910e-01|+6.21609968e-01|+8.10000000e-01|
+1.00000000e+00|+8.41470985e-01|+5.40302306e-01|+1.00000000e+00|