fork download
  1. #include <stdio.h>
  2.  
  3. //У
  4. class op1
  5. {
  6. protected:
  7. int a;
  8. double d;
  9. bool b;
  10. public:
  11. op1(int _a=0, double _d=0, bool _b=0) : a(_a), d(_d), b(_b)
  12. {}
  13.  
  14. op1 operator+(op1 &ob)
  15. {
  16. a = a + ob.a;
  17. d = d + ob.d;
  18. b = (b || ob.b);
  19. return *this;
  20. }
  21.  
  22. op1 operator-(op1 &ob)
  23. {
  24. a = a - ob.a;
  25. d = d - ob.d;
  26. if (b && !ob.b) { b = true; return *this;}
  27. if (b && ob.b) { b = false; return *this;}
  28. if (!b && !ob.b) { b = true; return *this;}
  29. if (!b && ob.b) { b = false; return *this;}
  30. return *this;
  31. }
  32.  
  33. void print () { printf ("Vot %d, %f, %d\n", a, d, b);}
  34.  
  35. op1 operator-()
  36. {
  37. a = -a;
  38. d = -d;
  39. if (b) { b = false; return *this;}
  40. if (!b) { b = true; return *this;}
  41. return *this;
  42. }
  43.  
  44. bool operator!= (op1 &ob)
  45. {
  46. return ( (a!=ob.a)||(d!=ob.d)||(b!=ob.b) );
  47. }
  48.  
  49. op1 operator= (const op1 &ob)
  50. {
  51. if (this != &ob)
  52. {
  53. a=ob.a;
  54. d=ob.d;
  55. b=ob.b;
  56. }
  57. return *this;
  58. }
  59.  
  60. op1 vstavF( int _a, double _d, bool _b)
  61. {
  62. a=_a; d=_d; b=_b;
  63. return *this;
  64. }
  65.  
  66.  
  67. };
  68.  
  69. int main ()
  70. {
  71. op1 od (25, 555, true);
  72. od.print();
  73. op1 dwa ( 47.58, false);
  74. dwa.print();
  75. dwa = od - dwa;
  76. dwa.print();
  77. dwa = -dwa;
  78. dwa.print();
  79. op1 tri;
  80. tri = dwa;
  81. bool nu=true;
  82. nu = (tri!=dwa);
  83. printf ("Vot %d\n",nu);
  84. tri.vstavF( 44, 98.5, true);
  85. dwa.print();
  86. tri.print();
  87.  
  88. return 0;
  89. }
Success #stdin #stdout 0s 4312KB
stdin
Standard input is empty
stdout
Vot 25, 555.000000,  1
Vot 47, 0.000000,  0
Vot -22, 555.000000,  1
Vot 22, -555.000000,  0
Vot   0
Vot 22, -555.000000,  0
Vot 44, 98.500000,  1