Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #define PI 3.14159265
- using namespace std;
- class Point {
- protected:
- double x, y; //координаты треугольника
- public:
- Point(double a = 0, double b = 0); //конструктор по умолчанию
- Point(const Point&); //конструктор копирования
- void Show(); //Показ координат
- void Move(double xs, double ys); //Смещение координат
- };
- Point::Point(double a, double b) {
- x = a;
- y = b;
- }
- Point::Point(const Point& other) {
- x = other.x;
- y = other.y;
- }
- void Point::Show() {
- cout << "x = " << x << endl << "y = " << y << endl;
- }
- void Point::Move(double xs, double ys) {
- cout << "The point is shifted by (" << xs << ", " << ys << ")" << endl;
- x += xs;
- y += ys;
- }
- class Triangle : public Point {
- int R; //радиус
- int Phi; //угол
- public:
- Triangle(double az = 0, double yz = 0, double Rz = 0, double Phiz = 0) : Point(az, yz), R(Rz), Phi(Phiz) {
- }
- void Input(); //ввод радиуса
- void Turn(int); //поворот фигуры на n градусов
- void Show(); //показ координат
- };
- void Triangle::Input() {
- cin >> R;
- }
- void Triangle::Turn(int alpha) {
- Phi += alpha;
- }
- void Triangle::Show() {
- int k = 3; //колличество углов, 3 - т.к. треугольник
- for (int i = 0; i < k; i++) {
- x += R * cos(Phi * PI / 180); y += R * sin(Phi * PI / 180);
- Phi += 120;
- cout << "x" << i << ": " << int(x * 100 + 0.5) / 100.0 << "\t\t" << "y" << i << ": " << int(y * 100 + 0.5) / 100.0 << endl;
- }
- }
- int main() {
- Triangle colt(0,0,3,0);
- int alpha;
- cout << "Enter radius: ";
- colt.Input();
- colt.Show();
- cout << "Enter how many degrees you want to rotate the triangle: " << endl; cin >> alpha;
- colt.Turn(alpha);
- colt.Show();
- int x1, y1;
- cout << "Enter how many coordinates you want to shift the triangle" << endl << "X: "; cin >> x1; cout << "Y: "; cin >> y1;
- colt.Move(x1, y1);
- colt.Show();
- //Triangle colt1(0, 0, 3, 0);
- //colt1.Show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement