Facebook
From Bistre Mousedeer, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 52
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. class Point{
  5.         private:
  6.                 double x,y;
  7.         public:
  8.                 Point(double x,double y){
  9.                         this->x=x;
  10.                         this->y=y;
  11.                 }
  12.                 Point(){
  13.  
  14.                 }
  15.  
  16.                 friend ostream& operator <<(ostream&, const Point&);
  17.                 friend istream& operator >> (istream&, Point&);
  18.  
  19.                void przesun(double dx, double dy){
  20.                         x+=dx;
  21.                         y+=dy;
  22.                 }
  23.                 void jednokladnosc(double k){
  24.                         x=x*k;
  25.                         y=y*k;
  26.                 }
  27.                 void symetriaOX(){
  28.                         y=-y;
  29.                 }
  30.                 void symetriaOY(){
  31.                         x=-x;
  32.                 }
  33.                 double getX(){
  34.                         return x;
  35.                 }
  36.                 double getY(){return y;}
  37. };
  38.  
  39. class Trojkat{
  40.         private:
  41.                 Point* a;
  42.                 Point* b;
  43.                 Point* c;
  44.  
  45.  
  46.         public:
  47.                 Trojkat(){
  48.                         a = new Point();
  49.                         b = new Point();
  50.                         c = new Point();
  51.  
  52.                 }
  53.                 Trojkat(Point aa,Point bb,Point cc){
  54.                         a = new Point(aa);
  55.                         b = new Point(bb);
  56.                         c = new Point(cc);
  57.  
  58.                 }
  59.                 Trojkat(double ax,double ay,double bx,double by,double cx,double cy){
  60.                         this->a = new Point(ax,ay);
  61.                         this->b = new Point(bx,by);
  62.                         this->c = new Point(cx,cy);
  63.  
  64.                 }
  65.  
  66.                 Point* getA(){
  67.                         return a;
  68.                 }
  69.                 Point* getB(){
  70.                         return b;
  71.                 }
  72.                 Point* getC(){
  73.                         return c;
  74.                 }
  75.                 void przesun(double ax,double ay,double bx,double by,double cx,double cy)
  76.                 {
  77.                     a->przesun(ax,ay);
  78.                     b->przesun(bx,by);
  79.                     c->przesun(cx,cy);
  80.  
  81.                 }
  82.                 void jednokladnosc(double ak){
  83.                         a->jednokladnosc(ak);
  84.                         b->jednokladnosc(ak);
  85.                         c->jednokladnosc(ak);
  86.  
  87.                 }
  88.                   void symetriaOX(){
  89.                         a->symetriaOX();
  90.                         b->symetriaOX();
  91.                         c->symetriaOX();
  92.                 }
  93.                 void symetriaOY(){
  94.                         a->symetriaOY();
  95.                         b->symetriaOY();
  96.                         c->symetriaOY();
  97.                 }
  98.  
  99.  
  100.                 friend ostream& operator <<(ostream&, const Trojkat&);
  101.                 friend istream& operator >> (istream&, Trojkat&);
  102.  
  103.  
  104.                 ~Trojkat(){
  105.                         delete a;
  106.                         delete b;
  107.                         delete c;
  108.                 }
  109. };
  110.  
  111. ostream& operator <<(ostream& os, const Point& pp)
  112. {
  113.     os << "("<<pp.x <<", " << pp.y<<")";
  114.     return os;
  115. }
  116. istream& operator >>(istream& is,  Point& pp)
  117. {
  118.     is >> pp.x  >> pp.y;
  119.     return is;
  120. }
  121. ostream& operator <<(ostream& os, const Trojkat& tr)
  122. {
  123.     os << "["<<*(tr.a) <<", " << *(tr.b)<< "," <<*(tr.c)<< "]";
  124.     return os;
  125. }
  126. istream& operator >>(istream& is,  Trojkat& tr)
  127. {
  128.     //is >> tr->a  >> tr->b >> tr->c;
  129.     return is;
  130. }
  131.  
  132. int main(){
  133.         Point p1;
  134.         cout<<"Podaj wsp p1:";
  135.         cin>>p1;
  136.         Point p2(4.0,5.3);
  137.         Point *wp3= new Point(2,0);
  138.         cout<<"Punkty"<<p1<<p2<<*wp3;
  139.         p1.jednokladnosc(2.0);
  140.         p2.przesun(-1,2.5);
  141.         wp3->symetriaOX();
  142.         cout<<*wp3;
  143.         cout<<p2;
  144.  
  145.         Trojkat tr1(1.0,1,4,5,2,0);
  146.         cout<<"tr1="<<tr1;
  147.         Trojkat tr2();
  148.         //cout<<"Podaj wsp tr2:";
  149.         //cin>>tr2;
  150.         //Trojkat *wt3= new Trojkat(&p1,&p2,wp3);
  151.         //cout<<"tr3="<<wt3;
  152.         tr1.jednokladnosc(2.0);
  153.         //tr2.przesun(-1,2.5);
  154.         //wt3->symetriaOY();
  155.         cout<<"tr1="<<tr1;
  156.        // cout<<"tr2="<<tr2;
  157.        // cout<<"tr3="<<*wt3;
  158.  
  159.  
  160.  
  161.  
  162.         return 0;
  163. }