请教一个关于类的小问题!!
这是一个解一元二次方程的程序(没完善),有个地方编译不过去了,哪位大哥 帮帮忙阿!!!
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
class Plural
{
public:
void Set(double x,double y)
{
a=x;
b=y;
}
void Paint(double x,double y)
{
cout<<x<<"+"<<y<<"i"<<endl;
}
private:
double a;
double b;
};
int main()
{
cout << "Coefficients for quadratic equation: ";
double a;
double b;
double c;
cin >> a >> b >> c;
if ((a != 0) && ((b*b - 4*a*c) > 0))
{
double radical = sqrt(b*b - 4*a*c);
double root1 = (-b + radical) / (2*a);
double root2 = (-b - radical) / (2*a);
cout << "The roots of " << a << "x**2 + " << b
<< "x + " << c << " are " << root1 << " and "
<< root2 << endl;
}
else if ((a !=0)&&((b*b-4*a*c)<=0))
{
double radical = sqrt(-(b*b - 4*a*c));
Plural root3 ,root4;
double x= (-b ) / (2*a);
double y=radical/(2*a);
root3.Set( x, y);
root4.Set(x,-y);
root3.Paint ;//**********编译不通过******
root4.Paint;//**********编译不通过******
}
else
{
cout << a << "x**2 + " << b << "x + " << c
<< " does not have two real roots" << endl;
}
return 0;
}
但下面的程序编译就通过了,不知为什么!!请指教!!
#include<iostream.h>
class Plural
{
public:
void Set(int x,int y)
{
a=x;
b=y;
}
void Paint(int x,int y)
{
cout<<x<<"+"<<y<<"i"<<endl;
}
private:
int a;
int b;
};
void main()
{
Plural p;
int x,y;
char q,i;
cout<< "Enter a plural: example 2+3i"<<endl;
cin>>x>>q>>y>>i;
p.Set( x, y);
p.Paint(x,y);
}