HaDuyAnh Bai2
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
class TIN_HIEU
{
int tancao,tanthap,trungbinh;
public:
TIN_HIEU();
TIN_HIEU operator+(TIN_HIEU);
TIN_HIEU operator-(TIN_HIEU);
friend ostream & operator<<(ostream &os,TIN_HIEU &b);
friend istream & operator>>(istream &is,TIN_HIEU &b);
};
//---------------------
TIN_HIEU::TIN_HIEU()
{
tancao=0;
tanthap=0;
trungbinh=0;
}
//--------------------
ostream & operator<<(ostream &os,TIN_HIEU &b)
{
os<<"Tan cao:"<<b.tancao<<endl<<"Tan thap:"<<b.tanthap<<endl<<"Trung binh: "<<b.trungbinh<<endl;
return os;
}
//----------------------
istream & operator>>(istream & is,TIN_HIEU &b)
{
cout<<"Nhap tan cao:";
is>>b.tancao;
cout<<"Nhap tan thap: ";
is>>b.tanthap;
cout<<"Nhap trung binh: ";
is>>b.trungbinh;
return is;
}
//----------------------
TIN_HIEU TIN_HIEU::operator+(TIN_HIEU p)
{
TIN_HIEU q;
q.tancao=tancao+p.tancao;
q.tanthap=tanthap+p.tanthap;
q.trungbinh=trungbinh+q.trungbinh;
return q;
}
//------------------------
TIN_HIEU TIN_HIEU::operator-(TIN_HIEU p)
{
TIN_HIEU q;
q.tancao=tancao-p.tancao;
q.tanthap=tanthap-p.tanthap;
q.trungbinh=trungbinh-p.trungbinh;
return q;
}
//------------------------
void main()
{
clrscr();
TIN_HIEU a,b;
cout<<"Nhap TIN_HIEU a: "<<endl;
cin>>a;
cout<<"Nhap TIN_HIEU b: "<<endl;
cin>>b;
cout<<"Tong la "<<endl<<a+b;
cout<<"----------------"<<endl;
cout<<"Hieu la "<<endl<<a-b;
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top