Advertisement
Guest User

112347

a guest
May 25th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5. class X {
  6. public:
  7. int *x1, *x2;
  8. X(int x1, int x2) {
  9. X::x1 = new int;
  10. X::x2 = new int;
  11. Set(x1, x2);}
  12. ~X() {
  13. delete X::x1;
  14. delete X::x2;}
  15. virtual void Set(int x1, int x2) {
  16. *X::x1 = x1;
  17. *X::x2 = x2;
  18. }};
  19. class Y : public X {
  20. public:
  21. int *y;
  22. Y(int x1, int x2, int y) : X(x1, x2) {
  23. Y::y = new int;
  24. Set(x1, x2, y);}
  25. ~Y() {
  26. delete Y::y;}
  27. virtual void Set(int x1, int x2, int y) {
  28. X::Set(x1, x2);
  29. *Y::y = y;
  30. }
  31. virtual int Run() {
  32. return *X::x1 + (*X::x2 * *Y::y);
  33. }};
  34. int _tmain(int argc, _TCHAR* argv[]){
  35. int x1, x2, y;
  36. cout « "X1: ";
  37. cin » x1;
  38. cout « "X2: ";
  39. cin » x2;
  40. cout « "Y: ";
  41. cin » y;
  42. Y obj(x1, x2, y);
  43. cout « endl « "Otvet = " « obj.Run() « endl;
  44. system("pause");
  45. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement