Advertisement
DescendingBear

Dziedziczenie elementow prywatnych: Zadanie 1

Dec 8th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. class PLN{
  6.     private:
  7.            virtual float oblicz_powierzchnie() = 0;
  8.     protected:
  9.             int w, h, d;
  10.             PLN(int w_n, int h_n){};    //konstruktor dla banknotow
  11.             PLN(int d_n){};             //konstruktor dla monet
  12.             PLN(){};
  13.  
  14.             float za_duza_powierzchnia(float ograniczenie)
  15.             {
  16.                 if (oblicz_powierzchnie() > ograniczenie)
  17.                 {
  18.                     cout<<"Za duze pole powierzchni!"<<endl;
  19.                     return true;
  20.                 }
  21.                 else
  22.                 {
  23.                     cout<<"Akceptowalne pole powierzchni!"<<endl;
  24.                     return false;
  25.                 }
  26.             }
  27.     public:
  28. };
  29.  
  30. class Moneta: PLN{
  31. private:
  32. protected:
  33. public:
  34.     Moneta(int d1): PLN(d1) {};
  35.  
  36.     float oblicz_powierzchnie()
  37.     {
  38.         float circ = d*d*3.14;
  39.         cout<<circ<<endl;
  40.     }
  41. };
  42.  
  43. class Banknot: PLN{
  44. private:
  45. protected:
  46. public:
  47.     Banknot(int w1, int h1): PLN(w1, h1) {};
  48.     float oblicz_powierzchnie()
  49.     {
  50.         float rect = w*h;
  51.         cout<<rect<<endl;
  52.     }
  53. };
  54.  
  55. int main()
  56. {
  57.     Banknot kilometr (1.44, 1.72);
  58.     kilometr.oblicz_powierzchnie();
  59.  
  60.     Moneta metr (2.4);
  61.     metr.oblicz_powierzchnie();
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement