Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <string>
  4.  
  5. /*zad1 - TOsoba*/
  6.  
  7. using namespace std;
  8.  
  9. class TAdres{
  10.             private:
  11.                     string miasto;
  12.                     string ulica;
  13.                     int numer;
  14.             public:
  15.                     TAdres(string city, string street, int nr);
  16.                     void Wyswietl();
  17.                     ~TAdres();
  18. };
  19.  
  20. class TOsoba{
  21.             protected:
  22.                     string imie;
  23.                     string nazwisko;
  24.                     int wiek;
  25.                     TAdres adres;
  26.             public:
  27.                     TOsoba(string name, string surname, int age, string city, string street, int nr):adres(city, street, nr)
  28.                     {
  29.                             imie = name;
  30.                             nazwisko = surname;
  31.                             wiek = age;
  32.                             cout<<"Zostal wywolany konstruktor TOsoba!"<<endl;
  33.                                    
  34.                     }
  35.                     virtual void Wyswietl() = 0;/*{
  36.                         cout<<imie<<" "<<nazwisko<<"  lat "<<wiek<<","<<endl;
  37.                         cout<<"adres: ";
  38.                         adres.Wyswietl();
  39.                         cout<<endl;
  40.                     }*/
  41.                     string PodajImie(){
  42.                        
  43.                         return imie;
  44.                     }
  45.                     string PodajNazwisko(){
  46.                         return nazwisko;
  47.                     }
  48.                     ~TOsoba(){
  49.                         cout<<"Wywolalismy destruktor TOsoba!"<<endl;
  50.                     }
  51. };
  52.  
  53. class TStudent: public TOsoba{
  54.               private:
  55.                       string kierunek;
  56.                       int rok;
  57.               public:
  58.                       TStudent(string name, string surname, int age, string city, string street, int nr, string kier, int year):TOsoba(name, surname, age, city, street, nr){
  59.                         kierunek = kier;
  60.                         rok = year;
  61.                         cout<<""<<endl;
  62.                         cout<<"Zostal wywolany konstruktor TStudent!"<<endl;
  63.                        
  64.                       }
  65.                       virtual void Wyswietl(){
  66.                             cout<<imie<<" "<<nazwisko<<"  lat "<<wiek<<","<<endl;
  67.                             cout<<"adres: ";
  68.                             adres.Wyswietl();
  69.                             cout<<"kierunek studiow: "<<kierunek<<", rok: "<<rok<<endl;
  70.                             cout<<endl;
  71.                       }
  72.                       string PodajKierunek(){
  73.                             return kierunek;
  74.                       }
  75.                       ~TStudent(){
  76.                             cout<<"Zostal wywolany destruktor TStudent!"<<endl;
  77.                       }
  78.                      
  79. };
  80.  
  81. TAdres::TAdres(string city, string street, int nr){
  82.     miasto = city;
  83.     ulica = street;
  84.     numer = nr;
  85.     cout<<"Zostal wywolany konstruktor TAdres!"<<endl;
  86. }
  87.  
  88. void TAdres::Wyswietl(){
  89.    
  90.     cout<<miasto<<" "<<"ul."<<ulica<<" "<<numer<<endl;
  91.     return;
  92. }
  93.  
  94. TAdres::~TAdres(){
  95.    
  96.     cout<<"Wywolalismy destruktor TAdres!"<<endl;
  97. }
  98.  
  99. //**********************************************
  100.  
  101.  
  102. int main() {
  103.  
  104. TStudent st("Justyna", "Lachowska", 20, "Rejowiec", "Fabryczna", 12, "informatyka", 2);
  105. st.Wyswietl();
  106.  
  107. TOsoba *wskaznik = new TStudent("Gosia", "Lesczuk", 21, "Lublin", "Romantyczna", 15, "informatyka", 2);
  108. wskaznik->Wyswietl();
  109. TOsoba &os = st;
  110. os.Wyswietl();
  111.  
  112.  
  113.  
  114.  
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement