fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class VT{
  4. private:
  5. float a,b,c;
  6. public:
  7. friend istream&operator>>(istream&x,VT &y );
  8. friend ostream&operator<<(ostream&x,VT y);
  9. VT operator+(VT y);
  10. bool operator>( VT y);
  11. };
  12. istream&operator>>(istream&x,VT &y ){
  13. cout<<"nhap a="; x>>y.a;
  14. cout<<"nhap b="; x>>y.b;
  15. cout<<"nhap c="; x>>y.c;
  16. return x;
  17. }
  18. ostream&operator<<(ostream&x,VT y ){
  19. x<<"("<<y.a<<","<<y.b<<","<<y.c<<")"<<endl;
  20. return x;
  21. }
  22. VT VT::operator+(VT y){
  23. VT u;
  24. u.a=a+y.a;
  25. u.b=b+y.b;
  26. u.c=c+y.c;
  27. return u;
  28. }
  29. bool VT::operator>(VT y){
  30. if(a>y.a&&b>y.b&&c>y.c)
  31. return true;
  32. else return false;
  33. }
  34. int main(){
  35. VT u,v;
  36. cout<<"Nhap thong tin Vecto u: "<<endl;
  37. cin>>u;
  38. cout<<"Nhap thong tin Vecto v: "<<endl;
  39. cin>>v;
  40. cout<<"Thong tin vecto u"<<endl;
  41. cout<<u<<endl;
  42. cout<<"Thong tin vecto v"<<endl;
  43. cout<<v<<endl;
  44. VT m=u+v;
  45. cout<<"tong 2 vecto"<<m<<endl;
  46. if(u>v==true){
  47. cout<<"vecto u lon hon vecto v!"<<endl;
  48. }
  49. else{
  50. cout<<"vecto u khong lon hon vecto v!"<<endl;
  51. }
  52. ofstream f("VT.txt");
  53. f<<"Tong 2 vecto"<<m<<endl;
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Nhap thong tin Vecto u: 
nhap a=nhap b=nhap c=Nhap thong tin Vecto v: 
nhap a=nhap b=nhap c=Thong tin vecto u
(0,2.8026e-45,0)

Thong tin vecto v
(0,0,0)

tong 2 vecto(0,2.8026e-45,0)

vecto u khong lon hon vecto v!