Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Point;
- struct Point {
- int x;
- int y;
- void construct(int x1, int y1) {
- x = x1;
- y = y1;
- }
- void show_in() {
- cout << "(" << x << ", " << y << ")" << endl;
- }
- double dist_in(const Point& pt2) {
- int dx = pt2.x - x;
- int dy = pt2.y - y;
- double res = dx * dx + dy * dy;
- return sqrt(res);
- }
- };
- struct Line {
- Point pt1;
- Point pt2;
- void show() {
- /*pt1.show_in();
- pt2.show_in();*/
- cout << "line{" << pt1.x << ", " << pt1.y << ", "
- << pt2.x << ", " << pt2.y << "}" << endl;
- }
- };
- struct ZigZag {
- Point pnts[10];
- void show() {
- for (int k = 0; k < 10; k++) {
- cout << pnts[k].x << ", " << pnts[k].y << "| ";
- }
- cout << endl;
- }
- };
- void show(const Point& pt) {
- cout << "(" << pt.x << ", "
- << pt.y << ")" << endl;
- }
- double dist(const Point& pt1, const Point& pt2) {
- int dx = pt2.x - pt1.x;
- int dy = pt2.y - pt1.y;
- double res = dx * dx + dy * dy;
- return sqrt(res);
- }
- void show(Point pnts[], int size) {
- for (int k = 0; k < size; k++) {
- show(pnts[k]);
- }
- }
- struct Man {
- string name;
- int cash;
- };
- int num_names = 7;
- const string names[]{"Ivan", "Artem", "Anna", "Oleg", "Sema", "Lena", "Igor"};
- struct Bus {
- Man pasangers[10];
- void construct() {
- /*
- pasangers[0].name = new char[] {"Artem Igorevich Sebastiyanov"};
- pasangers[1].name = new char[] {"P2"};
- pasangers[2].name = new char[] {"P3"};
- pasangers[3].name = new char[] {"P4"};
- pasangers[4].name = new char[] {"P5"};
- pasangers[5].name = new char[] {"P6"};
- pasangers[6].name = new char[] {"P7"};
- pasangers[7].name = new char[] {"P8"};
- pasangers[8].name = new char[] {"P9"};
- pasangers[9].name = new char[] {"P10"};
- */
- for (int k = 0; k < 10; k++) {
- pasangers[k].name = names[rand() % num_names];
- pasangers[k].cash = 32;
- }
- pasangers[2].cash = 16;
- pasangers[7].cash = 16;
- }
- void show() {
- for (int k = 0; k < 10; k++) {
- cout << pasangers[k].name << " "
- << pasangers[k].cash << " rub." << endl;
- }
- }
- void destruct() {/*
- for (int k = 0; k < 10; k++) {
- delete[] pasangers[k].name;
- }
- */
- }
- };
- void test_Point() {
- Point pt1{ 12, -5 };
- Point pt2;
- pt2.x = 45;
- pt2.y = 12;
- Point pnts[]{ pt1, pt2 };
- show(pt1);
- show(pt2);
- cout << "dist: "
- << dist(pt1, pt2) << endl;
- pnts[1].x = 15;
- show(pnts, 2);
- cout << "-----------------" << endl;
- pt1.show_in();
- cout << "dist: " << pt1.dist_in(pt2) << endl;
- }
- void test_Line() {
- Point pt1{ 12, -5 };
- Point pt2;
- pt2.x = 45;
- pt2.y = 12;
- Line line{ pt1, pt2 };
- line.show();
- line.pt1.x += 10;
- line.pt2.x -= 10;
- line.show();
- }
- void test_ZigZag() {
- ZigZag point_array;
- for (int k = 0; k < 10; k++) {
- point_array.pnts[k].x = k;
- point_array.pnts[k].y = 10 - k;
- }
- point_array.show();
- }
- void main(){
- Bus bus65;
- bus65.construct();
- bus65.show();
- bus65.destruct();
- }
Advertisement
Add Comment
Please, Sign In to add comment