Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ООП_3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- using namespace std;
- class Substance
- {
- int weight;
- char* name;
- char* type;
- public:
- Substance(int _weight, char* _name, char* _type)
- {
- weight = _weight;
- name = _name;
- type = _type;
- }
- void unique_method_Substance()
- {
- cout << "Уникальный метод для класса вещество" << endl;
- }
- void show()
- {
- cout << "Вес: " << weight << endl;
- cout << "название: " << name << endl;
- cout << "тип:" << type << endl;
- }
- virtual ~Substance()
- {
- delete[] type;
- delete[] name;
- cout << "---destruct_Substance---" << endl;
- }
- };
- class Water
- {
- int name_volume;
- public:
- Water(int Volume)
- {
- name_volume = Volume;
- }
- void unique_method_Water()
- {
- cout << "Уникальный метод для класса вода" << endl;
- }
- void show()
- {
- cout << "Объем воды: " << name_volume << endl;
- }
- virtual ~Water()
- {
- cout << "---destruct_Water---" << endl;
- }
- };
- class Solute : public Substance, public Water
- {
- public:
- Solute(int _weight, char* _name, char* _type, int Volume) : Substance(_weight, _name, _type), Water(Volume) {};
- void show()
- {
- Substance::show();
- Water::show();
- }
- void unique_method_Solute()
- {
- cout << "Уникальный метод для класса Раствор" << endl;
- unique_method_Substance();
- unique_method_Water();
- }
- ~Solute()
- {
- cout << "---destruct_Solute---" << endl;
- }
- };
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int i;
- while (1)
- {
- cout << "Выберите цифру:" << endl;
- cout << "1 - Работа с классом вещество" << endl;
- cout << "2 - Работа с классом вода" << endl;
- cout << "3 - Работа с классом раствор" << endl;
- cout << "4 - Выход" << endl;
- cin >> i;
- switch (i)
- {
- case 1:
- {
- int _weight;
- char* _name = new char[10];
- char* _type = new char[20];
- cout << "Введите вес:" << endl;
- cin >> _weight;
- cout << "Введите название вещества:" << endl;
- cin >> _name;
- cout << "Введите тип вещества:" << endl;
- cin >> _type;
- Substance* class_Substance = new Substance(_weight, _name, _type);
- class_Substance->show();
- class_Substance->unique_method_Substance();
- delete class_Substance;
- break;
- }
- case 2:
- {
- int Volume;
- cout << "Введите объем воды:" << endl;
- cin >> Volume;
- Water* class_Water = new Water(Volume);
- class_Water->show();
- class_Water->unique_method_Water();
- delete class_Water;
- break;
- }
- case 3:
- {
- int _weight;
- char* _name = new char[10];
- int Volume;
- char* _type = new char[20];
- cout << "Введите вес раствора:" << endl;
- cin >> _weight;
- cout << "Введите название раствора:" << endl;
- cin >> _name;
- cout << "Введите тип раствора:" << endl;
- cin >> _type;
- cout << "Введите объем раствора:" << endl;
- cin >> Volume;
- Solute* class_Solute = new Solute(_weight, _name, _type, Volume);
- int n;
- while (1)
- {
- cout << "Выберите цифру:" << endl;
- cout << "1 - Работа с методами класса Раствор" << endl;
- cout << "2 - Работа с методами базовых классов Вода и Вещество" << endl;
- cout << "3 - Выход" << endl;
- cin >> n;
- if (n == 3)
- {
- break;
- }
- switch (n)
- {
- case 1:
- {
- class_Solute->show();
- class_Solute->unique_method_Solute();
- break;
- }
- case 2:
- {
- class_Solute->Substance::show();
- class_Solute->Water::show();
- class_Solute->unique_method_Substance();
- class_Solute->unique_method_Water();
- break;
- }
- }
- }
- delete class_Solute;
- break;
- }
- case 4:return 0;
- }
- }
- }
- // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
- // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
- // Советы по началу работы
- // 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
- // 2. В окне Team Explorer можно подключиться к системе управления версиями.
- // 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
- // 4. В окне "Список ошибок" можно просматривать ошибки.
- // 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
- // 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
Add Comment
Please, Sign In to add comment