Advertisement
DominusTempus

OOP Lab #6

May 30th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. class Figure {
  7. protected:
  8.     float x, y, vx, vy, angle, scale;
  9. public:
  10.     Figure() {
  11.         x = 0;
  12.         y = 0;
  13.         vx = 0;
  14.         vy = 0;
  15.         angle = 0;
  16.         scale = 0;
  17.     }
  18.     virtual void create_figure() = 0;
  19.     virtual void show() = 0;
  20.     virtual void delete_figure() = 0;
  21.     virtual void turn() = 0;
  22.     virtual void move() = 0;
  23. };
  24.  
  25. class Circle: public Figure {
  26. public:
  27.     Circle() {};
  28.     ~Circle(){};
  29.     void create_figure();
  30.     void show();
  31.     void delete_figure();
  32.     void turn();
  33.     void move();
  34. };
  35.  
  36. void Circle::show() {
  37.     cout << "Coordinates of center:" << endl;
  38.     cout << "\tx = " << x;
  39.     cout << "\ty = " << y << endl;
  40.  
  41.     cout << "Scale of the circle: " << scale << endl;
  42. }
  43.  
  44. void Circle::create_figure(){
  45.     cout << "Set coordinates of center of the circle:" << endl;
  46.     cout << "x = ";
  47.     cin >> x;
  48.     cout << "y = ";
  49.     cin >> y;
  50.  
  51.     cout << "Set scale of circle: ";
  52.     cin >> scale;
  53.     cout << endl;
  54. }
  55.  
  56. void Circle::delete_figure(){
  57.     cout << "Circle was deleted." << endl;
  58.     x = 0;
  59.     y = 0;
  60.     scale = 0;
  61.     angle = 0;
  62. }
  63.  
  64. void Circle::turn(){
  65.     cout << "Set the angel of rotations of the circle: ";
  66.     cin >> angle;
  67.     cout << "Circle was rotated at " << angle << " degrees\n";
  68. }
  69.  
  70. void Circle::move(){
  71.     cout << "Set coordinates of vector to move the circle:" << endl;
  72.     cout << "x = ";
  73.     cin >> vx;
  74.     cout << "y = ";
  75.     cin >> vy;
  76.     x += vx;
  77.     y += vy;
  78.  
  79.     cout << "New coordinates of center of the circle: x = " << x << "; y = " << y << endl;
  80. }
  81.  
  82.  
  83. int main() {
  84.     Figure *f;
  85.     Circle obj1;
  86.  
  87.     f = &obj1;
  88.     f->create_figure();
  89.     f->show();
  90.     f->turn();
  91.     f->move();
  92.     f->delete_figure();
  93.  
  94.     _getch();
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement