Advertisement
Bakayaro1

Test

May 1st, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. // 1 proba.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. class figura
  8. {
  9.     public:
  10.  
  11.     struct Punkt
  12.     {
  13.         double x,y;
  14.         Punkt():x(0),y(0) {}
  15.         Punkt(double x,double y):x(x),y(y) {}
  16.     };
  17.    
  18.     vector < Punkt > lista;
  19.  
  20.  
  21.     void wyswietl()
  22.     {
  23.         for(int i=0 ; i<lista.size(); i++)
  24.             cout << lista[i].x << lista[i].y;
  25.     }
  26.    
  27.    
  28.     void obwod() //dodawanie wszystkich bokow
  29.     {
  30.         int OBW = 0;
  31.         for(int i=0 ; i<lista.size(); i++)
  32.         OBW += sqrt(pow(((lista[i+1].x) - (lista[i].x)),2) + pow((((lista[i+1].y) - (lista[i].y))),2));
  33.  
  34.         cout << OBW;
  35.     }  
  36.  
  37. };
  38.  
  39. class trojkat : public figura
  40. {
  41.     public:
  42.     trojkat()
  43.     {
  44.         lista.push_back(Punkt(1,2));
  45.         lista.push_back(Punkt(10,8));
  46.         lista.push_back(Punkt(0,11));
  47.     }
  48.    
  49.     void pole_trojkata() //ze wzoru
  50.     {
  51.         cout << 0.5 * ((lista[1].x - lista[0].x)*(lista[2].y - lista[0].y) - (lista[1].y - lista[0].y)*(lista[2].x - lista[0].x));
  52.     }
  53. };
  54.  
  55. class czworokat : public figura
  56. {
  57.     public:
  58.     czworokat()
  59.     {
  60.         lista.push_back(Punkt(1,2));
  61.         lista.push_back(Punkt(1,9));
  62.         lista.push_back(Punkt(5,8));
  63.         lista.push_back(Punkt(0,7));
  64.     }
  65.  
  66.  
  67. };
  68.  
  69. class osmiokat : public figura
  70. {
  71.     public:
  72.     osmiokat()
  73.     {
  74.         lista.push_back(Punkt(1,2));
  75.         lista.push_back(Punkt(3,4));
  76.         lista.push_back(Punkt(5,6));
  77.         lista.push_back(Punkt(7,8));
  78.         lista.push_back(Punkt(9,10));
  79.         lista.push_back(Punkt(11,12));
  80.         lista.push_back(Punkt(13,14));
  81.         lista.push_back(Punkt(15,16));
  82.     }
  83.  
  84.  
  85.     void pole_osmiokat() //Shoelace formula
  86.     {
  87.         int B = 0;
  88.         for (int i = 0 ; i < 7 ; i++)
  89.         B += lista[i].x * lista[i+1].y;
  90.  
  91.         int C = 0;
  92.         for (int i = 0 ; i < 7 ; i++)
  93.         C -= lista[i+1].x * lista[i].y;
  94.  
  95.         int D = 0;
  96.         D = lista[7].x * lista[0].y;
  97.  
  98.         int E = 0;
  99.         E = lista[0].x * lista[7].y;
  100.  
  101.         cout << 0.5 * (B + C + D - E);
  102.     }
  103.  
  104.  
  105. };
  106.  
  107. class kwadrat : public czworokat
  108. {
  109.     public:
  110.     kwadrat()
  111.     {
  112.         lista.push_back(Punkt(1,3));
  113.         lista.push_back(Punkt(3,3));
  114.         lista.push_back(Punkt(3,1));
  115.         lista.push_back(Punkt(1,1));
  116.     }
  117.  
  118.    
  119.     void pole_kwadratu() //bok do kwadratu
  120.     {
  121.         cout << pow((sqrt(pow((lista[1].x - lista[0].x),2) + pow((lista[1].y - lista[0].y),2))),2);
  122.     }
  123.  
  124. };
  125.  
  126.  
  127.  
  128.  
  129.  
  130. int _tmain(int argc, _TCHAR* argv[])
  131. {
  132.     //list <trojkat> lista_trojkatow
  133.     //list <trojkat> ::iterator it = lista_trojkatow.begin();
  134.  
  135.  
  136.  
  137.  
  138.  
  139.     system("pause");
  140.     return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement