Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 3.42 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. class Punkt{
  8.    int x,y;
  9.    public:
  10.    Punkt() { x=y=0; }
  11.    Punkt(int xx, int yy){ x=xx; y=yy; }
  12.    Punkt(const Punkt& p) { x=p.x; y=p.y; }
  13.    ~Punkt();
  14.    int givex(){return x;}
  15.    int givey(){return y;}
  16.    
  17.    void przesun(int ax, int ay){
  18.                 x+=ax;
  19.                 y+=ay; 
  20.    }
  21.        
  22.    };
  23.  
  24.  class Linia {
  25.    private: Punkt *p1, *p2;
  26.    public:
  27.    Linia() { p1=new Punkt(0,0); p2=new Punkt(0,0); }
  28.    Linia(Punkt a, Punkt b){ p1=new Punkt(a); p2=new Punkt(b);}
  29.    Linia(const Linia &l) { p1=l.p1; p2=l.p2; }
  30.        ~Linia(){ delete p1; delete p2;}
  31.    Punkt* getP1() {return p1;}
  32.    Punkt* getP2(){return p2;}
  33.    
  34.         void przesunLinie(int ax, int ay) {
  35.                 p1->przesun(ax,ay);
  36.         p2->przesun(ax,ay);
  37.     }
  38.    
  39.    };
  40.  
  41. class Figura{
  42. protected: char kolor;
  43. public:
  44.        Figura(char k){ kolor=k; }
  45.    };
  46.  
  47. class Trojkat: public Figura {
  48.    Linia *l1,*l2,*l3;
  49.  
  50. public: Trojkat (char k, Punkt p1, Punkt p2, Punkt p3) : Figura(k){
  51. l1=new Linia(p1,p2); l2=new Linia(p2,p3); l3=new Linia (p1,p3); }
  52. //      Trojkat (char k, Punkt p1, Punkt p2, Punkt p3) { l1=new Linia(p1,p2); l2=new Linia(p2,p3); l3=new Linia (p1,p3); }
  53.  
  54. void przesunTrojkat(int ax,int ay)
  55.         {
  56.         l1->przesunLinie(ax,ay);
  57.         l2->przesunLinie(ax,ay);
  58.         l3->przesunLinie(ax,ay);
  59.         }
  60.  
  61.  
  62. int obwodTrojkata() {
  63. int bok1,bok2,bok3,obwod;
  64. bok1=bok2=bok3=obwod=0;
  65.  
  66.                 int x1 = (l1->getP1()->givex());
  67.                 int y1= (l1->getP1()->givey());
  68.  
  69.                 int x2 = (l1->getP2()->givex());
  70.                 int y2= (l1->getP2()->givey());
  71.  
  72.                 int x3 = l2->getP2()->givex();
  73.                 int y3= l2->getP2()->givey();
  74.  
  75.                 bok1=sqrt( (x2-x1)*(x2-x1)-(y2-y1)*(y2-y1) );
  76.                 bok2=sqrt( (x3-x2)*(x3-x2)-(y3-y2)*(y3-y2) );
  77.                 bok3=sqrt( (x3-x1)*(x3-x1)-(y3-y1)*(y3-y1) );
  78.        
  79.                 obwod=bok1+bok2+bok3;
  80.                
  81.                 return obwod;
  82.         }
  83.        
  84. double obliczPole()
  85.         {
  86. int bok1,bok2,bok3,obwod;
  87. bok1=bok2=bok3=obwod=0;
  88. double pole=0;
  89.  
  90.                 int x1 = (l1->getP1()->givex());
  91.                 int y1= (l1->getP1()->givey());
  92.                 int x2 = (l1->getP2()->givex());
  93.                 int y2= (l1->getP2()->givey());
  94.                 int x3 = l2->getP2()->givex();
  95.                 int y3= l2->getP2()->givey();
  96.  
  97.                 bok1=sqrt( (x2-x1)*(x2-x1)-(y2-y1)*(y2-y1) );
  98.                 bok2=sqrt( (x3-x2)*(x3-x2)-(y3-y2)*(y3-y2) );
  99.                 bok3=sqrt( (x3-x1)*(x3-x1)-(y3-y1)*(y3-y1) );
  100.        
  101.         double p=(bok1+bok2+bok3)/2;
  102.         pole=sqrt(p*(p-bok1)*(p-bok2)*(p-bok3));
  103.        
  104.         return pole;
  105.         }
  106.    };
  107.  
  108. class Czworokat: public Figura{
  109. private: Linia *l1,*l2,*l3,*l4;
  110. public: Czworokat(char k, Punkt p1, Punkt p2, Punkt p3, Punkt p4): Figura(k){
  111.                 l1=new Linia(p1,p2);
  112.         l2=new Linia(p2,p3);
  113.         l3=new Linia (p3,p4);
  114.         l4=new Linia(p1,p4);
  115.         }
  116.  
  117. void przesunCzworokat(int ax,int ay)
  118.         {
  119.         l1->przesunLinie(ax,ay);
  120.         l2->przesunLinie(ax,ay);
  121.         l3->przesunLinie(ax,ay);
  122.         l4->przesunLinie(ax,ay);
  123.         }      
  124.  
  125.  
  126.    };
  127.  
  128. class Prostokat: public Czworokat{
  129.        //Prostokat(char k, int dlugosc, int szerokosc):Czworokat{
  130.        double pole;
  131.        int obwod;
  132. public: Prostokat(char k, Punkt p1, Punkt p2) : Czworokat(k, p1,Punkt(p1.givex(), p2.givey()), Punkt(p2.givex(), p1.givey()), p2){}
  133.  
  134.  
  135.    };
  136.  
  137. class Kwadrat: public Prostokat{
  138.   // Kwadrat(Punkt p, int dlugosc) { }
  139. Kwadrat(char k, Punkt p1, int dlugosc) : Prostokat(k, p1,Punkt(p1.givex() + dlugosc, p1.givey() + dlugosc)){}
  140.  
  141.    };
  142.  
  143. int main()
  144. {
  145.  
  146.         Linia l1((5,5),(3,3));
  147.  
  148. Czworokat cz('n', (0,0),(0,3),(3,0),(3,3));
  149.  
  150.    system("pause");
  151.        return 0;
  152. }