hướng dẫn thui heng !
tạo: class complex
2 thuộc tính : public float real,image
tạo constructor :
complex(int a=0,int b=0)
{
real=a;image=b;
}
với phép cộng : tạo operator +
(/*complex:
if outline)*/)complex operator+(complex b)
{
complex c;
c.real=real+b.real;c.image=image+b.image;
return c;
}
với phép -= : tạo operator -=
complex &operator-=(complex b)
{
real-=b.real;
image-=b.image;
return this;
}
int &operator==(complex b)
{
return (real==b.real&&image==b.image);
}
// ham xuat
ostream &operator<<(ostream o, phanso b)
{
cout<<real<<"+"<<(image>0?' ':'-')<<"*"<<asp(image);
}
các cái khác làm tương tự.
lâu rùi không viết có thể có vài lỗi nhỏ, chủ yêu cung cấp cho bạn phương pháp toán tử của c++ !
welcome uitstudent.com/forum
Bookmarks