Advertisement
jakobok12

Untitled

Mar 31st, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4. #define pi (3.14)
  5. using namespace std;
  6.  
  7. class Figura
  8. {
  9. protected:
  10.     int pozycjaX, pozycjaY;
  11.     double pole;
  12.     string nazwa;
  13. public:
  14.     int pobierzX()
  15.     {
  16.         return pozycjaX;
  17.     }
  18.     Figura(int x, int y, string nazwa) : pozycjaX(x), pozycjaY(y), nazwa(nazwa)
  19.     {
  20.         nazwa = "figura";
  21.     }
  22.     string pobierzNazwe()
  23.     {
  24.         return nazwa;
  25.     }
  26.     double pobierzPole()
  27.     {
  28.         return pole;
  29.     }
  30. };
  31.  
  32. class Okrag : public Figura
  33. {
  34. private:
  35.     int z;
  36. public:
  37.  
  38.     Okrag(int x, int y, int z, string nazwa) : Figura(x, y, nazwa), z(z)
  39.     {
  40.         polepow();
  41.     }
  42.     float polepow()
  43.     {
  44.         pole = (pi*z*z);
  45.         return (pi*z*z);
  46.     }
  47.     int pobierzY()
  48.     {
  49.         return pozycjaY;
  50.     }
  51. };
  52.  
  53. class Prostokat : public Figura
  54. {
  55. public:
  56.     Prostokat(int x, int y, string nazwa) : Figura(x, y, nazwa)
  57.     {
  58.         polepow();
  59.     }
  60.     int polepow()
  61.     {
  62.         pole = pozycjaX * pozycjaY;
  63.         return (pozycjaX*pozycjaY);
  64.     }
  65. };
  66.  
  67. class Kwadrat : public Figura
  68. {
  69. public:
  70.     Kwadrat(int x, string nazwa) : Figura(x, x, nazwa)
  71.     {
  72.         polepow();
  73.     }
  74.     int polepow()
  75.     {
  76.         pole = pozycjaX*pozycjaX;
  77.         return (pozycjaX * pozycjaY);
  78.     }
  79.  
  80. };
  81.  
  82. int main()
  83. {
  84.     double pola=0;
  85.     int suma = 0;
  86.     list<Figura*>lista;
  87.     lista.push_back(new Okrag(1, 2, 3, "kolko"));
  88.     lista.push_back(new Prostokat(2, 5, "prostokacik"));
  89.     lista.push_back(new Kwadrat(5, "kwadracik"));
  90.  
  91.     for (list<Figura*>::iterator iter = lista.begin(); iter != lista.end(); iter++)
  92.     {
  93.         cout << "Nazwa: " <<(*iter)->pobierzNazwe();
  94.         cout << ", pole: " << (*iter)->pobierzPole() << endl;
  95.         pola += (*iter)->pobierzPole();
  96.     }
  97.     cout << endl << "Suma pol wszystkich figur wynosi: " << pola << "[j]^2.";
  98.     //cout << k.polepow();
  99.     getchar();
  100.     cin.ignore();
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement