Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NOMINMAX
- #include <windows.h>
- #include <iostream>
- #include <string>
- #include <limits>
- #include <fstream>
- #include <sstream>
- #include <vector>
- using namespace std;
- struct Coach;
- struct Gym
- {
- string name;
- vector<Coach*> coaches;
- };
- struct Coach
- {
- string name;
- vector<Gym*> gyms;
- };
- void make_relation(vector<Gym>& gyms, vector<Coach>& coaches) {
- system("cls");
- if (coaches.empty()) {
- cout << "Нет тренеров для связи.\n";
- system("pause");
- system("cls");
- return;
- }
- if (gyms.empty()) {
- cout << "Нет залов для связи.\n";
- system("pause");
- system("cls");
- return;
- }
- int indx = 0;
- for (auto& i : coaches)
- {
- cout << indx + 1 << ". " << i.name << '\n';
- indx++;
- }
- int coach_indx = 0;
- while (true) {
- cout << "Выберите тренера для связи: ";
- if (cin >> coach_indx and coach_indx > 0 and coach_indx <= coaches.size()) {
- break;
- }
- else {
- cout << "Неверный ввод. Попробуйте снова.\n";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- indx = 0;
- for (auto& i : gyms)
- {
- cout << indx + 1 << ". " << i.name << '\n';
- indx++;
- }
- int gym_indx = 0;
- while (true) {
- cout << "Выберите зал для связи: ";
- if (cin >> gym_indx and gym_indx > 0 and gym_indx <= gyms.size()) {
- break;
- }
- else {
- cout << "Неверный ввод. Попробуйте снова.\n";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- gyms[gym_indx - 1].coaches.push_back(&coaches[coach_indx - 1]);
- coaches[coach_indx - 1].gyms.push_back(&gyms[gym_indx - 1]);
- system("cls");
- }
- void add_coach(vector<Coach>& coaches) {
- system("cls");
- Coach new_coach;
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- cout << "Введите имя тренера: ";
- string name;
- getline(cin, name);
- new_coach.name = name;
- coaches.push_back(new_coach);
- system("cls");
- }
- void add_gym(vector<Gym>& gyms) {
- system("cls");
- Gym new_gym;
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- cout << "Введите название зала: ";
- string name;
- getline(cin, name);
- new_gym.name = name;
- gyms.push_back(new_gym);
- system("cls");
- }
- void list_gyms(const vector<Gym>& gyms) {
- system("cls");
- if (gyms.empty()) {
- cout << "Список залов пуст.\n";
- }
- else {
- for (const auto& gym : gyms) {
- cout << gym.name << '\n';
- }
- }
- system("pause");
- system("cls");
- }
- void list_coaches(const vector<Coach>& coaches) {
- system("cls");
- if (coaches.empty()) {
- cout << "Список тренеров пуст.\n";
- }
- else {
- for (const auto& coach : coaches) {
- cout << coach.name << '\n';
- }
- }
- system("pause");
- system("cls");
- }
- void list_coaches_in_gym(const vector<Gym>& gyms) {
- system("cls");
- if (gyms.empty()) {
- cout << "Список залов пуст.\n";
- system("pause");
- system("cls");
- return;
- }
- int indx = 0;
- for (const auto& gym : gyms) {
- cout << indx + 1 << ". " << gym.name << '\n';
- indx++;
- }
- int gym_indx = 0;
- while (true) {
- cout << "Выберите зал для отображения тренеров: ";
- if (cin >> gym_indx and gym_indx > 0 and gym_indx <= gyms.size()) {
- break;
- }
- else {
- cout << "Неверный ввод. Попробуйте снова.\n";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- system("cls");
- if (gyms[gym_indx - 1].coaches.empty()) {
- cout << "В этом зале нет тренеров.\n";
- }
- else {
- for (const auto& coach : gyms[gym_indx - 1].coaches) {
- cout << coach->name << '\n';
- }
- }
- system("pause");
- system("cls");
- }
- void list_gyms_of_coach(const vector<Coach>& coaches) {
- system("cls");
- if (coaches.empty()) {
- cout << "Список тренеров пуст.\n";
- system("pause");
- system("cls");
- return;
- }
- int indx = 0;
- for (const auto& coach : coaches) {
- cout << indx + 1 << ". " << coach.name << '\n';
- indx++;
- }
- int coach_indx = 0;
- while (true) {
- cout << "Выберите тренера для отображения залов: ";
- if (cin >> coach_indx and coach_indx > 0 and coach_indx <= coaches.size()) {
- break;
- }
- else {
- cout << "Неверный ввод. Попробуйте снова.\n";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- system("cls");
- if (coaches[coach_indx - 1].gyms.empty()) {
- cout << "У этого тренера нет залов.\n";
- }
- else {
- for (const auto& gym : coaches[coach_indx - 1].gyms) {
- cout << gym->name << '\n';
- }
- }
- system("pause");
- system("cls");
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- setlocale(LC_ALL, "Russian");
- vector<Gym> my_gyms;
- vector<Coach> my_coaches;
- while (true)
- {
- cout << "--------------------\n";
- cout << "Выберите один из пунктов меню\n";
- cout << "1) Создать связь\n"
- << "2) Добавить тренера\n"
- << "3) Добавить зал\n"
- << "4) Список залов\n"
- << "5) Список тренеров\n"
- << "6) Вывести всех тренеров из зала\n"
- << "7) Вывести все залы тренера\n"
- << "8) Закончить программу\n"
- << "Введите нужный пункт меню: ";
- int answer;
- while (true) {
- if (cin >> answer and answer > 0 and answer <= 8) {
- break;
- }
- else {
- cout << "Неверный ввод. Попробуйте снова.\n";
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }
- switch (answer)
- {
- case 1: {
- make_relation(my_gyms, my_coaches);
- break;
- }
- case 2: {
- add_coach(my_coaches);
- break;
- }
- case 3: {
- add_gym(my_gyms);
- break;
- }
- case 4: {
- list_gyms(my_gyms);
- break;
- }
- case 5: {
- list_coaches(my_coaches);
- break;
- }
- case 6: {
- list_coaches_in_gym(my_gyms);
- break;
- }
- case 7: {
- list_gyms_of_coach(my_coaches);
- break;
- }
- case 8: {
- return 0;
- }
- default:
- cout << "Неверный пункт меню, попробуйте снова.\n";
- system("pause");
- system("cls");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement