Advertisement
SeriousVenom

ClassPoint

Jan 24th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #define PI 3.14159265
  4.  
  5. using namespace std;
  6.  
  7. class Point {
  8. protected:
  9.     double x, y; //координаты треугольника
  10. public:
  11.     Point(double a = 0, double b = 0); //конструктор по умолчанию
  12.     Point(const Point&); //конструктор копирования
  13.     void Show(); //Показ координат
  14.     void Move(double xs, double ys); //Смещение координат
  15. };
  16.  
  17.  
  18.  
  19. Point::Point(double a, double b) {
  20.     x = a;
  21.     y = b;
  22. }
  23.  
  24. Point::Point(const Point& other) {
  25.     x = other.x;
  26.     y = other.y;
  27. }
  28.  
  29. void Point::Show() {
  30.     cout << "x = " << x << endl << "y = " << y << endl;
  31. }
  32.  
  33. void Point::Move(double xs, double ys) {
  34.     cout << "The point is shifted by (" << xs << ", " << ys << ")" << endl;
  35.     x += xs;
  36.     y += ys;
  37. }
  38.  
  39.  
  40. class Triangle : public Point {
  41.     int R; //радиус
  42.     int Phi; //угол
  43. public:
  44.     Triangle(double az = 0, double yz = 0, double Rz = 0, double Phiz = 0) : Point(az, yz), R(Rz), Phi(Phiz) {
  45.  
  46.     }
  47.     void Input(); //ввод радиуса
  48.     void Turn(int); //поворот фигуры на n градусов
  49.     void Show(); //показ координат
  50. };
  51.  
  52. void Triangle::Input() {
  53.     cin >> R;
  54. }
  55.  
  56. void Triangle::Turn(int alpha) {
  57.     Phi += alpha;
  58. }
  59.  
  60. void Triangle::Show() {
  61.     int k = 3; //колличество углов, 3 - т.к. треугольник
  62.  
  63.     for (int i = 0; i < k; i++) {
  64.         x += R * cos(Phi * PI / 180); y += R * sin(Phi * PI / 180);
  65.         Phi += 120;
  66.         cout << "x" << i << ": " << int(x * 100 + 0.5) / 100.0 << "\t\t" << "y" << i << ": " << int(y * 100 + 0.5) / 100.0 << endl;
  67.     }
  68.  
  69. }
  70.  
  71. int main() {
  72.     Triangle colt(0,0,3,0);
  73.     int alpha;
  74.  
  75.     cout << "Enter radius: ";
  76.     colt.Input();
  77.     colt.Show();
  78.     cout << "Enter how many degrees you want to rotate the triangle: " << endl;  cin >> alpha;
  79.     colt.Turn(alpha);
  80.     colt.Show();
  81.  
  82.     int x1, y1;
  83.     cout << "Enter how many coordinates you want to shift the triangle" << endl << "X: "; cin >> x1; cout << "Y: "; cin >> y1;
  84.     colt.Move(x1, y1);
  85.     colt.Show();
  86.     //Triangle colt1(0, 0, 3, 0);
  87.     //colt1.Show();
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement