Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. //KAMIL GRODZKI, GR.1 LAB.2, 127968, 29.01.2020r.
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class Punkt
  7. {
  8. private:
  9. float _x, _y;
  10.  
  11. public:
  12. Punkt(): _x(0), _y(0) {}
  13. Punkt(float x, float y): _x(x), _y(y) {}
  14. friend ostream& operator<<(ostream &out, const Punkt &o);
  15. bool operator==(const Punkt&pun){return (_x == pun._x && _y == pun._y);}
  16. float &x() {return _x;}
  17. float &y() {return _y;}
  18.  
  19. const float &x() const {return _x;}
  20. const float &y() const {return _y;}
  21. };
  22.  
  23. ostream& operator<<(ostream& out, const Punkt &o){
  24. out << "x: " << o._x<<"; y: "<<o._y<<endl;
  25. return out ;
  26. }
  27.  
  28. class Figura
  29. {
  30. string *id;
  31. public:
  32. Figura(): id(new string("brak")){}
  33. Figura(const string& _id): id(new string(_id)){}
  34. Figura(const Figura& f): id(new string(*f.id)){}
  35.  
  36. friend ostream& operator<<(ostream &o, Figura &){return o;}
  37.  
  38. Figura& operator=(const Figura& o) {
  39. if (this != &o) {
  40. id = new string(*o.id);
  41. }
  42. return *this;
  43. }
  44.  
  45. string& Id() { return *id; }
  46. const string& Id() const { return *id; }
  47.  
  48. ~Figura() { delete id; }
  49. };
  50.  
  51. class Wielobok : public Figura
  52. {
  53.  
  54. public:
  55. Wielobok(){}
  56. Wielobok(string, Punkt *, Punkt *){}
  57. friend ostream& operator<<(ostream &o, Wielobok &){return o;}
  58. Wielobok operator+(Punkt ){return Wielobok();}
  59. Punkt operator[](int) {return Punkt();}
  60. };
  61.  
  62. int main()
  63. {
  64. Punkt punkt[] = {
  65. Punkt(0,0),
  66. Punkt(1,1),
  67. Punkt(2,1),
  68. Punkt(2,2),
  69. Punkt(3,0)
  70. };
  71.  
  72. cout << "---- 1 ----" << endl;
  73. cout << punkt[0] << endl << punkt[1] << endl;
  74.  
  75. cout << "---- 2 ----" << endl;
  76. cout << boolalpha << (punkt[0] == punkt[1]) << endl;
  77. cout << boolalpha << (punkt[2] == punkt[2]) << endl;
  78.  
  79. cout << "---- 3 ----" << endl;
  80. Figura f1("001");
  81. cout << f1 << endl;
  82.  
  83. {
  84. cout << "---- 4 ----" << endl;
  85. Figura f2(f1);
  86. cout << f2 << endl;
  87. }
  88.  
  89. cout << "---- 5 ----" << endl;
  90. cout << f1 <<endl;
  91.  
  92. cout << "---- 6 ----" << endl;
  93. Figura f3;
  94. {
  95. Figura f4(f1);
  96. f3 = f4;
  97. }
  98. cout << f3 << endl;
  99.  
  100. cout << "---- 7 ----" << endl;
  101. Wielobok w1("002", punkt, punkt+4);
  102. cout << w1 << endl;
  103.  
  104. cout << "---- 7 ----" << endl;
  105. w1 = w1 + punkt[4];
  106. w1 = w1 + punkt[5];
  107.  
  108. cout << w1 << endl;
  109.  
  110. {
  111. cout << "---- 8 ----" << endl;
  112. Wielobok w2(w1);
  113. cout << w2 << endl;
  114. }
  115.  
  116. cout << "---- 9 ----" << endl;
  117. cout << w1 << endl;
  118.  
  119. cout << "---- 10 ----" << endl;
  120. Wielobok w3;
  121. {
  122. Wielobok w4(w1);
  123. w3 = w4;
  124. }
  125. cout << w3 << endl;
  126.  
  127. cout << "---- 11 ----" << endl;
  128. try{
  129. cout << w3[10] <<endl;
  130. }
  131. catch(...){
  132. cout << "Wyjatek" << endl;
  133. }
  134.  
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement