fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class tg{
  4. int gio,phut,giay;
  5. public:
  6. tg(){
  7. gio=phut=giay=0;
  8. }
  9. tg(int g,int p,int s){
  10. gio=g;
  11. phut=p;
  12. giay=s;
  13. }
  14. int operator~(){
  15. return (gio*60*60+phut*60+giay);
  16. }
  17. friend istream&operator>>(istream&x,tg &y);
  18. friend ostream&operator<<(ostream&x,tg y);
  19. };
  20. istream&operator>>(istream&x,tg &y){
  21. cout<<"gio:"; x>>y.gio;
  22. cout<<"phut: " ; x>>y.phut;
  23. cout<<"giay: "; x>>y.giay;
  24. return x;
  25. }
  26. ostream&operator<<(ostream&x,tg y){
  27. x<<y.gio<<" gio "<<y.phut<<" phut "<<y.giay<<" giay "<<endl;
  28. return x;
  29. }
  30. int main(){
  31. tg t1(4,2,5);
  32. cout<<"thong tin cua t1:"<<endl;
  33. cout<<t1<<endl;
  34. tg t2;
  35. cout<<"nhap thong tin cho t2: "<<endl;
  36. cin>>t2;
  37. int chenhlech=abs(~t1-~t2);
  38. ofstream f("tg.txt");
  39. cout<<"thong tin moc tgian 1 :"<<t1<<endl;
  40. f<<"thong tin moc tgian 1 :"<<t1<<endl;
  41. cout<<"thong tin moc tgian 2 :"<<t2<<endl;
  42. f<<"thong tin moc tgian 2 :"<<t2<<endl;
  43. cout<<"so giay chenh lech: "<<chenhlech<<endl;
  44. f<<"so giay chenh lech: "<<chenhlech<<endl;
  45. f.close();
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
thong tin cua t1:
4 gio 2 phut 5 giay 

nhap thong tin cho t2: 
gio:phut: giay: thong tin moc tgian 1 :4 gio 2 phut 5 giay 

thong tin moc tgian 2 :0 gio 0 phut 0 giay 

so giay chenh lech: 14525