Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int LEN = 80;
- class instrument{
- private:
- char name[LEN];
- char prois[LEN];
- char type[LEN];
- public:
- virtual void get_name() {
- cout << "Инструмент\n";
- }
- void getdata() {
- cout << "\n Введите фамилию владельца инструмента: "; cin >> name;
- cout << "\n Производитель инструмента: "; cin >> prois;
- }
- void putdata() const {
- cout << "\n Фамилия: " << name;
- cout << "\n Производитель инструмента: " << prois;
- }
- };
- class Kick : public instrument{
- void get_name() {
- cout << "Ударный\n";
- }
- };
- class String : public instrument{
- private:
- int kolvo; // кол-во струн
- public:
- void get_name() {
- cout << "Струнный\n";
- }
- void getdata(){
- instrument::getdata();
- cout << "\n Количество струн: "; cin >> kolvo;
- }
- void putdata() const {
- instrument::putdata();
- cout << "\n Количество струн: " << kolvo;
- }
- };
- class Horn : public instrument{
- private:
- char lenghtcanal[LEN]; // длина канала
- public:
- void get_name() {
- cout << "Духовой\n";
- }
- void getdata(){
- instrument::getdata();
- cout << "\n Длина канала духового инструмента: "; cin >> lenghtcanal;
- }
- void putdata() const {
- instrument::putdata();
- cout << "\n Длина канала духового инструмента: " << lenghtcanal;
- }
- };
- int main(){
- system("chcp 1251");
- system("cls");
- instrument* o[2];//массив указателей
- o[0] = new Horn();//создаём объект
- o[1] = new String();
- o[0]->get_name();
- o[1]->get_name();
- int n,choice;
- cout << "Введите размер оркестра";
- cin >> n;
- instrument* or = new instrument[n];
- for (int i = 0; i < n; i++)
- {
- cout << "Выберите тип инструмента:\n1-Ударный\n2-струнный\n3-духовой"<<endl;
- cin >> choice;
- switch (choice){
- case 1:or[i] =new Kick();
- or[i]->get_name();
- break;
- case 2:or[i] = new String();
- or[i]->get_name();
- break;
- case 3:or[i] = new Horn();
- or[i]->get_name();
- break;
- }
- }
- system("pause");
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement