Advertisement
JouJoy

Klassy

Dec 27th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. class Dot
  6. {
  7. private:
  8. double x;
  9. double y;
  10.  
  11. public:
  12.  
  13. void set_x(double x) {
  14. this->x = x;
  15. }
  16. void set_y(double y) {
  17. this->y = y;
  18. }
  19.  
  20. double get_x() {
  21. return this->x;
  22. }
  23. double get_y() {
  24. return this->y;
  25. }
  26.  
  27. Dot(double x, double y) {
  28. this->x = x;
  29. this->y=y;
  30. }
  31.  
  32. Dot() {
  33. this->x = 0;
  34. this->y = 0;
  35. }
  36.  
  37. void print() {
  38. cout << "X: " << this->x << "Y: " << this->y << endl;
  39. }
  40.  
  41. void make_dot_input() {
  42. cout << "Enter X: ";
  43. cin >> this->x;
  44. cout << "Enter Y: ";
  45. cin >> this->y;
  46. cout << endl;
  47. }
  48.  
  49. double how_far(Dot A, Dot B) {
  50. double k = (pow((B.get_x() - A.get_x()), 2) + pow((B.get_y() - A.get_y()), 2));
  51. return sqrt(k);
  52. }
  53.  
  54. };
  55.  
  56. class Cilindr {
  57. protected:
  58. Dot centre;
  59. Dot dot_in_circle;
  60. double height;
  61.  
  62. public:
  63. void set_centre(Dot A) {
  64. this->centre = Dot(A.get_x(), A.get_y());
  65. }
  66. void set_dot_in_circle(Dot A) {
  67. this->dot_in_circle = Dot(A.get_x(), A.get_y());
  68. }
  69. void set_height(double h) {
  70. this->height = h;
  71. }
  72. Dot get_centre() {
  73. return this->centre;
  74. }
  75. Dot get_dot_in_cirle() {
  76. return this->dot_in_circle;
  77. }
  78. double get_height() {
  79. return this->height;
  80. }
  81.  
  82. Cilindr() {
  83. this->centre = Dot();
  84. this->dot_in_circle = Dot();
  85. this->height = 1;
  86. }
  87. Cilindr(Dot centre, Dot dot_in_circle, double h) {
  88. this->centre = centre;
  89. this->dot_in_circle = dot_in_circle;
  90. this->height = h;
  91. }
  92.  
  93. void print() {
  94. cout << "Cilindr" << endl;
  95. centre.print();
  96. dot_in_circle.print();
  97. cout << "Height: " << this->height << endl;
  98. }
  99.  
  100. void make_cilindr_input() {
  101. cout << "Enter height of new cilindr: ";
  102. cin >> this->height;
  103. centre.make_dot_input();
  104. dot_in_circle.make_dot_input();
  105. cout << endl;
  106. }
  107.  
  108.  
  109. double square_osnovaniya() {
  110. return pow(Dot().how_far(centre, dot_in_circle), 2) * 3.14;
  111. }
  112.  
  113. double volume() {
  114. return this->square_osnovaniya() * this->height;
  115. }
  116.  
  117. double square_bok_pov() {
  118. return 2 * 3.14 * Dot().how_far(centre, dot_in_circle) * height;
  119. }
  120.  
  121. double len_circle() {
  122. return 2 * 3.14 * Dot().how_far(centre, dot_in_circle);
  123. }
  124. };
  125.  
  126. int main()
  127. {
  128. Cilindr A = Cilindr(Dot(0, 0), Dot(0, 1), 3);
  129. A.print();
  130. cout << " SQUARE OSN | Volume | Bok pov | Len " << endl;
  131. cout <<" " << A.square_osnovaniya() << " " << A.volume() << " " << A.square_bok_pov() << " " << A.len_circle() << endl;
  132. A.make_cilindr_input();
  133. A.print();
  134. cout << " SQUARE OSN | Volume | Bok pov | Len " << endl;
  135. cout << " " << A.square_osnovaniya() << " " << A.volume() << " " << A.square_bok_pov() << " " << A.len_circle() << endl;
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement