fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class MAY{
  4. float Trongluong,Giatien;
  5. public:
  6. MAY operator+(MAY y);
  7. MAY(){
  8. Trongluong=Giatien=0;
  9. }
  10. MAY(float a,float b){
  11. Trongluong=a;
  12. Giatien=b;
  13. }
  14. friend istream&operator>>(istream&x ,MAY&y);
  15. friend ostream&operator<<(ostream&x,MAY y);
  16. bool operator==(MAY y);
  17. };
  18. istream&operator>>(istream&x,MAY&y){
  19. cout<<"Nhap trong luong: "; x>>y.Trongluong;
  20. cout<<"Nhap gia tien: "; x>>y.Giatien;
  21. return x;
  22. }
  23. ostream&operator<<(ostream&x,MAY y){
  24. x<<"Trong luong :"<<y.Trongluong<<endl;
  25. x<<"Gia tien: "<<y.Giatien<<endl;
  26. return x;
  27. }
  28. MAY MAY::operator+(MAY y){
  29. MAY m;
  30. m.Trongluong =Trongluong+y.Trongluong;
  31. m.Giatien=Giatien+y.Giatien;
  32. return m;
  33. }
  34. bool MAY:: operator==(MAY y){
  35. if(y.Trongluong==Trongluong&&y.Giatien==Giatien)
  36. return true;
  37. else return false;
  38. }
  39. int main(){
  40. MAY m(2,300);
  41. MAY n;
  42. cout<<"nhap gia tri cua may n:"<<endl;
  43. cin>>n;
  44. ofstream f("may.txt");
  45. cout<<"tong 2 may la: "<<m+n<<endl;
  46. f<<"tong 2 may :"<<m+n<<endl;
  47. if(m==n==true){
  48. cout<<"2 may co cung gia va trong luong!"<<endl;
  49. f<<"2 may co cung gia va trong luong!"<<endl;
  50. }
  51. else{
  52. cout<<"2 may ko cung gia va trong luong"<<endl;
  53. f<<"2 may ko cung gia va trong luong"<<endl;
  54. }
  55. f.close();
  56. return 0;
  57. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
nhap gia tri cua may n:
Nhap trong luong: Nhap gia tien: tong 2 may la: Trong luong :2
Gia tien: 300

2 may ko cung gia va trong luong