Sophuc
#include<conio.h>
#include<iostream.h>
class sophuc
{
public:
int thuc,ao;
public:
void nhap()
{
cout<<"Nhap phan thuc:";cin>>thuc;
cout<<"Nhap phan ao:";cin>>ao;
}
void xuat()
{
cout<<"
"<<thuc;
if(ao>0)
cout<<"+";
cout<<ao<<"i";
}
};
class sophuc1:public sophuc
{
public:
void nhap1()
{
sophuc::nhap();
}
void xuat1()
{
sophuc::xuat();
}
sophuc1 operator +(sophuc1 s)
{
sophuc1 c;
c.thuc=thuc+s.thuc;
c.ao=ao+s.ao;
return c;
}
sophuc1 operator -(sophuc1 s)
{
sophuc1 c;
c.thuc=thuc-s.thuc;
c.ao=ao-s.ao;
return c;
}
sophuc1 operator *(sophuc1 s)
{
sophuc1 c;
c.thuc=thuc*s.thuc-ao*s.ao;
c.ao=thuc*+s.ao+ao*s.thuc;
return c;
}
};
void main()
{
sophuc1 t;
t.nhap1();
sophuc1 l;
l.nhap1();
sophuc1 z;
z=l+t;
cout<<"Tong:";
z.xuat1();
cout<<"
Hieu:";
z=t-l;
z.xuat1();
cout<<"
Tich:";
z=t*l;
z.xuat1();
getch();
}
Bạn đang đọc truyện trên: Truyen4U.Com