Trying to draw sin graph in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ZaynM
    New Member
    • Aug 2014
    • 1

    Trying to draw sin graph in c++

    This is what I have so far
    void TrigFunctions:: DrawSine(int degree)
    {
    int range=0;
    int NumLines=16;
    double CurrentStep;

    //constants
    const double sample=0.05;
    const double PI=3.1415;
    const int FIRSTSTEP=0.5;

    //prompt your user for input.
    cout << "Please input the range."<<endl;
    cin >> range;

    //Convert for degree to radians and assign current step a value
    CurrentStep= FIRSTSTEP * PI/180;

    //get sine values and display graph
    for(int i=0;i < NumLines;i++)
    {
    for(int j =-180;j < 180;j++)
    {

    /* Compare the sin of the step value to the sin of the sine range value and print '*' if there is a match.
    Otherwise, print a blank */
    if(sin(CurrentS tep) == sin(j* PI/180))
    {
    cout <<"*"<<endl;
    }
    else
    {
    cout <<" ";
    }
    }

    //Increment Current step
    CurrentStep += FIRSTSTEP*PI/180;
    }


    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What's your question exactly?

    I see the function is named DrawSine and it takes an int argument. Then in the middle it becomes a data entry function to get the range. The function should have no arguments. All it should do id draw the sine with the couts.

    The range, degree, NumLines, sample, should be class member variables. These class members can have their own member functions for data entry.

    Try to keep your functions doing only one thing.

    Comment

    Working...