NEED HELP. Not sure whats wrong. ASAP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: NEED HELP. Not sure whats wrong. ASAP

  1. #1
    Join Date
    May 2010
    Posts
    1

    Question NEED HELP. Not sure whats wrong. ASAP

    Hi. I am doing the following assignment.

    Problem Statement:
    In this assignment, the objective is to write a program that produces a plotting canvas
    on which some simple math functions can be plotted. The plotting canvas should
    have 21 rows and 76 columns which should be mapped to the rectangular area from
    (0,0) to (15,4). That is the bottom row (1st) corresponds to y=0 line (x axis) and top
    row (21st) corresponds to y=4 line. Similarly 1st column corresponds to x=0 line (y
    axis) and 76th column corresponds to x=15 line. The points drawn or marked on the
    canvas should be displayed with either * symbol or o symbol. The points that are not
    marked should be displayed with either . (dot) symbol or simply by space. The (0,0)
    location corresponds to the leftmost point of the last row (bottom) of the canvas.

    Here is a list of tasks that the program must perform


    1. When program begins (initialization):
    The XY canvas should be initialised so that if displayed it will either show .
    (dots) or spaces. It is not necessary to display the initial canvas during the
    initialization. In C++ code, this step should be performed using a separate
    function which can be clearly identified.

    2. Once the program has completed the above, the program should display a
    menu with the following selections and functions:

    a. Plot function 1 3.5sin(2πx/8)
    When this option is selected, the program should display the
    function y=3.5sin(2πx/8) on the plotting canvas. The values of
    the function that falls outside of the plotting canvas (e.g. negative
    values) should be ignored.
    (15,4)
    (15,0)
    (0,4)
    (0,0)
    300027 2010.1 Assignment Version 1.01 4

    b. Plot function 2 sqrt(x)
    When this option is selected, the program should display the
    function y=sqrt(x) on the plotting canvas. The values of the
    function that falls outside of the plotting canvas (e.g. negative
    values) should be ignored.

    c. Plot function 3 (Ax2+Bx+C)/(x2+1)
    When this option is selected, the program should request user to
    enter values of A, B, C which are real numbers. The program
    should ensure that the values entered must be within the
    following range:
    A between 0 and 3
    B between -2 and 5
    C between 1 and 4.
    Once A, B and C, the program should evaluate and display the
    function (Ax2+Bx+C)/(x2+1).

    d. Exit the program.
    When this option is selected, the program should perform the
    following tasks:

    i. Write student name and student ID to
    Prog2_StudentID.txt file.

    ii. Exit the program.

    I will paste the code for what i have done so far. this code compliles and runs and does most things and is pretty much there but the graph does not look like it supposed too.

    Here is screens of how the graph should look.
    1st two options
    http://i104.photobucket.com/albums/m...assignment.jpg

    3rd option
    http://i104.photobucket.com/albums/m...ssignment2.jpg

    Here is the code.
    #include <iostream>
    #include <cmath>
    #include <fstream>

    using namespace std;

    //Global intialization.
    const double PI = 3.14159;
    const int Row = 21;
    const int Col = 76;
    char Plot[Row][Col];

    //Function Prototypes.
    void canvas(char[Row][Col]);
    void Print(char [Row][Col]);
    void SIN(char[Row][Col]);
    void SQRT(char[Row][Col]);
    void POL(char[Row][Col]);




    int main()
    {

    int selection; //Menu Selection.


    canvas(Plot); // Function call, XY plane operator.
    Print(Plot); // Function call, XY plane display.


    system("cls"); // Clear screen.

    cout<<"\n Math Function Plotter\n";
    cout<<"\n 1.Plot Function 1. 3.5*sin((2*pi*t)/8))\n";
    cout<<"\n 2.Plot Function 2. sqrt(t)\n";
    cout<<"\n 3.Plot Function 3. (At^2 + Bt + C)/(t^2 + 1)\n";
    cout<<"\n 4.Exit \n\n";
    cout<<"\n Enter Selection: ";
    cin>> selection;




    switch ( selection ) // Menu.
    {
    case 1:

    SIN(Plot); // Sine curve function.


    break;

    case 2:

    SQRT(Plot); // Sqauare root function.

    break;

    case 3:

    POL(Plot); // Polynomial function.

    break;

    case 4:



    if ( selection == 4 ) // My details.
    {

    ofstream outputFile;
    outputFile.open( "c:\\ Prog2_16780545.txt");


    outputFile<< " Name: Behnam Jezan\n";
    outputFile<< " ID# : 16780545\n";
    }
    system("EXIT");// Quit program.
    break;


    default:

    while ( selection < 1 || selection > 4 ) // Selection validation.
    {
    cout<<" Please entre 1,2,3 or 4";
    cin>> selection;
    }

    }



    return 0;
    }
    // Plotting Canvas operator.
    void canvas(char A[Row][Col])
    {

    for (int j = (Row - 1); j > -1; j--) //Row operator.
    {
    for (int i = 1; i < Col; i++)// Column operator

    A[j][i] = '.';
    }
    }
    //Plotting Canvas Printer.
    void Print(char A[Row][Col])
    {


    system("cls");
    cout<<"\n\t\t\t Math Function Plotter\n";

    for (int i=0 ; i < Row ; i++)
    {


    for (int j=0 ; j < Col ; j++)
    {

    cout << A[i][j];//Display canvas once canvas() is called.

    }


    cout << "\n";
    }
    system("pause");
    system("cls");
    }



    //Sine curve.
    void SIN(char xy[Row][Col])
    {
    int i, j, x, y;

    canvas(Plot);


    cout << endl;

    {

    for (x = 0; x < Col; x++)
    {



    y =3.5*(sin(2.0*PI*x/8.0));







    xy[y][x] = 'o';
    cout<<"\n\t\t\t Math Function Plotter\n";
    }

    }

    {
    for (j = (Row -1); j > -1; j--)
    {
    for (i = 1; i < Col; i++)

    cout << xy[j][i];

    cout << endl;
    }

    }

    cout << endl;
    }

    // Square root curve.
    void SQRT(char xy[Row][Col])
    {
    int i, j, x, y;

    canvas(Plot);

    cout << endl;

    {
    for (x = 0; x < Col; x++)
    {

    y = sqrt((double)x);




    xy[y][x] = 'o';
    cout<<"\n\t\t\t Math Function Plotter\n";
    }



    }

    {
    for (j = (Row -1); j > -1; j--)
    {
    for (i = 1; i < Col; i++)

    cout << xy[j][i];

    cout << endl;
    }

    }


    cout << endl;
    }

    //Ploynomial curve.
    void POL(char xy[Row][Col])
    {
    int i, j, x, y;

    int A,B,C;

    cout<< " Enter value for A: ";
    cin >>A;
    while ( A < 0 || A > 3 )
    {
    cout << " Enter value between 0 to 3: ";
    cin >>A;
    }
    cout<< " Enter value for B: ";
    cin >>B;
    while ( B < -2 || B > 5 )
    {
    cout << " Enter value between 0 to 3: ";
    cin >>B;
    }
    cout<< " Enter value for C: ";
    cin >> C;
    while ( C < 1 || C > 4 )
    {
    cout << " Enter value between 0 to 3: ";
    cin >>C;
    }

    canvas(Plot);

    cout << endl;

    {
    for (x = 0; x < Col; x++ )
    {



    y = (A*(pow(x, 2.0)) + (B*x) + C ) / ( pow(x, 2.0) + 1 );








    xy[y][x] = 'o';
    cout<<"\n\t\t\t Math Function Plotter\n";
    }



    }

    {
    for (j = (Row -1); j > -1; j--)
    {
    for (i = 1; i < Col; i++)

    cout << xy[j][i];

    cout << endl;
    }

    }


    cout << endl;
    }



    -------------------------------------------------------------------------------


    As you can see when you compile are run it the graphs do not look the same. Please help and if someone could fix it for me it would be great.

    THANKS !!!

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,469

    Re: NEED HELP. Not sure whats wrong. ASAP

    Please, edit your post addidng Code tags around code snippet and indentations within code block.
    See Announcement: Before you post....
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center