Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- POLIGON.CPP
- #include "Poligon.h"
- #include <iostream>
- #include <fstream>
- #include <math.h>
- using namespace std;
- int i=0;
- Poligon::Poligon(int n)
- {
- this->BrojTemena = n;
- this->x = new double[this->BrojTemena];
- this->y = new double[this->BrojTemena];
- }
- Poligon::Poligon()
- {
- this->BrojTemena = 0;
- this->x = new double[this->BrojTemena];
- this->y = new double[this->BrojTemena];
- }
- Poligon::~Poligon()
- {
- if(this->x != NULL)
- {
- delete [] this->x;
- }
- if(this->y != NULL)
- {
- delete [] this->y;
- }
- }
- void Poligon::Obim()
- {
- int i;
- double obim=0,k1,k2;
- for(i=0; i<this->BrojTemena-1; i++)
- {
- k1=(this->x[i+1]-this->x[i])*(this->x[i+1]-this->x[i]);
- k2=(this->y[i+1]-this->y[i])*(this->y[i+1]-this->y[i]);
- obim += sqrt(k1+k2);
- }
- k1=(this->x[i]-this->x[0])*(this->x[i]-this->x[0]);
- k2=(this->y[i]-this->y[0])*(this->y[i]-this->y[0]);
- obim += sqrt(k1+k2);
- cout<<"Obim:"<<obim;
- }
- void Poligon::PostaviKordinate(int X, int Y)
- {
- this->x[i] = (double)X;
- this->y[i] = (double)Y;
- i++;
- }
- void Poligon::VratiNajdalje()
- {
- int i;
- double r1,r2,r3,max=0,k;
- for(i=0; i<this->BrojTemena-1; i++)
- {
- r1 = (this->x[i]-this->x[i+1])*(this->x[0]-this->x[i+1]);
- r2 = (this->y[i]-this->y[i+1])*(this->y[i]-this->y[i+1]);
- r3=r1+r2;
- k = sqrt(r3);
- if(k>max)
- {
- max = k;
- }
- }
- r1 = (this->x[0]-this->x[this->BrojTemena-1])*(this->x[0]-this->x[this->BrojTemena-1]);
- r2 = (this->y[9]-this->y[this->BrojTemena-1])*(this->y[0]-this->y[this->BrojTemena-1]);
- r3=r1+r2;
- k = sqrt(r3);
- if(k>max)
- {
- max = k;
- }
- cout<<"Najduze rastojanje:"<<max;
- }
- void Poligon::PrikaziKordinate()
- {
- for(int i=0; i<this->BrojTemena; i++)
- {
- cout<<"X:"<<this->x[i]<<" "<<"Y:"<<this->y[i]<<endl;
- }
- }
- void Poligon::IzbaciTeme()
- {
- double* kopijax;
- kopijax = new double[20];
- double* kopijay;
- kopijay = new double[20];
- for(int i=0; i<this->BrojTemena; i++)
- {
- kopijax[i] = this->x[i];
- kopijay[i] = this->y[i];
- }
- delete[] this->x;
- delete[] this->y;
- this->BrojTemena--;
- this->x = new double[this->BrojTemena];
- this->y = new double[this->BrojTemena];
- for(int i=0; i<this->BrojTemena; i++)
- {
- this->x[i] = kopijax[i];
- this->y[i] = kopijay[i];
- }
- delete[] kopijax;
- delete[] kopijay;
- }
- Poligon::Poligon(const Poligon& p)
- {
- this->BrojTemena = p.BrojTemena;
- x = new double[p.BrojTemena];
- y = new double[p.BrojTemena];
- for(int i =0; i<BrojTemena; i++)
- {
- x[i] = p.x[i];
- y[i] = p.y[i];
- }
- }
- void Poligon::PreslikajUOdnosuNaX()
- {
- for(int i=0; i<this->BrojTemena; i++)
- {
- this->x[i] = this->x[i]*(-1);
- }
- }
- void Poligon::PreslikajUOdnosuNaY()
- {
- for(int i=0; i<this->BrojTemena; i++)
- {
- this->y[i] = this->y[i]*(-1);
- }
- }
- istream& operator>>(istream& ulaz, Poligon& p)
- {
- for(int i=0; i<p.BrojTemena; i++)
- {
- ulaz>>p.x[i]>>p.y[i];
- }
- return ulaz;
- }
- ostream& operator<<(ostream& izlaz, const Poligon& p)
- {
- for(int i=0; i<p.BrojTemena; i++)
- {
- izlaz <<p.x[i]<<' '<<p.y[i]<<endl;
- }
- return izlaz;
- }
- ------------------------------------------------------------------------------------------------------------------------------------------
- MAIN.CPP
- #include "Slika.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- void main()
- {
- Poligon* p1;
- int n;
- cout<<"Broj temena p1:"<<endl;
- cin>>n;
- p1= new Poligon(n);
- ifstream f("kordinate.txt");
- f>>*p1;
- f.close();
- cout<<"P1 posle preslikavanjie u odnosu na X osu"<<endl;
- p1->PreslikajUOdnosuNaX();
- p1->PrikaziKordinate();
- cout<<"P1 Posle preslikavanjie u odnosu na Y osu"<<endl;
- p1->PreslikajUOdnosuNaY();
- p1->PrikaziKordinate();
- int m;
- cout<<"Broj temena p2:"<<endl;
- cin>>m;
- Poligon* p2 = new Poligon(m);
- cout<<"P2 posle preslikavanjie u odnosu na X osu"<<endl;
- ifstream f1("kordinate.txt");
- f1>>*p2;
- f1.close();
- p2->PreslikajUOdnosuNaX();
- p2->PrikaziKordinate();
- cout<<"P2 posle preslikavanjie u odnosu na Y osu"<<endl;
- p2->PreslikajUOdnosuNaY();
- p2->PrikaziKordinate();
- int k;
- cout<<"Maksimalan broj elementa:"<<endl;
- cin>>k;
- Slika s(k);
- s.DodajPoligon(*p1);
- s.DodajPoligon(*p2);
- cout<<s;
- for(int i=0; i<k-2; i++)
- {
- int t;
- cout<<"Broj tacaka:"<<endl;
- cin>>t;
- Poligon* p3;
- p3 = new Poligon(t);
- for(int j=0; j<t; j++)
- {
- int x,y;
- cout<<"X: Y: "<<endl;
- cin>>x>>y;
- p3->PostaviKordinate(x,y);
- }
- s.DodajPoligon(*p3);
- }
- cout<<"posle"<<endl;
- cout<<s;
- system("pause");
- }
- ---------------------------------------------------------------------------------------------------------------------------------
- POLIGON.H
- #include <iostream>
- using namespace std;
- class Poligon
- {
- public:
- int BrojTemena;
- double* x;
- double* y;
- public:
- Poligon(int n);
- Poligon();
- ~Poligon();
- Poligon(const Poligon& p);
- inline int Vrati()
- {
- return this->BrojTemena;
- }
- void Obim();
- void PostaviKordinate(int X, int Y);
- void VratiNajdalje();
- void PrikaziKordinate();
- void IzbaciTeme();
- void PreslikajUOdnosuNaX();
- void PreslikajUOdnosuNaY();
- friend istream& operator>>(istream& ulaz, Poligon& p);
- friend ostream& operator<<(ostream& izlaz, const Poligon& p);
- };
- -----------------------------------------------------------------------------------------------------------------------------------------
- SLIKA.CPP
- #include "Slika.h"
- #include <iostream>
- #include <fstream>
- #include <math.h>
- int br=0;
- Slika::Slika(int k)
- {
- this->maxBrojaPoligona=k;
- this->niz = new Poligon[this->maxBrojaPoligona];
- }
- void Slika::DodajPoligon(Poligon& p)
- {
- this->niz[br] = p;
- br++;
- }
- ostream& operator<<(ostream& izlaz, const Slika& s)
- {
- for(int i=0; i<s.maxBrojaPoligona; i++)
- {
- izlaz << s.niz[i];
- }
- return izlaz;
- }
- -----------------------------------------------------------------------------------------------------------------------------------------
- SLIKA.H
- #include <iostream>
- #include "Poligon.h"
- using namespace std;
- class Slika
- {
- public:
- int maxBrojaPoligona;
- Poligon* niz;
- public:
- Slika(int k);
- void DodajPoligon(Poligon& p);
- friend ostream& operator<<(ostream& izlaz,const Slika& p);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement