您的位置:首页 > 其它

半年学习以来写的最长的程序,但是还有错误

2009-06-24 21:49 344 查看
#include <iostream>
using namespace std ;
class Complex
{
public:
Complex()
{
real=0 ;
imag=0 ;
}
Complex(int r , double im) : real(r) , imag(im) {}
friend Complex operator + (const Complex & , const Complex &) ;
friend Complex operator - (const Complex & , const Complex &) ;
friend Complex operator * (const Complex & , const Complex &) ;
friend Complex operator / (const Complex & , const Complex &) ;
void display ()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl ;
}
private:
int real ;
double imag ;
}

Complex operator + (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = c1.real + c2.real ;
c.imag = c1.imag + c2.imag ;
return c ;
}

Complex operator - (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = c1.real - c2.real ;
c.imag = c1.imag - c2.imag ;
return c ;
}

Complex operator * (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = (c1.real*c2.real) - (c1.imag*c2.imag) ;
c.imag = (c1.imag*c2.real) + (c1.real*c2.imag) ;
return c ;
}

Complex operator / (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = (c1.real * c2.real + c1.imag * c2.imag) / (c2.real * c2.real + c2.imag * c2.imag) ;
c.imag = (c1.imag * c2.real - c1.real * c2.imag) / (c2.real * c2.real + c2.imag * c2.imag) ;
return c ;
}

int main ()
{
Complex a(3 , 4) , b(5 , 10) , c ;
c = a + b ;
cout<<"a + b = "
c.display() ;
c = a - b ;
cout<<"a - b = "
c.display() ;
c = a * b ;
cout<<"a * b = "
c.display() ;
c = a / b ;
cout<<"a / b = "
c.display() ;
return 0 ;
}

--------------------Configuration: myfirst - Win32 Debug--------------------
Compiling...
myfirst.cpp
D:\myfirst\myfirst.cpp(12) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

myfirst.obj - 1 error(s), 0 warning(s)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐