Advertisement
Guest User

Untitled

a guest
May 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class figura{
  4.     protected:
  5.         string *kolor;
  6.         double liczba;
  7.     public:
  8.         figura():kolor(new string("Brak")),liczba(0){}
  9.         figura(const string &kolo, const double &a):kolor(new string(kolo)),liczba(a){}
  10.  
  11.  
  12.         virtual double pole() const = 0;
  13.         virtual ostream &pokaz(ostream &out)const=0;
  14.  
  15.         friend ostream &operator<<(ostream &out, const figura &a){
  16.         return a.pokaz(out);
  17.         }
  18.  
  19.  
  20. };
  21.  
  22.  
  23. class kolo:public figura{
  24. public:
  25.     kolo():figura(){}
  26.     kolo(const string &kol, const double &a):figura(kol, a){}
  27.     kolo (const kolo &a):figura(*a.kolor, a.liczba){}
  28.  
  29.     kolo &operator=(const kolo &a){
  30.         if(this!=&a){
  31.             kolor = new string(*a.kolor);
  32.             liczba = a.liczba;
  33.         }
  34.         return *this;
  35.     }
  36.  
  37.     ostream &pokaz(ostream &out)const{
  38.     return out << *kolor << " " << liczba << endl;
  39.     }
  40.  
  41.     double pole()const{
  42.     return 3.14 * liczba;
  43.     }
  44.  
  45. };
  46.  
  47.  
  48. class prost:public figura{
  49. protected:
  50.     double liczba2;
  51. public:
  52.     prost():figura(),liczba2(0){}
  53.     prost(const string &kol, const double &a, const double &a2):figura(kol, a),liczba2(a2){}
  54.     prost(const prost &a):figura(*a.kolor, a.liczba),liczba2(a.liczba2){}
  55.  
  56.     prost &operator=(const prost &a){
  57.         if(this!=&a){
  58.             kolor = new string(*a.kolor);
  59.             liczba = a.liczba;
  60.             liczba2 = a.liczba2;
  61.         }
  62.         return *this;
  63.     }
  64.  
  65.     ostream &pokaz(ostream &out)const{
  66.     return out << *kolor << " " << liczba << " " << liczba2 << endl;
  67.     }
  68.  
  69.     double pole()const{
  70.     return liczba * liczba2;
  71.     }
  72.  
  73. };
  74.  
  75. class prostop:public prost{
  76. protected:
  77.     double liczba3;
  78. public:
  79.     prostop():prost(), liczba3(0){}
  80.     prostop(const string &kol, const double &a, const double &a2, const double &a3):prost(kol, a, a2),liczba3(a3){}
  81.     prostop(const prostop &a):prost(*a.kolor, a.liczba, a.liczba2),liczba3(a.liczba3){}
  82.  
  83.     prostop &operator=(const prostop &a){
  84.         if(this!=&a){
  85.             kolor = new string(*a.kolor);
  86.             liczba = a.liczba;
  87.             liczba2 = a.liczba2;
  88.             liczba3 = a.liczba3;
  89.         }
  90.         return *this;
  91.     }
  92.  
  93.     ostream &pokaz(ostream &out)const{
  94.     return out << *kolor << " " << liczba << " " << liczba2 << " " << liczba3 << endl;
  95.     }
  96.  
  97.     double pole()const{
  98.     return liczba * liczba2 * liczba3;
  99.     }
  100.  
  101. };
  102.  
  103.  
  104. int main(){
  105.         figura *tab[5];
  106.         const kolo test1("czarny",100);
  107.         const prostop test2("szarny",2,2,2);
  108.  
  109.         tab[0]=new kolo("czerwony",1);
  110.         tab[1]=new kolo;
  111.         tab[2]=new prost("niebieski",1,1);
  112.         tab[3]=new prostop("Zielony",1,1,1);
  113.         tab[4]=new prostop;
  114.  
  115.         for(int i=0; i<5; ++i)
  116.             cout << tab[i]->pole() << endl;
  117.  
  118.         cout << "********** 3 **********"<< endl;
  119.             return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement