请教一个关于类的小问题!!

flamngo 2004-03-23 08:25:53
这是一个解一元二次方程的程序(没完善),有个地方编译不过去了,哪位大哥 帮帮忙阿!!!

#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);
}


...全文
47 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChenLau 2004-03-23
  • 打赏
  • 举报
回复
呵呵,粗心大意!!
Darkay_Lee 2004-03-23
  • 打赏
  • 举报
回复
明明是函数调用嘛,参数都不写,不错才怪啦!
cutemouse 2004-03-23
  • 打赏
  • 举报
回复
MAIN里面!
root3.Paint();//**********编译不通过******
root4.Paint();//**********编译不通过******
flamngo 2004-03-23
  • 打赏
  • 举报
回复
谢谢阿!
root3.Paint(x,y) ;
root4.Paint(x,y);
cutemouse 2004-03-23
  • 打赏
  • 举报
回复
class Plural
{
public:
void Set(double x,double y)
{
a=x;
b=y;
}
void Paint(double x,double y)
{
cout<<x<<"+"<<y<<"i"<<endl;
}
void Paint()
{
cout<<a<<"+"<<b<<"i"<<endl;
}

private:
double a;
double b;

};
flamngo 2004-03-23
  • 打赏
  • 举报
回复
但下面的程序编译就通过了,不知为什么!!请指教!!
#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);
}

ldongpeng 2004-03-23
  • 打赏
  • 举报
回复
同意TaoLD(Xaero)看法!
cgsw12345 2004-03-23
  • 打赏
  • 举报
回复
root3.Paint ;//从语法上来说这是错误的,如果是调用程成员函但又没有重载,
dddd8888 2004-03-23
  • 打赏
  • 举报
回复
Paint是什么
TaoLD 2004-03-23
  • 打赏
  • 举报
回复
root3.Paint ;//**********编译不通过******
root4.Paint;//**********编译不通过******


Paint的实参表呢?

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧