fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class osoba{
  6. protected:
  7. string* imie;
  8. string nazwisko;
  9. public:
  10. osoba():imie(new string("brak ")),nazwisko("brak"){}
  11. osoba(const string& a1,const string& a2):imie(new string(a1)),nazwisko(a2){}
  12. osoba(const osoba& ob):imie(new string(*ob.imie)),nazwisko(ob.nazwisko){}
  13. virtual ostream& wypisz(ostream& out){out << *imie << " " << nazwisko;}
  14. friend ostream& operator<<(ostream& out,osoba& ob){out << ob.wypisz(out);}
  15. virtual ~osoba(){delete imie;}
  16. };
  17. class student:public osoba{
  18. string kierunek;
  19. unsigned rok;
  20. public:
  21. student():osoba(){}
  22. student(const osoba& ob):osoba(ob){}
  23. student(const osoba& ob,const string& a1,const unsigned& a2):osoba(ob),kierunek(a1),rok(a2){}
  24. ostream& wypisz(ostream& out){out << *imie << " " << nazwisko << " " << kierunek << " " << rok << endl;}
  25. };
  26. //osoba::ktory = 0;
  27. int main()
  28. {
  29. const osoba o1("Jan", "Kowalski");
  30. const osoba o2("Ewa", "Nowak");
  31.  
  32. osoba* tab[5];
  33.  
  34. tab[0] = new osoba;
  35. tab[1] = new student;
  36. tab[2] = new osoba("Ala", "Kot");
  37. tab[3] = new student(o1);
  38. tab[4] = new student(o2, "Informatyka",3);
  39.  
  40. for(int i = 0; i < 5; i++)
  41. try
  42. {
  43. cout << *tab[i] << endl;
  44. }
  45. catch (const string& err)
  46. {
  47. cerr << err << endl;
  48. }
  49.  
  50. cout << "**********" << endl;
  51.  
  52. return 0;
  53. }
Runtime error #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
Standard output is empty