#include<bits/stdc++.h>
using namespace std;
class MAY{
float Trongluong,Giatien;
public:
MAY operator+(MAY y);
MAY(){
Trongluong=Giatien=0;
}
MAY(float a,float b){
Trongluong=a;
Giatien=b;
}
friend istream&operator>>(istream&x ,MAY&y);
friend ostream&operator<<(ostream&x,MAY y);
bool operator==(MAY y);
};
istream&operator>>(istream&x,MAY&y){
cout<<"Nhap trong luong: "; x>>y.Trongluong;
cout<<"Nhap gia tien: "; x>>y.Giatien;
return x;
}
ostream&operator<<(ostream&x,MAY y){
x<<"Trong luong :"<<y.Trongluong<<endl;
x<<"Gia tien: "<<y.Giatien<<endl;
return x;
}
MAY MAY::operator+(MAY y){
MAY m;
m.Trongluong =Trongluong+y.Trongluong;
m.Giatien=Giatien+y.Giatien;
return m;
}
bool MAY:: operator==(MAY y){
if(y.Trongluong==Trongluong&&y.Giatien==Giatien)
return true;
else return false;
}
int main(){
MAY m(2,300);
MAY n;
cout<<"nhap gia tri cua may n:"<<endl;
cin>>n;
ofstream f("may.txt");
cout<<"tong 2 may la: "<<m+n<<endl;
f<<"tong 2 may :"<<m+n<<endl;
if(m==n==true){
cout<<"2 may co cung gia va trong luong!"<<endl;
f<<"2 may co cung gia va trong luong!"<<endl;
}
else{
cout<<"2 may ko cung gia va trong luong"<<endl;
f<<"2 may ko cung gia va trong luong"<<endl;
}
f.close();
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY2xhc3MgTUFZewoJZmxvYXQgVHJvbmdsdW9uZyxHaWF0aWVuOwoJcHVibGljOgoJCU1BWSBvcGVyYXRvcisoTUFZIHkpOwoJCU1BWSgpewoJCQlUcm9uZ2x1b25nPUdpYXRpZW49MDsKCQl9CgkJTUFZKGZsb2F0IGEsZmxvYXQgYil7CgkJCVRyb25nbHVvbmc9YTsKCQkJR2lhdGllbj1iOwoJCX0KCQlmcmllbmQgaXN0cmVhbSZvcGVyYXRvcj4+KGlzdHJlYW0meCAs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