Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. class human{
  4. private:
  5.     char *h;
  6. public:
  7.     human(char *s){
  8.         h = s;
  9.     }
  10.     virtual void eat(){
  11.         printf("Поел %s\n", h);
  12.     }
  13.     virtual ~human();
  14. };
  15.  
  16. class Maxim : public human{
  17. public:
  18.     Maxim(char *s) : human(s){}
  19. };
  20.  
  21. class Sanya : public human{
  22. private:
  23.     int years;
  24. public:
  25.     Sanya(char *n, int y) : human(n){
  26.         years = y;
  27.     }
  28.     int get_years();
  29. };
  30.  
  31. int Sanya::get_years(){
  32.     return years;
  33. }
  34.  
  35. int main() {
  36.     human *as = new Maxim((char*)"Maxim");
  37.     as->eat();
  38.     delete as;
  39.     as = 0;
  40.     human *asd = new Sanya((char*)"228", 13);
  41.     asd->eat();
  42.     printf("%d\n", asd->get_years());
  43.     delete asd;
  44.     asd = 0;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement