Guest User

Untitled

a guest
Apr 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <conio.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. class Base
  6. {
  7. float x, y;
  8. public:
  9. Base (float _x = 0, float _y = 0)
  10. {
  11. x = _x;
  12. y = _y;
  13. }
  14. float getX()
  15. {
  16. return x;
  17. }
  18. float getY()
  19. {
  20. return y;
  21. }
  22. void setX (float _x)
  23. {
  24. x = _x;
  25. }
  26. void setY (float _y)
  27. {
  28. y = _y;
  29. }
  30. void print ()
  31. {
  32. printf ("\nKoordinaty tochki %.2f, %.2f\n", x, y);
  33. }
  34. void set ()
  35. {
  36. printf ("\nVvedite koordinaty\n");
  37. scanf ("%f%f", &x, &y);
  38. }
  39. void shift (float _x, float _y)
  40. {
  41. x += _x;
  42. y += _y;
  43. }
  44. };
  45.  
  46. class Circle: public Base
  47. {
  48. float radius;
  49. public:
  50. Circle(float _radius = 0, float _x = 0, float _y = 0):Base(_x, _y)
  51. {
  52. radius = _radius;
  53. }
  54. void print()
  55. {
  56. Base::print();
  57. printf ("\nradius %.2f\n", radius);
  58. }
  59. void set ()
  60. {
  61. Base::set();
  62. printf ("\nVvedite radius\n");
  63. scanf ("%f",&radius);
  64. }
  65. float s()
  66. {
  67. return 3.14*radius*radius;
  68. }
  69. };
  70.  
  71. class Pryamougolnik:protected Base
  72. {
  73. float a, b;
  74. public:
  75. Pryamougolnik(float _a = 0, float _b = 0, float _x = 0, float _y = 0):Base(_x, _y)
  76. {
  77. a = _a;
  78. b = _b;
  79. }
  80. void print()
  81. {
  82. Base::print();
  83. printf("\ndlina = %.2f, shirina = %.2f\n", a, b);
  84. }
  85. void set()
  86. {
  87. Base::set();
  88. printf("\nvvedite razmeri\n");
  89. scanf("%f%f", &a, &b);
  90. }
  91. void koordinaty ()
  92. {
  93. printf ("\nkoordinaty levoy nizhney vershiny %.2f, %.2f\n", getX(), getY());
  94. printf ("\nkoordinaty levoy verhney vershiny %.2f, %.2f\n", getX(), getY()+b);
  95. printf ("\nkoordinaty pravoy nizhney vershiny %.2f, %.2f\n", getX()+a, getY());
  96. printf ("\nkoordinaty pravoy verhney vershiny %.2f, %.2f\n", getX()+a, getY()+b);
  97. }
  98. };
  99.  
  100. class Triangle:private Base
  101. {
  102. float x1, y1, x2, y2;
  103. public:
  104. Triangle (float _x1 = 0, float _y1 = 0, float _x2 = 0, float _y2 = 0, float _x = 0, float _y = 0):Base(_x, _y)
  105. {
  106. x1 = _x1;
  107. x2 = _x2;
  108. y1 = _y1;
  109. y2 = _y2;
  110. }
  111. void print()
  112. {
  113. printf("\nkoordinaty tochek: x1(%.2f, %.2f), x2(%.2f, %.2f), x3(%.2f, %.2f)\n", getX(), getY(), getX() + x1, getY() + y1, getX() + x2, getY() + y2);
  114. }
  115. void set()
  116. {
  117. Base::set();
  118. printf ("\nVvedite koordinaty vektorov\n");
  119. scanf ("%f %f %f %f", &x1, &y1, &x2, &y2);
  120. }
  121.  
  122. float *dlina()
  123. {
  124. float *mas = new float[3];
  125. mas[0] = sqrt(x1 * x1 + y1 * y1);
  126. mas[1] = sqrt(x2 * x2 + y2 * y2);
  127. float _x1 = getX() + x1, _y1 = getY() + y1, _x2 = getX() + x2, _y2 = getY() + y2;
  128. mas[2] = sqrt((_x1 - _x2) * (_x1 - _x2) + (_y1 - _y2) * (_y1 - _y2));
  129. return mas;
  130. }
  131. };
  132.  
  133. void main ()
  134. {
  135. Base a;
  136. a.set();
  137. a.print();
  138.  
  139. Circle b;
  140. b.set();
  141. b.print();
  142. printf ("\nS kruga %.2f\n", b.s());
  143.  
  144. Pryamougolnik c;
  145. c.set();
  146. c.print();
  147. c.koordinaty();
  148.  
  149. Triangle d;
  150. d.set();
  151. d.print();
  152. printf ("\ndliny storon:");
  153. printf ("\n%.2f, %.2f, %.2f\n", d.dlina()[0], d.dlina()[1], d.dlina()[2]);
  154. getch();
  155. }
Add Comment
Please, Sign In to add comment