Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include "sinus.h"
- using namespace std;
- int checkRange(double sin, int y);
- void main() {
- /*
- Erzeugen Sie ein 2-dimensionales Feld von Zeichen (21 Zeilen a 41 Zeichen)
- und drucken sie eine Sinuskurve in dieses Feld (siehe Beispielskizze).
- Geben Sie diese Kurve dann in der Konsole mittels printf() oder cout aus.
- Benutzen Sie fΓΌr den Sinus die Funktion double sin(double x) aus math.h.
- */
- const int x = 41;
- const int y = 21; // + Terminierungsnull
- double pi = 3.1416;
- char Feld[y][x]; //feld[Zeilen][Spalten]
- // Feld "leer" initialiseren
- for (int yKoord = 0; yKoord < y ; yKoord++) {
- for (int xKoord = 0; xKoord < x; xKoord++) {
- Feld[yKoord][xKoord] = '_';
- }
- }
- cout << "\n\n\n";
- // SPALTENweise durchiterieren --> x = ... if(y = sin(x) ) --> #
- for (int xKoord = 0; xKoord < x; xKoord++) {
- //double xinGrad =
- double Ergebnis = (10 * sin((xKoord*pi/20)) + 10);
- for (int yKoord = 0; yKoord < y; yKoord++) {
- if (checkRange(Ergebnis, yKoord)) {
- Feld[yKoord][xKoord] = '#'; break;
- }
- }
- cout << "\n";
- }
- cout << "\n\n";
- // Ausgabe
- for (int i = 0; i < y; i++) {
- for (int f = 0; f < x; f++) {
- cout << Feld[i][f];
- }
- cout << "\n";
- }
- }
- int checkRange(double sin, int y)
- {
- if (sin <= (y + 0.5) && sin > (y - 0.5))
- return 1;
- else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement