Petro_zzz

lesson_1010

Oct 10th, 2022
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct Point;
  5.  
  6. struct Point {
  7.     int x;
  8.     int y;
  9.  
  10.     void construct(int x1, int y1) {
  11.         x = x1;
  12.         y = y1;
  13.     }
  14.  
  15.     void show_in() {
  16.         cout << "(" << x << ", " << y << ")" << endl;
  17.     }
  18.  
  19.     double dist_in(const Point& pt2) {
  20.         int dx = pt2.x - x;
  21.         int dy = pt2.y - y;
  22.         double res = dx * dx + dy * dy;
  23.         return sqrt(res);
  24.     }
  25. };
  26.  
  27. struct Line {
  28.     Point pt1;
  29.     Point pt2;
  30.  
  31.     void show() {
  32.         /*pt1.show_in();
  33.         pt2.show_in();*/
  34.         cout << "line{" << pt1.x << ", " << pt1.y << ", "
  35.             << pt2.x << ", " << pt2.y << "}" << endl;
  36.     }
  37. };
  38.  
  39. struct ZigZag {
  40.     Point pnts[10];
  41.  
  42.     void show() {
  43.         for (int k = 0; k < 10; k++) {
  44.             cout << pnts[k].x << ", " << pnts[k].y << "| ";
  45.         }
  46.         cout << endl;
  47.     }
  48. };
  49.  
  50. void show(const Point& pt) {
  51.     cout << "(" << pt.x << ", "
  52.         << pt.y << ")" << endl;
  53. }
  54.  
  55. double dist(const Point& pt1, const Point& pt2) {
  56.     int dx = pt2.x - pt1.x;
  57.     int dy = pt2.y - pt1.y;
  58.     double res = dx * dx + dy * dy;
  59.     return sqrt(res);
  60. }
  61.  
  62. void show(Point pnts[], int size) {
  63.     for (int k = 0; k < size; k++) {
  64.         show(pnts[k]);
  65.     }
  66. }
  67.  
  68. struct Man {
  69.     string name;
  70.     int cash;
  71. };
  72.  
  73. int num_names = 7;
  74. const string names[]{"Ivan", "Artem", "Anna", "Oleg", "Sema", "Lena", "Igor"};
  75.  
  76. struct Bus {
  77.     Man pasangers[10];
  78.  
  79.     void construct() {
  80.         /*
  81.         pasangers[0].name = new char[] {"Artem Igorevich Sebastiyanov"};
  82.         pasangers[1].name = new char[] {"P2"};
  83.         pasangers[2].name = new char[] {"P3"};
  84.         pasangers[3].name = new char[] {"P4"};
  85.         pasangers[4].name = new char[] {"P5"};
  86.         pasangers[5].name = new char[] {"P6"};
  87.         pasangers[6].name = new char[] {"P7"};
  88.         pasangers[7].name = new char[] {"P8"};
  89.         pasangers[8].name = new char[] {"P9"};
  90.         pasangers[9].name = new char[] {"P10"};
  91.     */
  92.  
  93.         for (int k = 0; k < 10; k++) {                     
  94.             pasangers[k].name = names[rand() % num_names];
  95.             pasangers[k].cash = 32;
  96.         }
  97.  
  98.         pasangers[2].cash = 16;
  99.         pasangers[7].cash = 16;
  100.     }
  101.  
  102.     void show() {
  103.         for (int k = 0; k < 10; k++) {
  104.             cout << pasangers[k].name << " "
  105.                  << pasangers[k].cash << " rub." << endl;
  106.         }
  107.     }
  108.  
  109.     void destruct() {/*
  110.         for (int k = 0; k < 10; k++) {
  111.             delete[] pasangers[k].name;
  112.         }
  113.         */
  114.     }
  115. };
  116.  
  117.  
  118. void test_Point() {
  119.     Point pt1{ 12, -5 };
  120.     Point pt2;
  121.  
  122.     pt2.x = 45;
  123.     pt2.y = 12;
  124.  
  125.     Point pnts[]{ pt1, pt2 };
  126.  
  127.     show(pt1);
  128.     show(pt2);
  129.  
  130.     cout << "dist: "
  131.         << dist(pt1, pt2) << endl;
  132.  
  133.     pnts[1].x = 15;
  134.     show(pnts, 2);
  135.     cout << "-----------------" << endl;
  136.     pt1.show_in();
  137.     cout << "dist: " << pt1.dist_in(pt2) << endl;
  138. }
  139.  
  140.  
  141. void test_Line() {
  142.     Point pt1{ 12, -5 };
  143.     Point pt2;
  144.     pt2.x = 45;
  145.     pt2.y = 12;
  146.  
  147.     Line line{ pt1, pt2 };
  148.     line.show();
  149.  
  150.     line.pt1.x += 10;
  151.     line.pt2.x -= 10;
  152.     line.show();
  153. }
  154.  
  155. void test_ZigZag() {
  156.     ZigZag point_array;
  157.     for (int k = 0; k < 10; k++) {
  158.         point_array.pnts[k].x = k;
  159.         point_array.pnts[k].y = 10 - k;
  160.     }
  161.     point_array.show();
  162. }
  163.  
  164. void main(){
  165.     Bus bus65;
  166.     bus65.construct();
  167.     bus65.show();
  168.     bus65.destruct();
  169. }
Advertisement
Add Comment
Please, Sign In to add comment