Talar97

[JPO] Powtorka egzamin 1

Jun 25th, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. //Zad 16
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. class Osoba{
  8. private:
  9.     int rok;
  10.     string * nazwisko;
  11. public:
  12.     Osoba(){
  13.         *nazwisko = "";
  14.         rok = 2000;
  15.     }
  16.    
  17.     Osoba(int r, char * nzw){
  18.         ustawRok(r);
  19.         ustawNazwisko(nzw);
  20.     }
  21.    
  22.     ~Osoba(){
  23.         delete nazwisko;
  24.     }
  25.    
  26.     void ustawRok(int r){
  27.         if(r > 1990 && r < 2018) rok = r;
  28.     }
  29.    
  30.     int zwrocRok(){
  31.         return rok;
  32.     }
  33.    
  34.     void ustawNazwisko(char * nzw){
  35.         nazwisko = new string(nzw);
  36.     }
  37.    
  38.     string zwrocNazwisko(){
  39.         return *nazwisko;
  40.     }
  41. };
  42.  
  43. class Student : public Osoba{
  44. public:
  45.     int nr_albumu;
  46.     Student()
  47.             : Osoba()
  48.     {
  49.         nr_albumu = -1;
  50.     }
  51.    
  52.     Student(int r,  char * nzw, int alb)
  53.             : Osoba(r, nzw)
  54.     {
  55.         nr_albumu = alb;
  56.     }
  57. };
  58.  
  59. int main(){
  60.     Osoba * pan = new Osoba(2000, "Adam");
  61.     Student * studenciak = new Student(1998, "Marcin", 320084);
  62.     pan->ustawRok(1997);
  63.     cout << pan->zwrocNazwisko() << ", " << pan->zwrocRok() << endl;
  64.    
  65.     studenciak->ustawNazwisko("Mariusz");
  66.     cout << studenciak->zwrocNazwisko() << ", " << studenciak->zwrocRok();
  67.    
  68.     return EXIT_SUCCESS;
  69. }
Add Comment
Please, Sign In to add comment