PROBLEM MIT C-programm



  • Hey, ich stehe momentan echt auf dem schlauch und weis nicht wie ich mein Problem lösen kann. Das programm soll so eine Art funktionsplotter sein, der halt beim errechneten wert im graphen ein char, in diesem Fall ein x setzt.. Uch schicke euch mal meine dateien. es wäre echt cool, wenn einer eine Lösung dafür hat..

    /*main.c*/
    #include <math.h>
    #include "textplot.h"
    #include <stdio.h>

    double poly(double x) {
    return (8*x*x*x - 10*x*x -9*x +9)/4;
    }

    double sin(double x) {
    if(x !=0)
    return sin(x)/x;

    return 1;
    }

    int main(int argc, char *argv[]) {
    Function f;
    clearPlotter () ;
    setPlotArea(-1.0,-5, 2.0, 7);
    /*calcdY(TRUE);*/

    f = poly;
    addFunction(f);

    f = sin;
    addFunction(f);

    showPlotter();
    return 0;
    }

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@

    /*textplot.c*/
    #include "textplot.h"
    #include<math.h>
    #include<stdio.h>

    char graph[ROWS][COLS];

    /** add a function to plot)*/
    void addFunction(Function f)
    {
    int z = 0, help = 0;
    double xAchse,x,y = 0;
    xAchse = 0.0375;

    for(x = -1; x < 2; x = x + xAchse)
    {
    /*y=f(x)*/
    y=f(x);
    if(y == 0)
    {
    y = ROWS / 2 + 2;
    help = y;
    }
    else
    {
    if(y > 0)
    {
    help = y;
    if(y - help > 0.3 && y - help < 0.6)
    {
    help = ROWS/2 + 1 - help; /* Ermittelung der richtigen Stelle auf dem Y Graphen bei Komma Werten /
    }
    else
    {
    if(y - help < 0.3)
    {
    help = ROWS/2 - help;
    }
    else
    {
    help = ROWS/2 - help - 2;
    }
    }
    }
    else
    {
    help = y;
    if(y - help > 0.3 && y - help < 0.6)
    {
    help = ROWS/2 + help + 3; /
    Ermittelung der richtigen Stelle auf dem Y Graphen bei Komma Werten */
    }
    else
    {
    if(y - help < 0.3)
    {
    help = ROWS/2 + 2 + help;
    }
    else
    {
    help = ROWS/2 + help + 4;
    }
    }
    }
    }

    graph[help][z] = '*';
    z++;
    }
    }

    /** initialize the plotter */
    void clearPlotter () {
    int i,j;
    for(i=0; i<ROWS; i++)
    {
    for(j=0; j<COLS; j++)
    {
    graph[i][j] = ' ';
    }
    }
    }
    /** print plotter array to stdout */
    void showPlotter(){
    int i,j;
    for(i=0; i<ROWS; i++)
    {
    for (j=0; j<COLS; j++)
    {
    printf("%c",graph[i][j]);
    }
    printf("\n");
    }
    }

    /** set the plot area coordinates*/
    void setPlotArea(float x0, float y0, float x1, float y1){
    int mark = 0;
    plot_Axes();
    mark = (ROWS - 2) / 2;
    mark = mark - 5;
    if(y0 > mark - 5 || y0 < (mark - 5)*(-1))
    {

    }
    else
    {
    if(x0 > 2.0 || x0 < -1.0)
    {

    }
    }

    }
    /** plot char at coordinate (x,y). */
    void plot(float x, float y, char c){

    }
    /** utility method to draw x,y axes */
    void plot_Axes(){
    int i,j, mark,flag = 0;

    mark = (ROWS - 2) / 2;
    mark = mark - 5;
    graph[0][40]='^';
    for(i=1;i<ROWS; i++){
    graph[i][40]='|';
    if(i % 2 == 0 && i != 0)
    {
    graph[i][39]=mark+'0';
    if(mark> 0 && flag == 0)
    {
    graph[i][38] = '+';
    mark--;
    }
    else
    {
    graph[i][38] = '-';
    flag = 1;
    mark++;
    }
    graph[i][40]='+';
    }
    }

    for(j = 0; j < COLS; j++)
    {
    graph[14][j] = '-';
    }

    graph[14][COLS - 1] = '>';
    }

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    /*textplot.h*/
    #ifndef TEXTPLOT_H_
    #define TEXTPLOT_H_

    #define ROWS 25
    #define COLS 80

    typedef enum {FALSE,TRUE} BOOLEAN;

    typedef double (*Function)(double);
    /** add a function to plot */
    void addFunction(Function f);

    /** initialize the plotter */
    void clearPlotter () ;
    /** print plotter array to stdout */
    void showPlotter();
    /** set the plot area coordinates */
    void setPlotArea(float x0, float y0, float x1, float y1);
    /** plot char at coordinate (x,y). */
    void plot(float x, float y, char c);
    /** utility method to draw x,y axes */
    void plot_Axes();

    #endif /*TEXTPLOT_H_*/



  • Was ist dein Problem?
    Du hast keine Frage gestellt (zumindest finde ich kein ?)

    Und setz deinen Code zwischen Code-tags: Am Anfang vom Code auf den C-Button unter dem 😡 klicken und am Ende vom Code nochmal.
    Ode Code markieren und einmal auf den C-Button Klicken.
    Du als registierter Usewr kannst das auch noch nachträglich tun.
    Nutze die Vorschaufunktion.

    Du hast da eine Funktion die sin heißt. In der Funktion wird auch sin aufgerufen.
    Und du bindest math.h ein, in der auch eine Funktion sin deklariert ist.

    Welche Funktionen meinst du bei den Aufrufen?



  • DirkB schrieb:

    Was ist dein Problem?

    Was in void plot(float x, float y, char c) reingehört vielleicht?



  • Mir ist aufgefallen, das bei der Sinusfunktion

    sin(winkel_im_Bogenmass);
    

    vorher keine Umwandlung des Winkels (Parameter1)
    ins Bogenmass erfolgt
    mit

    bogenmass = (Winkel_in_Grad * pi)  / 180;
    

    kannst du das erledigen.

    Vielleicht führt das zu fehlerhaften Ausgaben.


Anmelden zum Antworten