Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. //plik naglowkowy
  2. #ifndef _ukladwspolrzednych_h__
  3. #define _ukladwspolrzednych_h__
  4.  
  5. #include "figura.h"
  6. #include <vector>
  7.  
  8. class UkladWspolrzednych
  9. {
  10. public:
  11. typedef std::vector<Figure> ZbiorFigur;
  12. typedef std::vector<Figure>::iterator IteratorFigur;
  13.  
  14. UkladWspolrzednych();
  15. UkladWspolrzednych(const UkladWspolrzednych& uklad);
  16. UkladWspolrzednych& operator=(const UkladWspolrzednych& uklad);
  17. virtual void add(const Figure& figure);
  18. virtual void print(std::ostream& stream) const; //a to powinno byc zrobione jako operator,a nie funkcja
  19. void operator+(const Figure& figure) { //ten operator wg polecenie to powinno byc +=, a nie + - wystarczy zmienic i bedzie dzialac :)
  20. this->add(figure);
  21. }
  22. std::ostream& operator<<(std::ostream& stream);
  23.  
  24. private:
  25. ZbiorFigur m_figure;
  26. };
  27.  
  28. #endif /* _ukladwspolrzednych_h__ */
  29.  
  30.  
  31.  
  32.  
  33.  
  34. //plik cpp
  35.  
  36. #include "ukladwspolrzednych.h"
  37.  
  38. UkladWspolrzednych::UkladWspolrzednych()
  39. {
  40. m_figure.clear();
  41. }
  42.  
  43. UkladWspolrzednych::UkladWspolrzednych( const UkladWspolrzednych& uklad )
  44. {
  45. *this = uklad;
  46. }
  47.  
  48. UkladWspolrzednych& UkladWspolrzednych::operator=( const UkladWspolrzednych& uklad )
  49. {
  50. m_figure = uklad.m_figure;
  51.  
  52. return *this;
  53. }
  54.  
  55. void UkladWspolrzednych::add(const Figure& figure)
  56. {
  57. m_figure.push_back(figure);
  58. }
  59.  
  60. void UkladWspolrzednych::print( std::ostream& stream ) const
  61. {
  62. for (ConstIteratorFigur i = m_figure.begin(), end = m_figure.end() ; i != end ; ++i) //tu chodzi o to, ze robi dwa iteratory
  63. //jeden ustawiamy na cpzoatek wektora, drugi na koniec, i po prostu jedziemy nim po wektorze-dziala to tak sam, jakbys biegl zwyklym wskaznikiem
  64. //po tablicy, tylko ze tu wykorzystujemy specjalny typ do tego
  65. {
  66. i->print(stream);
  67. stream << std::endl;
  68. }
  69. }
  70.  
  71.  
  72.  
  73. std::ostream& operator<<( std::ostream& stream, const UkladWspolrzednych& uklad )
  74. {
  75. uklad.print(stream);
  76. return stream;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement