Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////Michal Szuleta sem3 nst g1 dz1
- #include <iostream>
- #include <math.h>
- using namespace std;
- class punkt
- {
- double X,Y;
- public:
- punkt();
- punkt(double,double);
- const double& x()const {return X;}
- const double& y()const {return Y;}
- double& x(){return X;}
- double& y(){return Y;}
- double odleglosc(punkt target)
- {
- double d =0.0;
- d=sqrt(pow(target.X - this->X,2)+pow(target.Y-this->Y,2));
- return d;
- }
- };
- punkt::punkt():X(0),Y(0){}
- punkt::punkt(double x,double y)
- {
- this->X = x;
- this->Y = y;
- }
- class wielobok
- {
- private:
- punkt *tab;
- int n=0;
- public:
- wielobok();
- wielobok(punkt* , punkt*);
- double obwod()
- {
- double obw=0.0;
- for(int i=0;i<n-1;i++)
- {
- obw+= tab[i].odleglosc(tab[i+1]);
- }
- obw+= tab[n-1].odleglosc(tab[0]);
- return obw;
- }
- punkt& Punkt (int a=0)
- {
- return tab[a];
- }
- void wyswietl(int a=0)
- {
- cout<<tab[a].x()<<","<<tab[a].y()<<endl;
- }
- int ilosc()
- {
- return n;
- }
- void punkty (punkt *c,punkt *d)
- {
- n=d-c;
- tab = new punkt[n];
- for(int i=0;i<n;i++)
- {
- tab[i]= c[i];
- }
- }
- ~wielobok()
- {
- delete [] tab;
- cout<<"USUNIETO TABLICE"<<endl;
- }
- };
- wielobok::wielobok(){}
- wielobok::wielobok(punkt *c,punkt *d)
- {
- n=d-c;
- tab = new punkt[n];
- for(int i=0;i<n;i++)
- {
- tab[i]= c[i];
- }
- }
- int main()
- {
- punkt p(2, 3);
- cout << p.x() << ' ' << p.y() << '\n';
- p.x() = 1;
- p.y() = 1;
- cout << p.x() << ' ' << p.y() << '\n';
- cout << p.odleglosc(punkt()) << '\n';
- punkt t[] = { punkt(0, 1), punkt(0, 0), punkt(1, 0), punkt(1,1) };
- wielobok w1(t,t+4);
- cout << w1.obwod() << '\n';
- w1.Punkt(1) = punkt(0.5, 0.5);
- cout << w1.obwod() << '\n';
- wielobok w2;
- w2.punkty(t, t+3);
- cout << w2.obwod() << '\n';
- for (int i = 0; i < w2.ilosc(); ++i)
- cout << w2.Punkt(i).x() << ' ' << w2.Punkt(i).y() << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement