# c ++ – Algebraic curve plotter

I've tried coding a plotter of algebraic curves. My plan was to accept an expression of x in the form of string (decreasing powers of x) of the user and to store the corresponding powers and coefficients of x in 2 separate tables, which I would evaluate and then represent. But all this goes for an infinite loop. Here is the code:

``````        //graphic
#understand
#understand
#understand
#understand
#understand
#understand
#define ab (x) 5 * x + 319 // shifts the origin
#define or (y) - (5 * y-239)
int x, y, num;
polyf class
{
public:
//private:
float * indx;
float * coeffx;
float constterm;
// Public:
polyf (char a[], float l1, float l2)
{
indx = new float[num];
coeffx = new float[num];
// outtextxy (2,2, a);
int i = 0, j = 0;
//powers
char p[6];
while[i]! = & # 39;  0 & # 39;)
{
cost << "@@";
if a[i]! = X & # 39;)
i ++;
other
{
if a[i+1]== & # 39; ^ & # 39; && at[i+2]== (& # 39;)
{
num ++;
i + = 3;
float * temp = new float[num];
while (j <num)
{cost << "L0L";
temp[j]= indx[j];
j ++;
}
wipe off [] indx;
indx = temp;
j = 0;
while[i]! = & # 39;) & # 39;)
{cost << "lmao";
p[j++]= one[i++];}
p[j]= ## ;; j = 0;
indx[num-1]= atof (p);
}
other
{++ num; j = 0;
float * temp = new float[num];
while (j <num)
{cout << "rofl";
temp[j]= indx[j];
j ++;
}
wipe off [] indx;
indx = temp;
j = 0;
indx[num-1]= 1.0;
}
}
}
i = j = num = 0;

// coefficient

if a[i]== & # 39; x & # 39;)
{
float * temp = new float[num];
while (j <num)
{cost << "maxx";
temp[j]= coeffx[j];
j ++;
}
wipe off [] coeffx;
coeffx = temp;
j = 0;
coeffx[0]= 1;
}
other
{
float * temp = new float[num];
while (j <num)
{cout << << brb ";
temp[j]= coeffx[j];
j ++;
}
wipe off [] coeffx;
coeffx = temp;
j = 0;
coeffx[0]= atof (a);
}
while[i]! = & # 39;  0 & # 39;)
{cout # << "#";
if a[i]==> x & # 39; && at[i+1]== & # 39; ^ & # 39;)
{

while[i]! = & # 39;) & # 39;)
{cout << << <> ";
i ++;
i + = 1;
num ++;
float * temp1 = new float[num];
while (j <num)
{
cost << "{}";
temp1[j]= coeffx[j];
j ++;
}
wipe off [] coeffx;
coeffx = temp1;
j = 0;
while[i]! = X & # 39;)
{cout << "sim";
p[j++]= one[i++];
}
p[j]= ## ;; j = 0;
coeffx[num-1]= atof (p);
}

other
i ++;
}
// term const
j = 0;
i = 1;
while[i+1]! = & # 39; + & # 39; || at[i+1]! = & # 39; - & # 39;)
{cout << << xD "; p[j++]= one[i--]; }
p[j]= & # 39;  0 & # 39 ;;
strrev (p);
constterm = atof (p);
// plotpoly (11, 12);
}
float evalpoly (float f)
{
float pf = constterm;
for (int i = 0; i <num; i ++)
pf + = coeffx[i]* pow (f, indx[i])
return pf;
}
empty plotpoly (floating range L, floating range R)
{
putpixel (L range, evalpoly (L range), 2);
putpixel (R range, evalpoly (R range), 2);
setcolor (1);
for (float i = range L + 1; i <range R; i + = 1)
lineto (i, evalpoly (i));
}
};
void coacc (int x, int y) // accept contact information
{
cost <<"Enter co-ordinates :nEnter x: ";
cin>> x;
cost <<"Enter y: ";
cin>> y;
}
void main ()
{clrscr ();
polyf p ("2x ^ (2) + 4x + 4", ab (-5.0), ab (8.0));
cout << p.constterm << "" << p.evalpoly (ab (-5.0));
cost << "" << p.coeffx[0]<< "" << p.indx[0]<< "" << num;
/ * int gdriver = DETECT, gmode, errorcode;
initgraph (& gdriver, & gmode, "C: \ turboc3 \ bgi");
line (ab (0) or (238), ab (0) or (-238)); // y axis
line (ab (318) or (0), ab (-318) or (0)); // x axis
outtextxy (ab (0) or (0), "O"); //origin
* /
}
``````

Note:
(1) You will find many parts of the coding that I have temporarily made as comments (mostly graphic elements). That's because I wanted to use "cost", which graphics do not allow.

(2) The many cost statements have been for me to determine which loop is the cause of the problem, but I guess I'm not going anywhere by myself. (sigh)

(3) The loop containing "rofl" goes crazy. I've printed 'num'. in this loop and it is incremented at each iteration, although the loop contains no instruction modifying the value of num.

(4) I am a high school student and a beginner, so forgive my idiocy and my inexperienced approach to both coding and questioning. I will be happy to learn if you report errors!