Facebook
From fdsfds, 2 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 112
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Person
  8. {
  9. private:
  10.     string imie;
  11.     string nazwisko;
  12.     string pesel;
  13.  
  14. public:
  15.     Person(string imie = "", string nazwisko = "", string pesel = "")
  16.         : imie(imie), nazwisko(nazwisko), pesel(pesel) {}
  17.  
  18.     string get_imie() const {
  19.         return imie;
  20.     }
  21.  
  22.     string get_nazwisko() const {
  23.         return nazwisko;
  24.     }
  25.  
  26.     string get_pesel() const {
  27.         return pesel;
  28.     }
  29.  
  30.     string to_string() const {
  31.         return "Osoba: " + imie + " " + nazwisko + ", Pesel: " + pesel;
  32.     }
  33. };
  34.  
  35. class Student : public Person
  36. {
  37. private:
  38.     string nr_indeksu;
  39.     string kierunek_studiow;
  40.  
  41. public:
  42.     Student(string imie, string nazwisko, string pesel, string nr_indeksu, string kierunek_studiow)
  43.         : Person(imie, nazwisko, pesel), nr_indeksu(nr_indeksu), kierunek_studiow(kierunek_studiow) {}
  44.     string to_string() const {
  45.         return "Student: " + get_imie() + " " + get_nazwisko() + ", Pesel: " + get_pesel() +
  46.                ", Nr indeksu: " + nr_indeksu + ", Kierunek studiow: " + kierunek_studiow;
  47.     }
  48. };
  49. ostream& operator<< ( ostream& out, const Student& wyjscie )
  50. {
  51. out << wyjscie.to_string();
  52. return out;
  53. }
  54.  
  55. int main()
  56. {
  57.     vector <Person*> osoby;
  58.    
  59.     osoby.push_back(new Person("Jan", "Kowalski", "7423764234"));
  60.     osoby.push_back(new Student("Jan", "Kowalski", "7423764234", "74632", "Elektronika"));
  61.        
  62.     Student student("Jan", "Kowalski", "75295732983", "75834", "Elektronika");
  63.    
  64.     cout << student.to_string() << endl;
  65. }
  66.