Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <math.h>
- #include <stdio.h>
- class Base
- {
- float x, y;
- public:
- Base (float _x = 0, float _y = 0)
- {
- x = _x;
- y = _y;
- }
- float getX()
- {
- return x;
- }
- float getY()
- {
- return y;
- }
- void setX (float _x)
- {
- x = _x;
- }
- void setY (float _y)
- {
- y = _y;
- }
- void print ()
- {
- printf ("\nKoordinaty tochki %.2f, %.2f\n", x, y);
- }
- void set ()
- {
- printf ("\nVvedite koordinaty\n");
- scanf ("%f%f", &x, &y);
- }
- void shift (float _x, float _y)
- {
- x += _x;
- y += _y;
- }
- };
- class Circle: public Base
- {
- float radius;
- public:
- Circle(float _radius = 0, float _x = 0, float _y = 0):Base(_x, _y)
- {
- radius = _radius;
- }
- void print()
- {
- Base::print();
- printf ("\nradius %.2f\n", radius);
- }
- void set ()
- {
- Base::set();
- printf ("\nVvedite radius\n");
- scanf ("%f",&radius);
- }
- float s()
- {
- return 3.14*radius*radius;
- }
- };
- class Pryamougolnik:protected Base
- {
- float a, b;
- public:
- Pryamougolnik(float _a = 0, float _b = 0, float _x = 0, float _y = 0):Base(_x, _y)
- {
- a = _a;
- b = _b;
- }
- void print()
- {
- Base::print();
- printf("\ndlina = %.2f, shirina = %.2f\n", a, b);
- }
- void set()
- {
- Base::set();
- printf("\nvvedite razmeri\n");
- scanf("%f%f", &a, &b);
- }
- void koordinaty ()
- {
- printf ("\nkoordinaty levoy nizhney vershiny %.2f, %.2f\n", getX(), getY());
- printf ("\nkoordinaty levoy verhney vershiny %.2f, %.2f\n", getX(), getY()+b);
- printf ("\nkoordinaty pravoy nizhney vershiny %.2f, %.2f\n", getX()+a, getY());
- printf ("\nkoordinaty pravoy verhney vershiny %.2f, %.2f\n", getX()+a, getY()+b);
- }
- };
- class Triangle:private Base
- {
- float x1, y1, x2, y2;
- public:
- Triangle (float _x1 = 0, float _y1 = 0, float _x2 = 0, float _y2 = 0, float _x = 0, float _y = 0):Base(_x, _y)
- {
- x1 = _x1;
- x2 = _x2;
- y1 = _y1;
- y2 = _y2;
- }
- void print()
- {
- printf("\nkoordinaty tochek: x1(%.2f, %.2f), x2(%.2f, %.2f), x3(%.2f, %.2f)\n", getX(), getY(), getX() + x1, getY() + y1, getX() + x2, getY() + y2);
- }
- void set()
- {
- Base::set();
- printf ("\nVvedite koordinaty vektorov\n");
- scanf ("%f %f %f %f", &x1, &y1, &x2, &y2);
- }
- float *dlina()
- {
- float *mas = new float[3];
- mas[0] = sqrt(x1 * x1 + y1 * y1);
- mas[1] = sqrt(x2 * x2 + y2 * y2);
- float _x1 = getX() + x1, _y1 = getY() + y1, _x2 = getX() + x2, _y2 = getY() + y2;
- mas[2] = sqrt((_x1 - _x2) * (_x1 - _x2) + (_y1 - _y2) * (_y1 - _y2));
- return mas;
- }
- };
- void main ()
- {
- Base a;
- a.set();
- a.print();
- Circle b;
- b.set();
- b.print();
- printf ("\nS kruga %.2f\n", b.s());
- Pryamougolnik c;
- c.set();
- c.print();
- c.koordinaty();
- Triangle d;
- d.set();
- d.print();
- printf ("\ndliny storon:");
- printf ("\n%.2f, %.2f, %.2f\n", d.dlina()[0], d.dlina()[1], d.dlina()[2]);
- getch();
- }
Add Comment
Please, Sign In to add comment