Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //h
- #ifndef POLI_H
- #define POLI_H
- #pragma warning(disable : 4996)
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Figura
- {
- public:
- virtual ~Figura(){}
- virtual float arie()=0;
- virtual void afisare()=0;
- };
- class Dreptunghi : public Figura
- {
- private:
- int x1,y1,x2,y2;
- public:
- Dreptunghi(int x1,int y1,int x2,int y2);
- float arie();
- void afisare();
- };
- class Cerc : public Figura
- {
- private:
- int x,y,r;
- public:
- Cerc(int x, int y, int r);
- float arie();
- void afisare();
- };
- //Figura *figCuArieMax(Figura **figuri, int n);
- class Triunghi : public Figura
- {
- private:
- int x1,y1,x2,y2,x3,y3;
- public:
- Triunghi(int x1,int y1,int x2,int y2,int x3,int y3);
- float arie();
- void afisare();
- };
- #endif
- //main
- #include"poli.h"
- /*
- int main(int)
- {
- const int n = 3;
- Figura *figuri[n];
- figuri[0] = new Dreptunghi(0,0,2,5);
- figuri[1] = new Dreptunghi(0,0,2,2);
- figuri[2] = new Cerc(0,0,3);
- figuri[2] = new Triunghi(1,4,3);
- Figura *figMax = figCuArieMax(figuri, n);
- cout << " Dintre figurile:"<<endl;
- for(int i=0; i<3; i++)
- {
- cout << i << ". ";
- figuri[i]->afisare();
- }
- cout << endl<<" aria maxima o are:"<<endl;
- figMax->afisare();
- for(int i=0; i<n; i++)
- {
- delete figuri[i];
- }
- return 0;
- }*/
- int main()
- {
- int f;
- Figura *dr = new Dreptunghi(1,2,4,4);
- Figura *cerc = new Cerc(1,1,3);
- Figura *tr = new Triunghi(0,2,7,0,-2,0);
- //urmatoarea linie ar genera eroare:
- //Figura *fig = new Figura();
- dr->afisare();
- cerc->afisare();
- tr->afisare();
- delete dr;
- delete cerc;
- delete tr;
- cin>>f;
- return 0;
- }
- //dreptunghi.cpp
- #include"poli.h"
- Dreptunghi::Dreptunghi(int x1, int y1, int x2, int y2)
- {
- this->x1 = x1;
- this->y1 = y1;
- this->x2 = x2;
- this->y2 = y2;
- }
- float Dreptunghi::arie()
- {
- return (float)(x2 - x1)*(y2 - y1);
- }
- void Dreptunghi::afisare()
- {
- cout << "Dreptunghi cu coordonatele (" <<x1<<","<<y1<<")-("<<x2<<","<<y2<<"), si aria " << arie()<<endl;
- }
- //cerc.cpp
- #include "poli.h"
- Cerc::Cerc(int x, int y, int r)
- {
- this->x = x;
- this->y = y;
- this->r = r;
- }
- float Cerc::arie()
- {
- const float PI = 3.14F;
- return PI * r * r;
- }
- void Cerc::afisare()
- {
- cout << "Cerc cu coordonatele (" <<x<<","<<y <<"), raza " << r<<" si aria " << arie()<<endl;
- }
- //triunghi.cxpp
- #include "poli.h"
- Triunghi::Triunghi(int x1,int y1,int x2,int y2,int x3,int y3)
- {
- this->x1 = x1;
- this->y1 = y1;
- this->x2 = x2;
- this->y2 = y2;
- this->x3 = x3;
- this->y3 = y3;
- }
- void Triunghi::afisare()
- {
- cout<<"triunghi cu coordonatele (" <<x1<<","<<y1<<")-("<<x2<<","<<y2<<")-("<<x3<<","<<y3<<"), si aria " << arie()<<endl;
- }
- float Triunghi::arie()
- {
- float p,s;
- float a,b,c;
- a= sqrt((float)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
- b= sqrt((float)(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
- c= sqrt((float)(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
- p= (a+b+c)/2;
- s = sqrt(p*(p-a)*(p-b)*(p-c));
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement