Advertisement
frentzy

POO ceva random

May 17th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.10 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Punct {
  6.     float x, y;
  7. public:
  8.     Punct(float x = 0, float y = 0);
  9.     Punct(Punct &ceva);
  10.     void setX(float x);
  11.     float getX();
  12.     void setY(float y);
  13.     float getY();
  14.     friend ostream & operator << (ostream &out, Punct &p);
  15. };
  16.  
  17. Punct::Punct(float x, float y) {
  18.     this->x = x; this->y = y;
  19. }
  20.  
  21. Punct::Punct(Punct &ceva) {
  22.     this->x = ceva.x;
  23.     this->y = ceva.y;
  24. }
  25.  
  26. void Punct::setX(float x) {
  27.     this->x = x;
  28. }
  29.  
  30. float Punct::getX() {
  31.     return x;
  32. }
  33.  
  34. void Punct::setY(float y) {
  35.     this->y = y;
  36. }
  37.  
  38. float Punct::getY() {
  39.     return y;
  40. }
  41.  
  42. ostream & operator << (ostream &out, Punct &p) {
  43.     out << "(" << p.x << "," << p.y << ")";
  44.     return out;
  45. }
  46.  
  47. class FiguraGeometrica {
  48. public:
  49.     virtual void print();
  50.     virtual ~FiguraGeometrica();
  51.     friend ostream & operator <<(ostream &out, FiguraGeometrica &p);
  52.  
  53.    
  54. };
  55.  
  56.  
  57. void FiguraGeometrica::print() {
  58.     cout << "Figura Geometrica Oarecare" << endl;
  59. }
  60. FiguraGeometrica::~FiguraGeometrica() {
  61.     cout << "Apel destructor FiguraGeometrica" << endl;
  62. }
  63.  
  64. ostream & operator <<(ostream &out, FiguraGeometrica &p) {
  65.      p.print();
  66.      return out;
  67. }
  68.  
  69. class Cerc : virtual public FiguraGeometrica {
  70.     Punct centru;
  71.     float raza;
  72. public:
  73.     Cerc(Punct c, float r);
  74.     Cerc::~Cerc();
  75.     void print();
  76.     friend ostream & operator << (ostream out, Cerc &p);
  77. };
  78. Cerc::Cerc(Punct c, float r) :centru(c), raza(r) {
  79. }
  80. void Cerc::print() {
  81.     cout << "Cerc (" << centru << "," << raza << ")" << endl;
  82.  
  83. }
  84. Cerc::~Cerc() {
  85.     cout << "Apel destructor Cerc" << endl;
  86. }
  87.  
  88. ostream & operator << (ostream out, Cerc &p) {
  89.     cout << "Cerc (" << p.centru << "," << p.raza << ")" << endl;
  90.     return out;
  91. }
  92.  
  93. class Dreptunghi : public FiguraGeometrica {
  94.     Punct colt_s_s; //colt stanga sus
  95.     Punct colt_d_j; //colt dreapta jos
  96. public:
  97.     Dreptunghi(Punct c_s_s, Punct c_d_j);
  98.     Dreptunghi(Dreptunghi &ceva);
  99.     ~Dreptunghi();
  100.     void print();
  101.     friend ostream & operator <<(ostream &out, Dreptunghi &p);
  102.         //friend ostream & operator << (ostream &out, Punct &p);
  103. };
  104.  
  105. Dreptunghi::Dreptunghi(Punct c_s_s, Punct c_d_j) : colt_s_s(c_s_s), colt_d_j(c_d_j) {
  106.     //this->colt_s_s.setX(c_s_s.getX()); // toate astea sunt =.= practic ar trebuii scrise , e same shit
  107.     //this->colt_s_s.setY(c_s_s.getY());
  108.     //this->colt_d_j.setX(c_d_j.getX());
  109.     //this->colt_d_j.setY(c_d_j.getY());
  110.  
  111. }
  112. Dreptunghi::Dreptunghi(Dreptunghi &ceva) : colt_s_s(ceva.colt_s_s), colt_d_j(ceva.colt_d_j) {
  113.    
  114. }
  115. void Dreptunghi::print() {
  116.     cout << "Dreptunghi [" << colt_s_s << "," << colt_d_j << "]" << endl;;
  117. }
  118. Dreptunghi::~Dreptunghi() {
  119.     cout << "Apel destructor Dreptunghi" << endl;
  120. }
  121. ostream & operator <<(ostream &out, Dreptunghi &p) {
  122.     cout << "Dreptunghi [" << p.colt_s_s << "," << p.colt_d_j << "]" << endl;
  123.     return out;
  124. }
  125.  
  126. class Plansa {
  127.     FiguraGeometrica **pFiguri;
  128.     int nrFiguri;
  129. public:
  130.     Plansa(int n, FiguraGeometrica *f[]);
  131.     Plansa(const Plansa &plansa);
  132.     ~Plansa();
  133.     void print();
  134.     friend ostream & operator << (ostream &out, Plansa &p);
  135. };
  136.  
  137. Plansa::Plansa(int n, FiguraGeometrica *f[]) {
  138.     nrFiguri = n;
  139.     pFiguri = new FiguraGeometrica*[nrFiguri];
  140.     for (int i = 0; i<nrFiguri; i++) {
  141.         pFiguri[i] = f[i];
  142.     }
  143. }
  144.  
  145. Plansa::Plansa(const Plansa &plansa) {
  146.     nrFiguri = plansa.nrFiguri;
  147.     this->pFiguri = new FiguraGeometrica*[nrFiguri];
  148.     for (int i = 0; i<nrFiguri; i++) {
  149.         this->pFiguri[i] = plansa.pFiguri[i];
  150.     }
  151. }
  152.    
  153. Plansa::~Plansa() {
  154.     if (pFiguri != 0) {
  155.         delete pFiguri;
  156.         pFiguri = 0;
  157.     }
  158. }
  159.  
  160. void Plansa::print() {
  161.    
  162. }
  163.  
  164. ostream  & operator <<(ostream &out, Plansa &p) {
  165.     cout << "Plansa:" << endl;
  166.     cout << "=======================================" << endl;
  167.     for (int i = 0; i<p.nrFiguri; i++) {
  168.         if (p.pFiguri[i] != 0) {
  169.             //pFiguri[i]->print();
  170.             //cout << p.(*pFiguri[i]);
  171.             cout << *p.pFiguri[i];
  172.         }
  173.     }
  174.     cout << "=======================================" << endl;
  175.     return out;
  176. }
  177. int main() {
  178.     Cerc c(Punct(0, 0), 1);
  179.     c.print();
  180.     Dreptunghi d(Punct(0, 1), Punct(2, 0)),e(d);
  181.     cout << d;
  182.  
  183.     //d.print();
  184.     FiguraGeometrica *f[] = { &c,&d ,&e};
  185.     Plansa plansa(3, f);
  186. //  plansa.print();
  187.  
  188.     cout << plansa;
  189.  
  190.     _getch();
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement