Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct Point
  5. {
  6.     int x;
  7.     int y;
  8.  
  9.     void print()
  10.     { // Point* const this
  11.         cout<<"("<< (*this).x <<";"<<y<<")";
  12.     }
  13. };
  14.  
  15. struct Circle
  16. {
  17.     double r;
  18.     Point p;
  19.  
  20.     void print() {
  21.         cout << r << " ";
  22.         p.print();
  23.         cout << endl;
  24.     }
  25. };
  26.  
  27. struct Rectangle
  28. {
  29.     double width;
  30.     double height;
  31.     Point p; //top left
  32.  
  33.     void print()
  34.     {
  35.         cout<<width<<" "
  36.             <<height<<" ";
  37.         p.print();
  38.         cout<<endl;
  39.     }
  40. };
  41.  
  42. struct Window
  43. {
  44.    
  45.     Circle* circles;
  46.     Rectangle* rectangles;
  47.  
  48.     void print(){
  49.         // for(Circle & c: circles) {
  50.         //     c.print();
  51.         // }
  52.         // for(Rectangle & r: rectangles) {
  53.         //     r.print();
  54.         // }
  55.     }
  56. };
  57.  
  58. int f() { return 0; }
  59.  
  60. struct DynamicArray {
  61.     Circle* circles;
  62.     DynamicArray(unsigned n) {
  63.         circles = new Circle[n];
  64.     }
  65.    
  66.     ~DynamicArray(){
  67.         delete[] circles;
  68.     }
  69. };
  70.  
  71. int main()
  72. {
  73.     Point p{5,10};
  74.     Rectangle r{3,4,p};
  75.     Circle c{6,p}; //{6,{5,10}}
  76.  
  77.     p.print();
  78.     c.print();
  79.  
  80.     unsigned n;
  81.     cin >> n;
  82.    
  83.     DynamicArray circlespPP{n};
  84.    
  85.     Rectangle* rectangles = new Rectangle[n];
  86.  
  87.     // Window w1{circles, rectangles};
  88.     // Window w2{circles, rectangles};
  89.     // w1.print();
  90.     // cout << endl;
  91.     // w2.print();    
  92.     return 0;
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement