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

it2025-05-21  40

 

#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.cppD:\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 informationError executing cl.exe.

myfirst.obj - 1 error(s), 0 warning(s)

 

 

转载于:https://www.cnblogs.com/bruceloo/archive/2009/06/24/1510528.html

最新回复(0)