#include #include #include #include // Константы для размеров массивов const int MAX_ATHLETES = 100; const int MAX_COACHES = 20; const int MAX_JUDGES = 20; const int MAX_COMPETITIONS = 50; const int MAX_ATHLETES_PER_COACH = 10; const int MAX_JUDGES_PER_COMPETITION = 5; const int MAX_COMPETITIONS_PER_JUDGE = 10; const int MAX_RESULTS_PER_COMPETITION = 100; using namespace std; // Структуры данных struct Athlete { string fullName; string rank; int birthYear; string team; string achievements; }; struct Coach { string fullName; string title; Athlete* athletes[MAX_ATHLETES_PER_COACH]; int athletecnt; }; struct Judge { string fullName; string category; string competitions[MAX_COMPETITIONS_PER_JUDGE]; int competitioncnt; }; struct Competition { string date; string status; string venue; Judge* judges[MAX_JUDGES_PER_COMPETITION]; int judgecnt; struct Result { Athlete* athlete; string result; } results[MAX_RESULTS_PER_COMPETITION]; int resultcnt; }; class SportsFederation { private: Athlete athletes[MAX_ATHLETES]; int athletecnt; Coach coaches[MAX_COACHES]; int coachcnt; Judge judges[MAX_JUDGES]; int judgecnt; Competition competitions[MAX_COMPETITIONS]; int competitioncnt; void loadAthletes() { ifstream file("Спортсмены.txt"); athletecnt = 0; if (file.is_open()) { while (file >> athletes[athletecnt].fullName >> athletes[athletecnt].rank >> athletes[athletecnt].birthYear >> athletes[athletecnt].team >> athletes[athletecnt].achievements) { athletecnt++; } file.close(); } } void loadCoaches() { ifstream file("Тренеры.txt"); coachcnt = 0; if (file.is_open()) { while (file >> coaches[coachcnt].fullName >> coaches[coachcnt].title) { coaches[coachcnt].athletecnt = 0; string athleteName; while (file >> athleteName) { for (int i = 0; i < athletecnt; ++i) { if (athletes[i].fullName == athleteName) { coaches[coachcnt].athletes[coaches[coachcnt].athletecnt++] = &athletes[i]; break; } } } coachcnt++; } file.close(); } } void loadJudges() { ifstream file("Судьи.txt"); judgecnt = 0; if (file.is_open()) { while (file >> judges[judgecnt].fullName >> judges[judgecnt].category) { judges[judgecnt].competitioncnt = 0; while (file >> judges[judgecnt].competitions[judges[judgecnt].competitioncnt]) { judges[judgecnt].competitioncnt++; } judgecnt++; } file.close(); } } void saveAthletes() { ofstream file("Спортсмены.txt"); if (file.is_open()) { for (int i = 0; i < athletecnt; ++i) { file << athletes[i].fullName << " " << athletes[i].rank << " " << athletes[i].birthYear << " " << athletes[i].team << " " << athletes[i].achievements << endl; } file.close(); } } void saveCoaches() { ofstream file("Тренеры.txt"); if (file.is_open()) { for (int i = 0; i < coachcnt; ++i) { file << coaches[i].fullName << " " << coaches[i].title; for (int j = 0; j < coaches[i].athletecnt; ++j) { file << " " << coaches[i].athletes[j]->fullName; } file << endl; } file.close(); } } void saveJudges() { ofstream file("Судьи.txt"); if (file.is_open()) { for (int i = 0; i < judgecnt; ++i) { file << judges[i].fullName << " " << judges[i].category; for (int j = 0; j < judges[i].competitioncnt; ++j) { file << " " << judges[i].competitions[j]; } file << endl; } file.close(); } } public: SportsFederation() : athletecnt(0), coachcnt(0), judgecnt(0), competitioncnt(0) { loadAthletes(); loadCoaches(); loadJudges(); } void addAthlete(const Athlete& athlete) { if (athletecnt < MAX_ATHLETES) { athletes[athletecnt++] = athlete; saveAthletes(); } } void addAthlete() { Athlete athlete; cout << "Введите ФИО спортсмена: "; cin.ignore(); getline(cin, athlete.fullName); cout << "Введите разряд спортсмена: "; getline(cin, athlete.rank); cout << "Введите год рождения спортсмена: "; cin >> athlete.birthYear; cout << "Введите команду спортсмена: "; cin.ignore(); getline(cin, athlete.team); cout << "Введите достижения спортсмена: "; getline(cin, athlete.achievements); addAthlete(athlete); } void removeAthlete(const string& fullName) { for (int i = 0; i < athletecnt; ++i) { if (athletes[i].fullName == fullName) { for (int j = i; j < athletecnt - 1; ++j) { athletes[j] = athletes[j + 1]; } athletecnt--; saveAthletes(); break; } } } void removeAthlete() { string fullName; cout << "Введите ФИО спортсмена для удаления: "; cin.ignore(); getline(cin, fullName); removeAthlete(fullName); } void addCoach(const Coach& coach) { if (coachcnt < MAX_COACHES) { coaches[coachcnt++] = coach; saveCoaches(); } } void addCoach() { Coach coach; cout << "Введите ФИО тренера: "; cin.ignore(); getline(cin, coach.fullName); cout << "Введите звание тренера: "; getline(cin, coach.title); coach.athletecnt = 0; cout << "Введите количество спортсменов тренера: "; int c; // cout << "123"; int cnt; cin >> cnt; cin.ignore(); for (int i = 0; i < cnt; ++i) { string athleteName; cout << "Введите ФИО спортсмена: "; cout << "wqe"; getline(cin, athleteName); for (int j = 0; j < athletecnt; ++j) { if (athletes[j].fullName == athleteName) { coach.athletes[coach.athletecnt++] = &athletes[j]; break; } } } addCoach(coach); } void removeCoach(const string& fullName) { for (int i = 0; i < coachcnt; ++i) { if (coaches[i].fullName == fullName) { for (int j = i; j < coachcnt - 1; ++j) { coaches[j] = coaches[j + 1]; } coachcnt--; saveCoaches(); break; } } } void removeCoach() { string fullName; cout << "Введите ФИО тренера для удаления: "; cin.ignore(); getline(cin, fullName); removeCoach(fullName); } void addJudge(const Judge& judge) { if (judgecnt < MAX_JUDGES) { judges[judgecnt++] = judge; saveJudges(); } } void addJudge() { Judge judge; cout << "Введите ФИО судьи: "; cin.ignore(); getline(cin, judge.fullName); cout << "Введите категорию судьи: "; getline(cin, judge.category); judge.competitioncnt = 0; cout << "Введите количество проведённых соревнований: "; int cnt; cin >> cnt; cin.ignore(); for (int i = 0; i < cnt; ++i) { cout << "Введите название соревнования: "; getline(cin, judge.competitions[judge.competitioncnt++]); } addJudge(judge); } void removeJudge(const string& fullName) { for (int i = 0; i < judgecnt; ++i) { if (judges[i].fullName == fullName) { for (int j = i; j < judgecnt - 1; ++j) { judges[j] = judges[j + 1]; } judgecnt--; saveJudges(); break; } } } void removeJudge() { string fullName; cout << "Введите ФИО судьи для удаления: "; cin.ignore(); getline(cin, fullName); removeJudge(fullName); } void addCompetition(const Competition& competition) { if (competitioncnt < MAX_COMPETITIONS) { competitions[competitioncnt++] = competition; } } void addCompetition() { Competition competition; cout << "Введите дату соревнования: "; cin.ignore(); getline(cin, competition.date); cout << "Введите статус соревнования: "; getline(cin, competition.status); cout << "Введите место проведения соревнования: "; getline(cin, competition.venue); competition.judgecnt = 0; cout << "Введите количество судей: "; int cnt; cin >> cnt; cin.ignore(); for (int i = 0; i < cnt; ++i) { string judgeName; cout << "Введите ФИО судьи: "; getline(cin, judgeName); for (int j = 0; j < judgecnt; ++j) { if (judges[j].fullName == judgeName) { competition.judges[competition.judgecnt++] = &judges[j]; break; } } } addCompetition(competition); } void createCompetitionResults(const string& competitionDate) { for (int i = 0; i < competitioncnt; ++i) { if (competitions[i].date == competitionDate) { competitions[i].resultcnt = 0; for (int j = 0; j < athletecnt; ++j) { if (competitions[i].resultcnt < MAX_RESULTS_PER_COMPETITION) { competitions[i].results[competitions[i].resultcnt].athlete = &athletes[j]; competitions[i].results[competitions[i].resultcnt].result = "Результат"; competitions[i].resultcnt++; } } break; } } } void createCompetitionResults() { string date; cout << "Введите дату соревнования для создания результатов: "; cin.ignore(); getline(cin, date); createCompetitionResults(date); } void updateAthleteAchievements(const string& competitionDate) { for (int i = 0; i < competitioncnt; ++i) { if (competitions[i].date == competitionDate) { for (int j = 0; j < competitions[i].resultcnt; ++j) { Athlete* athlete = competitions[i].results[j].athlete; if (!athlete->achievements.empty()) { athlete->achievements += ", "; } athlete->achievements += competitions[i].results[j].result; } saveAthletes(); break; } } } void updateAthleteAchievements() { string date; cout << "Введите дату соревнования для обновления достижений спортсменов: "; cin.ignore(); getline(cin, date); updateAthleteAchievements(date); } void printCoachAchievements() { for (int i = 0; i < coachcnt; ++i) { cout << coaches[i].fullName << " (" << coaches[i].title << "):" << endl; for (int j = 0; j < coaches[i].athletecnt; ++j) { cout << " " << coaches[i].athletes[j]->fullName << " - " << coaches[i].athletes[j]->achievements << endl; } } } }; void printMenu() { cout << "Меню:\n"; cout << "1. Добавить спортсмена\n"; cout << "2. Удалить спортсмена\n"; cout << "3. Добавить тренера\n"; cout << "4. Удалить тренера\n"; cout << "5. Добавить судью\n"; cout << "6. Удалить судью\n"; cout << "7. Добавить соревнование\n"; cout << "8. Создать результаты соревнования\n"; cout << "9. Обновить достижения спортсменов\n"; cout << "10. Показать достижения тренеров\n"; cout << "0. Выход\n"; } int main() { SportsFederation federation; int choice; cout << 123 << endl; do { printMenu(); cin >> choice; switch (choice) { case 1: federation.addAthlete(); break; case 2: federation.removeAthlete(); break; case 3: federation.addCoach(); break; case 4: federation.removeCoach(); break; case 5: federation.addJudge(); break; case 6: federation.removeJudge(); break; case 7: federation.addCompetition(); break; case 8: federation.createCompetitionResults(); break; case 9: federation.updateAthleteAchievements(); break; case 10: federation.printCoachAchievements(); break; case 0: cout << "Выход...\n"; break; default: cout << "Неверный выбор. Попробуйте снова.\n"; break; } } while (choice != 0); return 0; }