Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- using namespace std;
- class Punct {
- float x, y;
- public:
- Punct(float x = 0, float y = 0);
- Punct(Punct &ceva);
- void setX(float x);
- float getX();
- void setY(float y);
- float getY();
- friend ostream & operator << (ostream &out, Punct &p);
- };
- Punct::Punct(float x, float y) {
- this->x = x; this->y = y;
- }
- Punct::Punct(Punct &ceva) {
- this->x = ceva.x;
- this->y = ceva.y;
- }
- void Punct::setX(float x) {
- this->x = x;
- }
- float Punct::getX() {
- return x;
- }
- void Punct::setY(float y) {
- this->y = y;
- }
- float Punct::getY() {
- return y;
- }
- ostream & operator << (ostream &out, Punct &p) {
- out << "(" << p.x << "," << p.y << ")";
- return out;
- }
- class FiguraGeometrica {
- public:
- virtual void print();
- virtual ~FiguraGeometrica();
- friend ostream & operator <<(ostream &out, FiguraGeometrica &p);
- };
- void FiguraGeometrica::print() {
- cout << "Figura Geometrica Oarecare" << endl;
- }
- FiguraGeometrica::~FiguraGeometrica() {
- cout << "Apel destructor FiguraGeometrica" << endl;
- }
- ostream & operator <<(ostream &out, FiguraGeometrica &p) {
- p.print();
- return out;
- }
- class Cerc : virtual public FiguraGeometrica {
- Punct centru;
- float raza;
- public:
- Cerc(Punct c, float r);
- Cerc::~Cerc();
- void print();
- friend ostream & operator << (ostream out, Cerc &p);
- };
- Cerc::Cerc(Punct c, float r) :centru(c), raza(r) {
- }
- void Cerc::print() {
- cout << "Cerc (" << centru << "," << raza << ")" << endl;
- }
- Cerc::~Cerc() {
- cout << "Apel destructor Cerc" << endl;
- }
- ostream & operator << (ostream out, Cerc &p) {
- cout << "Cerc (" << p.centru << "," << p.raza << ")" << endl;
- return out;
- }
- class Dreptunghi : public FiguraGeometrica {
- Punct colt_s_s; //colt stanga sus
- Punct colt_d_j; //colt dreapta jos
- public:
- Dreptunghi(Punct c_s_s, Punct c_d_j);
- Dreptunghi(Dreptunghi &ceva);
- ~Dreptunghi();
- void print();
- friend ostream & operator <<(ostream &out, Dreptunghi &p);
- //friend ostream & operator << (ostream &out, Punct &p);
- };
- Dreptunghi::Dreptunghi(Punct c_s_s, Punct c_d_j) : colt_s_s(c_s_s), colt_d_j(c_d_j) {
- //this->colt_s_s.setX(c_s_s.getX()); // toate astea sunt =.= practic ar trebuii scrise , e same shit
- //this->colt_s_s.setY(c_s_s.getY());
- //this->colt_d_j.setX(c_d_j.getX());
- //this->colt_d_j.setY(c_d_j.getY());
- }
- Dreptunghi::Dreptunghi(Dreptunghi &ceva) : colt_s_s(ceva.colt_s_s), colt_d_j(ceva.colt_d_j) {
- }
- void Dreptunghi::print() {
- cout << "Dreptunghi [" << colt_s_s << "," << colt_d_j << "]" << endl;;
- }
- Dreptunghi::~Dreptunghi() {
- cout << "Apel destructor Dreptunghi" << endl;
- }
- ostream & operator <<(ostream &out, Dreptunghi &p) {
- cout << "Dreptunghi [" << p.colt_s_s << "," << p.colt_d_j << "]" << endl;
- return out;
- }
- class Plansa {
- FiguraGeometrica **pFiguri;
- int nrFiguri;
- public:
- Plansa(int n, FiguraGeometrica *f[]);
- Plansa(const Plansa &plansa);
- ~Plansa();
- void print();
- friend ostream & operator << (ostream &out, Plansa &p);
- };
- Plansa::Plansa(int n, FiguraGeometrica *f[]) {
- nrFiguri = n;
- pFiguri = new FiguraGeometrica*[nrFiguri];
- for (int i = 0; i<nrFiguri; i++) {
- pFiguri[i] = f[i];
- }
- }
- Plansa::Plansa(const Plansa &plansa) {
- nrFiguri = plansa.nrFiguri;
- this->pFiguri = new FiguraGeometrica*[nrFiguri];
- for (int i = 0; i<nrFiguri; i++) {
- this->pFiguri[i] = plansa.pFiguri[i];
- }
- }
- Plansa::~Plansa() {
- if (pFiguri != 0) {
- delete pFiguri;
- pFiguri = 0;
- }
- }
- void Plansa::print() {
- }
- ostream & operator <<(ostream &out, Plansa &p) {
- cout << "Plansa:" << endl;
- cout << "=======================================" << endl;
- for (int i = 0; i<p.nrFiguri; i++) {
- if (p.pFiguri[i] != 0) {
- //pFiguri[i]->print();
- //cout << p.(*pFiguri[i]);
- cout << *p.pFiguri[i];
- }
- }
- cout << "=======================================" << endl;
- return out;
- }
- int main() {
- Cerc c(Punct(0, 0), 1);
- c.print();
- Dreptunghi d(Punct(0, 1), Punct(2, 0)),e(d);
- cout << d;
- //d.print();
- FiguraGeometrica *f[] = { &c,&d ,&e};
- Plansa plansa(3, f);
- // plansa.print();
- cout << plansa;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement