谁来帮我找一下bug

NeoHeart 2004-10-12 04:26:23
我的代码是如下,他总是说我unexpect end of file,谁来帮我编译一下,看看问题出在哪 谢谢了


#include <iostream.h>
#include <math.h>

class equation
{
public:
void twoRealAnswer(int a,int b,int c);
void oneRealAnswer(int a,int b,int c);
void twoUnrealAnswer(int a,int b,int c);
private:
float a,b,c;
float realsection,unrealsection;
}


class equation::twoRealAnswer(int a,int b,int c)
{
realsection=-b/2*a;
unrealsection=sqrt((b*b-4*a*c)/2*a);
}

class equation::oneRealAnswer(int a,int b,int c)
{
realsection=-b/2*a;
unrealsection=0;
}

class equation::twoUnrealAnswer(int a,int b,int c)
{
realsection=-b/2*a;
unrealsection=sqrt((4*a*c-b*b)/2*a);
}


void main()
{
equation A;
cout<<"input the argument of a,b,c:";
cin>>A.a>>A.b>>A.c;
if ((A.b*A.b-4*A.c*A.a)>0)
{
A.twoRealAnswer(int a,int b,int c);
cout<<"answer1="<<A.realsection+A.unrealsection<<endl;
cout<<"answer2="<<A.realsection-A.unrealsection<<endl;
}
else if((A.b*A.b-4*A.c*A.a)==0)
{
A.oneRealAnswer(int a,int b,int c);
cout<<"answer="<<A.realsection+A.unrealsection<<endl;
}
else if((A.b*A.b-4*A.c*A.a)<0)
{
A.twoUnrealAnswer(int a,int b,int c);
cout<<"answer1="<<A.realsection<<"+"<<A.unrealsection<<"i"<<endl;
cout<<"answer2="<<A.realsection<<"+"<<A.unrealsection<<"i"<<endl;
}
}
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
NeoHeart 2004-10-12
  • 打赏
  • 举报
回复
to xteaj(半桶水
的确错了,应该用个成员函数去修改a,b,c 吧?
  • 打赏
  • 举报
回复
cout<<"answer1="<<A.realsection<<"+"<<A.unrealsection<<"i"<<endl;
cout<<"answer2="<<A.realsection<<"+"<<A.unrealsection<<"i"<<endl;
//你输得出吗,都用保护成员,保护成员在这种情况下不可见!
  • 打赏
  • 举报
回复
equation A;
cout<<"input the argument of a,b,c:";
cin>>A.a>>A.b>>A.c;//你输得进来吗?a,b,c是保护成员?
cat_dog 2004-10-12
  • 打赏
  • 举报
回复
class equation
{
public:
void twoRealAnswer(int a,int b,int c);
void oneRealAnswer(int a,int b,int c);
void twoUnrealAnswer(int a,int b,int c);
private:
float a,b,c;
float realsection,unrealsection;
} //这里要加分号

有每个类结束处加分号。
freefalcon 2004-10-12
  • 打赏
  • 举报
回复
class定义后面需要分号

而类的成员函数在定义时class关键字不是必需的

64,637

社区成员

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

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