Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / C++.Ашарина / !Сделанные / Наследование / var12 / Сделанная!!!!!!!!!!!!
.txt#include <iostream.h>
#include <stdlib.h>
class Voin
{
public:
int age;
char *gun;
Voin(){
gun=new char[10];
age=rand();
gun="kulak";
}
virtual Printage(){cout<<"age "<<age<<endl;}
virtual Printgun(){
cout<<"gun "<<gun<<endl<<endl;
}
};
class Pehota:public Voin{
public:
Pehota(){
age=rand()/100;
gun="vintovka";
}
Printage(){cout<<"age "<<age<<endl;}
Printgun(){cout<<"gun "<<gun<<endl<<endl;}
};
class Matros:public Voin{
public:
Matros(){
age=rand()/100;
gun="kortik";
}
Printage(){cout<<"age "<<age<<endl;}
Printgun(){cout<<"gun "<<gun<<endl<<endl;}
};
void main()
{
Voin *A=new Voin;
Pehota *B=new Pehota;
Matros *C=new Matros;
A->Printage();
A->Printgun();
B->Printage();
B->Printgun();
C->Printage();
C->Printgun();
}