當前位置:編程學習大全網 - 網站源碼 - VC++編程!請教高手!急!!!

VC++編程!請教高手!急!!!

這是VC6.0的BUG,不用名空間就可以,或者在TC下運行

#include <iostream.h>

class Complex

{

private:

double r;

double i;

public:

Complex(double x=0.0,double y=0.0)

{

r=x;

i=y;

}

Complex operator+(const Complex &c);

friend Complex operator-(const Complex &c1,const Complex &c2);

void print();

};

Complex Complex::operator+(const Complex &c)

{

Complex t;

t.r=r+c.r;

t.i=i+c.i;

return t;

}

Complex operator-(const Complex &c1,const Complex &c2)

{

Complex t;

t.r=c1.r-c2.r;

t.i=c1.i-c2.i;

return t;

}

void Complex::print()

{

cout<<"("<<r<<","<<i<<")"<<endl;

}

void main()

{

Complex a(3.0,4.0),b(10.5,20.5),c;

c=a+b;

c.print();

c=a-b;

c.print();

}

  • 上一篇:抖音和今日頭條是同壹個嗎?
  • 下一篇:請高手寫壹個薛斯通道1回調選股公式。。。。謝謝
  • copyright 2024編程學習大全網