Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 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. size_t rozmiar;
  54. Punkt * punkty;
  55. public:
  56. Wielobok(){rozmiar=0;}
  57. Wielobok(string, Punkt *, Punkt *){}
  58. friend ostream& operator<<(ostream &o, Wielobok &){return o;}
  59. Wielobok operator+(Punkt ){return Wielobok();}
  60. Punkt operator[](int) {return Punkt();}
  61. };
  62.  
  63. int main()
  64. {
  65. Punkt punkt[] = {
  66. Punkt(0,0),
  67. Punkt(1,1),
  68. Punkt(2,1),
  69. Punkt(2,2),
  70. Punkt(3,0)
  71. };
  72.  
  73. cout << "---- 1 ----" << endl;
  74. cout << punkt[0] << endl << punkt[1] << endl;
  75.  
  76. cout << "---- 2 ----" << endl;
  77. cout << boolalpha << (punkt[0] == punkt[1]) << endl;
  78. cout << boolalpha << (punkt[2] == punkt[2]) << endl;
  79.  
  80. cout << "---- 3 ----" << endl;
  81. Figura f1("001");
  82. cout << f1 << endl;
  83.  
  84. {
  85. cout << "---- 4 ----" << endl;
  86. Figura f2(f1);
  87. cout << f2 << endl;
  88. }
  89.  
  90. cout << "---- 5 ----" << endl;
  91. cout << f1 <<endl;
  92.  
  93. cout << "---- 6 ----" << endl;
  94. Figura f3;
  95. {
  96. Figura f4(f1);
  97. f3 = f4;
  98. }
  99. cout << f3 << endl;
  100.  
  101. cout << "---- 7 ----" << endl;
  102. Wielobok w1("002", punkt, punkt+4);
  103. cout << w1 << endl;
  104.  
  105. cout << "---- 7 ----" << endl;
  106. w1 = w1 + punkt[4];
  107. w1 = w1 + punkt[5];
  108.  
  109. cout << w1 << endl;
  110.  
  111. {
  112. cout << "---- 8 ----" << endl;
  113. Wielobok w2(w1);
  114. cout << w2 << endl;
  115. }
  116.  
  117. cout << "---- 9 ----" << endl;
  118. cout << w1 << endl;
  119.  
  120. cout << "---- 10 ----" << endl;
  121. Wielobok w3;
  122. {
  123. Wielobok w4(w1);
  124. w3 = w4;
  125. }
  126. cout << w3 << endl;
  127.  
  128. cout << "---- 11 ----" << endl;
  129. try{
  130. cout << w3[10] <<endl;
  131. }
  132. catch(...){
  133. cout << "Wyjatek" << endl;
  134. }
  135.  
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement