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.
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++)
Bookmarks