Advertisement
Guest User

sinus

a guest
Jan 16th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include "sinus.h"
  4. using namespace std;
  5.  
  6. int checkRange(double sin, int y);
  7.  
  8. void main() {
  9.  
  10. /*
  11.     Erzeugen Sie ein 2-dimensionales Feld von Zeichen (21 Zeilen a 41 Zeichen)
  12.     und drucken sie eine Sinuskurve in dieses Feld (siehe Beispielskizze).
  13.     Geben Sie diese Kurve dann in der Konsole mittels printf() oder cout aus.
  14.     Benutzen Sie fΓΌr den Sinus die Funktion double sin(double x) aus math.h.
  15. */
  16.     const int x = 41;
  17.     const int y = 21; // + Terminierungsnull
  18.     double pi = 3.1416;
  19.                        
  20.     char Feld[y][x];        //feld[Zeilen][Spalten]
  21.  
  22.     // Feld "leer" initialiseren
  23.     for (int yKoord = 0; yKoord < y ; yKoord++) {
  24.  
  25.         for (int xKoord = 0; xKoord < x; xKoord++) {
  26.  
  27.             Feld[yKoord][xKoord] = '_';
  28.         }
  29.     }
  30.  
  31.         cout << "\n\n\n";
  32.  
  33.     // SPALTENweise durchiterieren --> x = ... if(y = sin(x) ) --> #
  34.  
  35.     for (int xKoord = 0; xKoord < x; xKoord++) {
  36.        
  37.         //double xinGrad =
  38.         double Ergebnis = (10 * sin((xKoord*pi/20)) + 10);
  39.  
  40.         for (int yKoord = 0; yKoord < y; yKoord++) {
  41.  
  42.             if (checkRange(Ergebnis, yKoord)) {
  43.                 Feld[yKoord][xKoord] = '#'; break;
  44.             }
  45.  
  46.         }
  47.         cout << "\n";
  48.  
  49.     }
  50.     cout << "\n\n";
  51.  
  52.     // Ausgabe
  53.     for (int i = 0; i < y; i++) {
  54.         for (int f = 0; f < x; f++) {
  55.             cout << Feld[i][f];
  56.         }
  57.         cout << "\n";
  58.     }
  59. }
  60.  
  61. int checkRange(double sin, int y)
  62. {
  63.     if (sin <= (y + 0.5) && sin > (y - 0.5))
  64.         return 1;
  65.     else
  66.         return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement