Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Osoba{
  6.     string imie;
  7.     string nazwisko;
  8.     int wiek;
  9.  
  10. public:
  11.     Osoba()
  12.     {
  13.         imie="";
  14.         nazwisko="";
  15.         wiek = 0;          
  16.     }
  17.    
  18.     void Wypisz(){
  19.         cout << imie << " " << nazwisko << endl;
  20.     }
  21.     void set(string i,string n,int w){
  22.         imie = i;
  23.         nazwisko = n;
  24.         wiek = w;
  25.     }
  26.     friend class Ksiazka; //deklaracja przyjaźni
  27.    
  28. };
  29.  
  30. class Ksiazka{
  31.     string tytul;
  32.     Osoba autor;
  33.     int dataWydania;
  34.    
  35. public:
  36.     void wypisz() {
  37.         cout << tytul << " " << autor.imie << " " << autor.nazwisko << " " << dataWydania << endl;
  38.     }
  39.     void set(string t,Osoba a,int d){
  40.         tytul = t;
  41.         autor = a;
  42.         dataWydania = d;
  43.     }
  44. };
  45.  
  46. class Czytelnik : public Osoba{ //klasa Czytelnik dziedziczy publicznie z klasy Osoba
  47.     public:
  48.     Ksiazka tabob[3];
  49.     WypiszKsiazki(){
  50.         for(int i=0;i<3;i++)
  51.         tabob[i].wypisz();
  52.         }
  53. };
  54.  
  55.  
  56. int main()
  57. {
  58.     Osoba autor1,autor2,autor3;
  59.     autor1.set("Daniel","Dw",39);
  60.     autor2.set("Daniel","Dwx",36);
  61.     autor3.set("Daniel","Dwz",30);
  62.     Osoba c1,c2,c3;
  63.     Ksiazka k1,k2,k3,k4,k5;
  64.     k1.set("Elo",autor1,1900);
  65.     k2.set("Elo2",autor2,1999);
  66.     k3.set("Elo3",autor3,2000);
  67.     k4.set("Elo",autor1,1920);
  68.     k5.set("Elo",autor2,1905);
  69.     c1.set("Patrycja","Sniezek",21);
  70.     c2.set("Daniel","Galus",22);
  71.     c3.set("Twoj","Stary",123);
  72.     c1.tabob[0]=k1;
  73.     c1.tabob[1]=k3;
  74.     c1.tabob[2]=k5;
  75.     c2.tabob[0]=k2;
  76.     c2.tabob[1]=k4;
  77.     c2.tabob[2]=k5;
  78.     c3.tabob[0]=k1;
  79.     c3.tabob[1]=k3;
  80.     c3.tabob[2]=k4;
  81.     c1.WypiszKsiazki();
  82.    
  83.    
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement