c++控制台程序出错,请大家帮帮忙看看
cyply 2003-10-15 09:21:18 错误信息:F:\Visual Studio Projects\c++\complex\complex.cpp(56) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
大家帮帮忙看看,或许有更好的算法,请指点指点。
源程序为:
#include"iostream.h"
class Complex//复数类定义
{ private:
double Real;//复数实部
double imag;//复数虚部
public:
void output()//返回函数
{
if(imag>=0)
cout<<a.Real<<"+"<<a.imag<<"i "<<endl;
else
cout<<a.Real<<a.imag<<"i "<<endl;
}
void getnumber(double x,double y)
{
Real=x;
imag=y;
}
Complex operator -(const Complex a)//重载一元操作符负号"-"
{
Complex b;
b.Real=-a.Real;
b.imag=-a.imag;
return b;
}
Complex operator +(const Complex a)//重载二元操作符加号"+"
{
Complex b;
b.Real=Real+a.Real;
b.imag=imag+a.imag;
return b;
}
Complex operator *(const Complex a)//重载二元操作符加号"*"
{
Complex b;
b.Real=Real*a.Real-imag*a.imag;
b.imag=Real*a.imag+imag*a.Real;
return b;
}
Complex operator /(const Complex a)//重载二元操作符加号"/"
{
Complex b;
b.Real=(Real*a.Real+imag*a.imag)/(a.Real*a.Real+a.imag*a.imag);
b.imag=(imag*a.Real-Real*a.imag)/(a.Real*a.Real+a.imag*a.imag);
return b;
}
void main()
{
Complex a,b,c;
a.getnumber(0.0,0.0);
b.getnumber(1.0,1.0);
c=a-b;
cout<<"if c=a-b 则c=";
c.output();
c=a+b;
cout<<"if c=a+b 则c=";
c.output();
c=a*b;
cout<<"if c=a*b 则c=";
c.output();
c=a/b;
cout<<"if c=a/b 则c=";
c.output();
}