fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::cout;
  5. using std::endl;
  6.  
  7. class A {
  8. public:
  9. A(int x) : x_(x) {}
  10.  
  11. int y() const { return y_; }
  12.  
  13. void set_z(int z) { z_ = z; }
  14.  
  15. void show() const {
  16. cout << "x = " << x_ << " y = " << y_ << " z = " << z_ << endl;
  17. }
  18.  
  19. void calculation() {
  20. y_ = x_ + z_;
  21. x_ += z_;
  22. }
  23.  
  24. private:
  25. int x_ = 0;
  26. int y_ = 0;
  27. int z_ = 0;
  28. };
  29.  
  30. void ShowSeparator() { cout << "*************************" << endl; }
  31.  
  32. int main() {
  33. A a(28);
  34. A b(34);
  35. a.calculation();
  36. b.calculation();
  37. a.show();
  38. b.show();
  39. //передача информации от А к В
  40. b.set_z(a.y());
  41. //передача информации от B к A
  42. a.set_z(b.y());
  43. ShowSeparator();
  44. a.show();
  45. b.show();
  46. }
  47.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
x = 28 y = 28 z = 0
x = 34 y = 34 z = 0
*************************
x = 28 y = 28 z = 34
x = 34 y = 34 z = 28