fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class HH{
  4. float d,r,h;
  5. public:
  6. HH(){
  7. d=r=h;
  8. }
  9. HH(float a,float b,float c){
  10. d=a;
  11. r=b;
  12. h=c;
  13. }
  14. float Thetich(){
  15. return d*r*h;
  16. }
  17. friend istream&operator>>(istream &x,HH& y);
  18. friend ostream&operator<<(ostream &x,HH y);
  19. HH operator+(HH y);
  20. };
  21. istream&operator>>(istream &x,HH& y){
  22. cout<<"Chieu dai: "; x>>y.d;
  23. cout<<"Chieu rong: "; x>>y.r;
  24. cout<<"Chieu cao: "; x>>y.h;
  25. // x<<"The tich: "<<y.Thetich()<<endl;
  26. return x;
  27. }
  28. ostream&operator<<(ostream &x,HH y){
  29. x<<"Chieu dai: "<<y.d<<endl;
  30. x<<"Chieu rong: "<<y.r<<endl;
  31. x<<"Chieu cao: "<<y.h<<endl;
  32. x<<"The tich: "<<y.Thetich()<<endl;
  33. return x;
  34. }
  35. HH HH::operator+(HH y){
  36. HH m;
  37. m.d=d+y.d;
  38. m.r=r+y.r;
  39. m.h=h+y.h;
  40. return m;
  41. }
  42. int main(){
  43. HH h1(2,3,5);
  44. HH h2;
  45. cout<<"Thong tin hh1: "<<endl;
  46. cout<<h1<<endl;
  47. cout<<"Nhap thong tin hh2: "<<endl;
  48. cin>>h2;
  49. ofstream f("hhkthp.txt");
  50. f<<"thong tin hh1: "<<h1<<endl;
  51. f<<"thong tin hh2:"<<h2<<endl;
  52. cout<<"Tong 2 HH la: "<<h1+h2<<endl;
  53. f<<"Tong 2 HH la: "<<h1+h2<<endl;
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Thong tin hh1: 
Chieu dai: 2
Chieu rong: 3
Chieu cao: 5
The tich: 30

Nhap thong tin hh2: 
Chieu dai: Chieu rong: Chieu cao: Tong 2 HH la: Chieu dai: 2
Chieu rong: 3
Chieu cao: 5
The tich: 30