fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Ttb2{
  4. float a,b,c;
  5. public:
  6. Ttb2 (){
  7. a=b=c=0;
  8. }
  9. Ttb2(float x,float y,float z){
  10. a=x;
  11. b=y;
  12. c=z;
  13. }
  14. Ttb2 operator+(Ttb2 y);
  15. Ttb2 operator-(Ttb2 y);
  16. Ttb2 operator*();
  17. friend ostream&operator<<(ostream&x,Ttb2 y);
  18. };
  19. Ttb2 Ttb2::operator+(Ttb2 y){
  20. Ttb2 n;
  21. n.a=a+y.a;
  22. n.b=b+y.b;
  23. n.c=c+y.c;
  24. return n;
  25. }
  26. Ttb2 Ttb2::operator-(Ttb2 y){
  27. Ttb2 n;
  28. n.a=a-y.a;
  29. n.b=b-y.b;
  30. n.c=c-y.c;
  31. return n;
  32. }
  33. Ttb2 Ttb2::operator*(){
  34. Ttb2 n;
  35. n.a=-a;
  36. n.b=-b;
  37. n.c=-c;
  38. return n;
  39. }
  40. ostream&operator<<(ostream&x,Ttb2 y){
  41. x<<y.a<<"X"<<char(253);
  42. if(y.b>0)
  43. x<<"+"<<y.b<<"X";
  44. else
  45. x<<"-"<<-y.b<<"X";
  46. if(y.c>0)
  47. x<<"+"<<y.c<<endl;
  48. else
  49. x<<"-"<<-y.c<<endl;
  50. return x;
  51. }
  52. int main(){
  53. Ttb2 a(2,4,6);
  54. Ttb2 b(2,3,2);
  55. a=*a;
  56. b=*b;
  57. Ttb2 c=a+b;
  58. Ttb2 d=a-b;
  59. cout<<"TT t1 khi da doi dau la: "<<a<<endl;
  60. cout<<"TT t2 khi da doi dau la: "<<b<<endl;
  61. cout<<"Tong 2 TT la: "<<c<<endl;
  62. cout<<"Hieu 2 TT la: "<<d<<endl;
  63. ofstream f("ttb2.txt");
  64. f<<"TT t1 khi da doi dau la: "<<a<<endl;
  65. f<<"TT t2 khi da doi dau la: "<<b<<endl;
  66. f<<"Tong 2 TT la: "<<c<<endl;
  67. f<<"Hieu 2 TT la: "<<d<<endl;
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
TT t1 khi da doi dau la: -2X�-4X-6

TT t2 khi da doi dau la: -2X�-3X-2

Tong 2 TT la: -4X�-7X-8

Hieu 2 TT la: 0X�-1X-4