Advertisement
Guest User

Untitled

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