Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //KAMIL GRODZKI, GR.1 LAB.2, 127968, 29.01.2020r.
- #include <iostream>
- using namespace std;
- class Punkt
- {
- private:
- float _x, _y;
- public:
- Punkt(): _x(0), _y(0) {}
- Punkt(float x, float y): _x(x), _y(y) {}
- friend ostream& operator<<(ostream &out, const Punkt &o);
- bool operator==(const Punkt&pun){return (_x == pun._x && _y == pun._y);}
- float &x() {return _x;}
- float &y() {return _y;}
- const float &x() const {return _x;}
- const float &y() const {return _y;}
- };
- ostream& operator<<(ostream& out, const Punkt &o){
- out << "x: " << o._x<<"; y: "<<o._y<<endl;
- return out ;
- }
- class Figura
- {
- string *id;
- public:
- Figura(): id(new string("brak")){}
- Figura(const string& _id): id(new string(_id)){}
- Figura(const Figura& f): id(new string(*f.id)){}
- friend ostream& operator<<(ostream &o, Figura &){return o;}
- };
- class Wielobok : public Figura
- {
- public:
- Wielobok(){}
- Wielobok(string, Punkt *, Punkt *){}
- friend ostream& operator<<(ostream &o, Wielobok &){return o;}
- Wielobok operator+(Punkt ){return Wielobok();}
- Punkt operator[](int) {return Punkt();}
- };
- int main()
- {
- Punkt punkt[] = {
- Punkt(0,0),
- Punkt(1,1),
- Punkt(2,1),
- Punkt(2,2),
- Punkt(3,0)
- };
- cout << "---- 1 ----" << endl;
- cout << punkt[0] << endl << punkt[1] << endl;
- cout << "---- 2 ----" << endl;
- cout << boolalpha << (punkt[0] == punkt[1]) << endl;
- cout << boolalpha << (punkt[2] == punkt[2]) << endl;
- cout << "---- 3 ----" << endl;
- Figura f1("001");
- cout << f1 << endl;
- {
- cout << "---- 4 ----" << endl;
- Figura f2(f1);
- cout << f2 << endl;
- }
- cout << "---- 5 ----" << endl;
- cout << f1 <<endl;
- cout << "---- 6 ----" << endl;
- Figura f3;
- {
- Figura f4(f1);
- f3 = f4;
- }
- cout << f3 << endl;
- cout << "---- 7 ----" << endl;
- Wielobok w1("002", punkt, punkt+4);
- cout << w1 << endl;
- cout << "---- 7 ----" << endl;
- w1 = w1 + punkt[4];
- w1 = w1 + punkt[5];
- cout << w1 << endl;
- {
- cout << "---- 8 ----" << endl;
- Wielobok w2(w1);
- cout << w2 << endl;
- }
- cout << "---- 9 ----" << endl;
- cout << w1 << endl;
- cout << "---- 10 ----" << endl;
- Wielobok w3;
- {
- Wielobok w4(w1);
- w3 = w4;
- }
- cout << w3 << endl;
- cout << "---- 11 ----" << endl;
- try{
- cout << w3[10] <<endl;
- }
- catch(...){
- cout << "Wyjatek" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement