Facebook
From McHalt, 5 Years ago, written in C++.
This paste is a reply to laby from McHalt - view diff
Embed
Download Paste or View Raw
Hits: 246
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. class Punkt{
  6. private:
  7.     int x, y;
  8. public:
  9.     Punkt(){
  10.  
  11.     }
  12.     Punkt(int x, int y){
  13.         this->x = x;
  14.         this->y = y;
  15.     }
  16.     friend ostream& operator<<(ostream& os, Punkt& pp);
  17.     friend istream& operator>>(istream& is, Punkt& pp);
  18. };
  19.  
  20. ostream& operator<<(ostream& os, Punkt& pp){
  21.     os << "{" << pp.x << ", " << pp.y << "}";
  22.     return os;
  23. }
  24.  
  25. istream& operator>>(istream& is, Punkt& pp){
  26.     is >> pp.x;
  27.     is >> pp.y;
  28.     return is;
  29. }
  30.  
  31. class Odcinek{
  32. private:
  33.     Punkt p, k;
  34. public:
  35.     Odcinek(Punkt p, Punkt k){
  36.         this->p = p;
  37.         this->k = k;
  38.     }
  39.     friend ostream &operator<<(ostream &os, Odcinek &od);
  40. };
  41.  
  42. ostream &operator<<(ostream &os, Odcinek &od){
  43.     os << od.p << " <-> " << od.k;
  44.     return os;
  45. }
  46.  
  47. int main(){
  48.     Odcinek od(Punkt(10,5), Punkt(50, 20));
  49.     cout << od;
  50.     return 0;
  51. }