AleksandarH

Y1S1 Semester Homework, Soccer Championship

Apr 30th, 2021 (edited)
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.94 KB | None | 0 0
  1. // USED LIBRARIES AND NAMESPACE
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. // CONTAINS ALL NEEDED DATA FOR ONE CONTESTANT
  8. struct Team {
  9.     char teamName[100]{}, teamHometown[100]{};
  10.     int foundedDay{}, foundedMonth{}, foundedYear{}, matchPlayed{}, matchLost{}, goalsFor{}, goalsAgainst{}, goalDifference{}, Points{};
  11. };
  12.  
  13. // COUNTS EACH CONTESTANT ADDED FROM THE addContestant() FUNCTION
  14. void createContestant(Team* T, int& contestantCount, Team newTeam) {
  15.     T[contestantCount] = newTeam;
  16.     contestantCount++;
  17. }
  18.  
  19. // ADDS ONE OR MORE CONTESTANTS TO ARRAY
  20. void addContestant(Team* T, int& contestantCount) {
  21.     Team addContestant;
  22.     string correction;
  23.     cout << "  What is the name of the team?" << endl;
  24.     cout << "  > ";
  25.     cin >> addContestant.teamName;
  26.     cout << "\n  What is " << addContestant.teamName << "'s hometown?" << endl;
  27.     cout << "  > ";
  28.     cin >> addContestant.teamHometown;
  29.     do {
  30.         cout << "\n  What day was " << addContestant.teamName << " founded?" << endl;
  31.         cout << "  > ";
  32.         cin >> addContestant.foundedDay;
  33.         if (addContestant.foundedDay < 1 || addContestant.foundedDay > 31) {
  34.             cout << "______________________________________" << endl;
  35.             cout << "\n   ERROR: Please enter a valid day!" << endl;
  36.             cout << "                1 - 31" << endl;
  37.             cout << "______________________________________" << endl;
  38.         }
  39.     } while (addContestant.foundedDay < 1 || addContestant.foundedDay > 31);
  40.     do {
  41.         cout << "\n  What month was " << addContestant.teamName << " founded?" << endl;
  42.         cout << "  > ";
  43.         cin >> addContestant.foundedMonth;
  44.         if (addContestant.foundedMonth < 1 || addContestant.foundedMonth > 12) {
  45.             cout << "______________________________________" << endl;
  46.             cout << "\n  ERROR: Please enter a valid month!" << endl;
  47.             cout << "                1 - 12" << endl;
  48.             cout << "______________________________________" << endl;
  49.         }
  50.     } while (addContestant.foundedMonth < 1 || addContestant.foundedMonth > 12);
  51.     do {
  52.         cout << "\n  What year was " << addContestant.teamName << " founded?" << endl;
  53.         cout << "  > ";
  54.         cin >> addContestant.foundedYear;
  55.         if (addContestant.foundedYear < 1800 || addContestant.foundedYear > 2021) {
  56.             cout << "______________________________________" << endl;
  57.             cout << "\n  ERROR: Please enter a valid year!" << endl;
  58.             cout << "             1800 - 2021" << endl;
  59.             cout << "______________________________________" << endl;
  60.         }
  61.     } while (addContestant.foundedYear < 1800 || addContestant.foundedYear > 2021);
  62.     createContestant(T, contestantCount, addContestant);
  63. }
  64.  
  65. // GENERATES RANDOM MATCH RESULTS FOR ALL CONTESTANTS IN THE CHAMPIONSHIP
  66. void holdChampionship(Team* T, int& contestantCount) {
  67.     int s1, s2;
  68.     srand(unsigned int(time(NULL)));
  69.     system("cls");
  70.     cout << "|----------------------------------------------------------------|" << endl;
  71.     cout << "                     HOLDING THE CHAMPIONSHIP" << endl;
  72.     cout << "|----------------------------------------------------------------|" << endl << endl;
  73.     for (int i = 0; i < contestantCount - 1; i++) {
  74.         for (int j = i + 1; j < contestantCount; j++) {
  75.             cout << "___________________________________________" << endl;
  76.  
  77.             // T[i] IS HOST, T[j] IS GUEST
  78.             cout << "\n  Team " << T[i].teamName << " vs Team " << T[j].teamName << endl;
  79.  
  80.             // SETS RESULT - UP TO 5 GOALS FOR EACH TEAM
  81.             s1 = rand() % 5;
  82.             s2 = rand() % 5;
  83.  
  84.             // ACCOUNT THE SCORES ON T[i]
  85.             T[i].matchPlayed += 1;
  86.             T[i].goalsFor += s1;
  87.             T[i].goalsAgainst += s2;
  88.  
  89.             // ACCOUNT THE SCORES ON T[j]
  90.             T[j].matchPlayed += 1;
  91.             T[j].goalsFor += s2;
  92.             T[j].goalsAgainst += s1;
  93.  
  94.             T[i].goalDifference += s1 - s2;
  95.             T[j].goalDifference += s2 - s1;
  96.  
  97.             cout << "  Result: (" << T[i].teamName << ") " << s1 << " : " << s2 << " (" << T[j].teamName << ")" << endl;
  98.             if (s1 > s2) {
  99.                 cout << "  " << T[i].teamName << " won the match!" << endl;
  100.                 T[i].Points += 3;
  101.                 T[j].matchLost += 1;
  102.             }
  103.             else if (s2 > s1) {
  104.                 cout << "  " << T[j].teamName << " won the match!" << endl;
  105.                 T[j].Points += 3;
  106.                 T[i].matchLost += 1;
  107.             }
  108.             else {
  109.                 T[i].Points += 1;
  110.                 T[j].Points += 1;
  111.                 cout << "  Match was a tie!" << endl;
  112.             }
  113.  
  114.             ////////// SWITCHING MATCH HOSTS //////////
  115.  
  116.             // T[i] IS HOST, T[j] IS GUEST
  117.             cout << "\n  Team " << T[j].teamName << " vs Team " << T[i].teamName << endl;
  118.  
  119.             // SETS RESULT - UP TO 5 GOALS FOR EACH TEAM
  120.             s1 = rand() % 5;
  121.             s2 = rand() % 5;
  122.  
  123.             // ACCOUNT THE SCORES ON T[j]
  124.             T[j].matchPlayed += 1;
  125.             T[j].goalsFor += s1;
  126.             T[j].goalsAgainst += s2;
  127.  
  128.             // ACCOUNT THE SCORES ON T[i]
  129.             T[i].matchPlayed += 1;
  130.             T[i].goalsFor += s2;
  131.             T[i].goalsAgainst += s1;
  132.  
  133.             T[j].goalDifference += s1 - s2;
  134.             T[i].goalDifference += s2 - s1;
  135.  
  136.             cout << "  Result: (" << T[j].teamName << ") " << s1 << " : " << s2 << " (" << T[i].teamName << ")" << endl;
  137.             if (s1 > s2) {
  138.                 cout << "  " << T[j].teamName << " won the match!" << endl;
  139.                 T[j].Points += 3;
  140.                 T[i].matchLost += 1;
  141.             }
  142.             else if (s2 > s1) {
  143.                 cout << "  " << T[i].teamName << " won the match!" << endl;
  144.                 T[i].Points += 3;
  145.                 T[j].matchLost += 1;
  146.             }
  147.             else {
  148.                 T[j].Points += 1;
  149.                 T[i].Points += 1;
  150.                 cout << "  Match was a tie!" << endl;
  151.             }
  152.         }
  153.     }
  154.     cout << "___________________________________________" << endl << endl;
  155.     system("pause");
  156. }
  157.  
  158. // GENERATES AN ORGANIZED TABLE OF CONTESTANT DATA: NAME, SCORED GOALS, ALLOWED GOALS, WON POINTS
  159. void showContestants(Team* T, int& contestantCount) {
  160.     system("cls");
  161.     cout << "|-------------------------------------------------------------|" << endl;
  162.     cout << "                       CONTESTANTS LIST" << endl;
  163.     cout << "|-------------------------------------------------------------|" << endl << endl;
  164.  
  165.     // FOR LOOP LISTS ALL CONTESTANTS ADDED AND SHOWS ALL OF THE DATA THAT THEY HAVE
  166.     for (int i = 0; i < contestantCount; i++) {
  167.         cout << "  | Name: " << T[i].teamName << "  | Hometown: " << T[i].teamHometown << "  | Founded: " << T[i].foundedDay << "/" << T[i].foundedMonth << "/" << T[i].foundedYear << "y." << "  | Scored Goals: " << T[i].goalsFor << "  | Allowed Goals: " << T[i].goalsAgainst << "  | Goal Difference: " << T[i].goalDifference << "  | Points: " << T[i].Points << "  | Played Matches: " << T[i].matchPlayed << "  | Lost Matches: " << T[i].matchLost << endl << endl;
  168.     }
  169.     system("pause");
  170. }
  171.  
  172. // RUNS A FOR LOOP THAT CALCULATE CONTESTANT FOUNDATION DATES, DISPLAYS THE CONTESTANT WITH THE EARLIEST DATE OF FOUNDATION
  173. // IF ALL CONTESTANTS HAVE THE SAME DATE, IT WILL RETURN ALL OF THEM
  174. void showContestantDate(Team* T, int& contestantCount) {
  175.     int year = 9999;
  176.     int month = 9999;
  177.     int day = 9999;
  178.  
  179.     // FIRST RUN OF THE LOOP SETS THE INTEGERS TO THE CORRESPONDING DATES OF THE FIRST CONTESTANT THAT IS CALLED BY THE LOOP
  180.     // LOOPS AGAIN WITH THE NEXT CONTESTANT IN LINE AND CHECKS IF HIS YEAR IS THE SAME AS THE PREVIOUS CONTESTANT'S YEAR
  181.     // NOTE: IF THE NEXT CONTESTANT'S DAY/MONTH/YEAR IS NOT LOWER THAN THE PREVIOUS ONE, IT WILL SKIP THAT CONTESTANT AND LOOP THE NEXT ONE IN LINE
  182.     // IF THE YEAR DATE MATCHES BOTH CONTESTANTS, IT WILL CHECK IF THE MONTH DATES ARE THE SAME, IF THEY ARE, IT WILL CHECK THE DAYS
  183.     // THE LOOP WILL GO THROUGH EACH SINGLE CONTESTANT TO FIND THE EARLIEST POSSIBLE DATE OF FOUNDATION FOR THAT ONE CONTESTANT
  184.     for (int i = 0; i < contestantCount; i++) {
  185.         if (T[i].foundedYear < year) {
  186.             year = T[i].foundedYear;
  187.         }
  188.         if (T[i].foundedYear == year) {
  189.             if (T[i].foundedMonth < month) {
  190.                 month = T[i].foundedMonth;
  191.             }
  192.             if (T[i].foundedMonth == month) {
  193.                 if (T[i].foundedDay < day) {
  194.                     day = T[i].foundedDay;
  195.                 }
  196.             }
  197.         }
  198.     }
  199.  
  200.     // LOOPS ALL CONTESTANTS IN THE COUNTER
  201.     for (int i = 0; i < contestantCount; i++) {
  202.  
  203.         // if STATEMENT CHECKS FOR INTEGERS day, month, and year IF THEY ARE THE SAME AS ANY OF THE CONTESTANTS' GIVEN DATES
  204.         // WHEN COMPARISON FINISHES AND FINDS THE RIGHT CONTESTANT DATE CORRESPONDING TO THE INTEGERS, IT WILL RETURN THAT CONTESTANT'S DATE
  205.         if (T[i].foundedYear == year && T[i].foundedMonth == month && T[i].foundedDay == day) {
  206.             system("cls");
  207.             cout << "|--------------------------------------------------------------------------------------------|" << endl;
  208.             cout << "                      SHOWING THE TEAM WITH EARLIEST DATE OF FOUNDATION" << endl;
  209.             cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  210.             cout << "  | Team: " << T[i].teamName << " | Founded: " << day << "/" << month << "/" << year << "y." << endl << endl;
  211.             system("pause");
  212.         }
  213.     }
  214. }
  215.  
  216. // RUNS A LOOP THAT GOES THROUGH EACH CONTESTANT IN THE COUNTER, if STATEMENT CHECKS IF THE FIRST CONTESTANT'S LOST MATCHES IS LOWER THAN THE GIVEN "min" INTEGERS' VALUE, WHICH IS 9999 BY DEFAULT
  217. // LOOP GOES AGAIN WITH THE SECOND CONTESTANT IN THE COUNTER AND THE if STATEMENT CHECKS AGAIN, BUT THIS TIME, THE min INTEGER IS WITH A VALUE OF THE PREVIOUS CONTESTANT'S LOST MATCHES
  218. // IF THE NEW CONTESTANT'S VALUE IS LOWER THAN THE "min" INTEGER, IT WILL SET IT AS ITS NEW VALUE
  219. // IF IT'S NOT, IT WILL SKIP THAT CONTESTANT
  220.  
  221. // RESULT IS THE VALUE OF THE CONTESTANT WITH THE LEAST LOST MATCHES
  222.  
  223. // NOTE: FUNCTION WILL SHOW MORE THAN ONE CONTESTANT IF THERE IS MORE THAN ONE WITH THE SAME AMOUNT OF LEAST LOST MATCHES
  224. void showContestantLosses(Team* T, int& contestantCount) {
  225.     int min = 9999;
  226.     for (int i = 0; i < contestantCount; i++) {
  227.         if (T[i].matchLost < min) {
  228.             min = T[i].matchLost;
  229.         }
  230.     }
  231.  
  232.     // LOOP GOES THROUGH EACH CONTESTANT IN THE COUNTER
  233.     for (int i = 0; i < contestantCount; i++) {
  234.  
  235.         // if STATEMENT COMPARES EACH CONTESTANT'S LOST MATCHES VALUE TO THE INTEGER min's VALUE SET FROM THE PREVIOUS LOOP
  236.         // WHEN IT FINDS A MATCH, IT OUTPUTS THAT CONTESTANT'S NAME AND LOST MATCHES COUNT
  237.         if (T[i].matchLost == min) {
  238.             system("cls");
  239.             cout << "|--------------------------------------------------------------------------------------------|" << endl;
  240.             cout << "                         SHOWING THE TEAM WITH THE LEAST LOST MATCHES" << endl;
  241.             cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  242.             cout << "  | Team: " << T[i].teamName << " | Lost Matches: " << T[i].matchLost << endl << endl;
  243.             system("pause");
  244.         }
  245.     }
  246. }
  247.  
  248. // INPUT FROM USER IS CHECKED AND COMPARED TO ALL NAMES OF CONTESTANTS THAT ARE ALREADY IN THE ARRAY, IF NAME IS FOUND, RETURN PLAYED MATCHES FOR THAT CONTESTANT
  249. // IF INPUT IS INCORRECT, RETURN BACK TO main FUNCTION
  250. void searchContestant(Team* T, int& contestantCount) {
  251.     string nameSearch;
  252.     system("cls");
  253.     cout << "|---------------------------------------------------|" << endl;
  254.     cout << "                SEARCHING FOR A TEAM" << endl;
  255.     cout << "|---------------------------------------------------|" << endl << endl;
  256.     cout << "  > Enter team name: ";
  257.     cin >> nameSearch;
  258.     for (int i = 0; i < contestantCount; i++) {
  259.         if (nameSearch == T[i].teamName) {
  260.             system("cls");
  261.             cout << "|---------------------------------------|" << endl;
  262.             cout << "  Showing match data for team (" << nameSearch << ")." << endl;
  263.             cout << "|---------------------------------------|" << endl << endl;
  264.             cout << " The team has " << T[i].matchPlayed << " matches." << endl << endl;
  265.             system("pause");
  266.             break;
  267.         }
  268.     }
  269. }
  270.  
  271. // WORKS THE SAME AS THE showContestantLosses FUNCTION
  272. void goalDifferenceContestant(Team* T, int& contestantCount) {
  273.     int difference = 0;
  274.  
  275.     for (int i = 0; i < contestantCount; i++) {
  276.         if (T[i].goalDifference > difference) {
  277.             difference = T[i].goalDifference;
  278.         }
  279.     }
  280.     for (int i = 0; i < contestantCount; i++) {
  281.         if (T[i].goalDifference == difference) {
  282.             system("cls");
  283.             cout << "|--------------------------------------------------------------------------------------------|" << endl;
  284.             cout << "                       SHOWING THE TEAM WITH THE BIGGEST GOAL DIFFERENCE" << endl;
  285.             cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  286.             cout << "  | Team: " << T[i].teamName << " | Goal Difference: " << T[i].goalDifference << endl << endl;
  287.             system("pause");
  288.         }
  289.     }
  290. }
  291.  
  292. // WORKS THE SAME AS THE showContestantLosses FUNCTION
  293. void mostGoalsContestant(Team* T, int& contestantCount) {
  294.     int goals = 0;
  295.  
  296.     for (int i = 0; i < contestantCount; i++) {
  297.         if (T[i].goalsFor > goals) {
  298.             goals = T[i].goalsFor;
  299.         }
  300.     }
  301.     for (int i = 0; i < contestantCount; i++) {
  302.         if (T[i].goalsFor == goals) {
  303.             system("cls");
  304.             cout << "|--------------------------------------------------------------------------------------------|" << endl;
  305.             cout << "                         SHOWING THE TEAM WITH THE MOST SCORED GOALS" << endl;
  306.             cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  307.             cout << "  | Team: " << T[i].teamName << " | Scored: " << T[i].goalsFor << endl << endl;
  308.             system("pause");
  309.         }
  310.     }
  311. }
  312.  
  313. void sortContestantsByDate(Team* T, int& contestantCount) {
  314.     for (int i = 0; i < contestantCount; i++) {
  315.         for (int j = i + 1; j < contestantCount; j++) {
  316.             if (T[i].foundedYear > T[j].foundedYear) {
  317.                 Team temporary = T[i];
  318.                 T[i] = T[j];
  319.                 T[j] = temporary;
  320.             }
  321.             else if (T[i].foundedYear == T[j].foundedYear && T[i].foundedMonth > T[j].foundedMonth) {
  322.                 Team temporary = T[i];
  323.                 T[i] = T[j];
  324.                 T[j] = temporary;
  325.             }
  326.             else if (T[i].foundedYear == T[j].foundedYear && T[i].foundedMonth == T[j].foundedMonth && T[i].foundedDay > T[j].foundedDay) {
  327.                 Team temporary = T[i];
  328.                 T[i] = T[j];
  329.                 T[j] = temporary;
  330.             }
  331.         }
  332.     }
  333.     system("cls");
  334.     cout << "|--------------------------------------------------------------------------------------------|" << endl;
  335.     cout << "                            SORTING CONTESTANTS BY FOUNDATION DATE" << endl;
  336.     cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  337.     for (int c = 0; c < contestantCount; c++) {
  338.         cout << "  | Team: " << T[c].teamName << " | Founded: " << T[c].foundedDay << "/" << T[c].foundedMonth << "/" << T[c].foundedYear << "y." << endl << endl;
  339.     }
  340. }
  341.  
  342. void sortContestantsByPoints(Team* T, int& contestantCount) {
  343.     int points;
  344.  
  345.     for (int j = 0; j < contestantCount; j++) {
  346.         for (int i = 0; i < contestantCount; i++) {
  347.             if (T[i].Points < T[i + 1].Points) {
  348.                 points = T[i].Points;
  349.                 T[i].Points = T[i + 1].Points;
  350.                 T[i + 1].Points = points;
  351.             }
  352.         }
  353.     }
  354.     system("cls");
  355.     cout << "|--------------------------------------------------------------------------------------------|" << endl;
  356.     cout << "                      SORTING CONTESTANTS BY POINTS WON FROM ALL MATCHES" << endl;
  357.     cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  358.     for (int i = 0; i < contestantCount; i++) {
  359.         cout << "  | Team: " << T[i].teamName << "  | Points: " << T[i].Points << endl << endl;
  360.     }
  361. }
  362.  
  363. void writeBinary(Team* T, int& contestantCount) {
  364.     Team Data;
  365.     fstream File;
  366.     File.open("Data.bin", ios::binary | ios::out);
  367.     if (File.is_open()) {
  368.         File.write((char*)T, sizeof(Team) * contestantCount);
  369.         File.close();
  370.         system("cls");
  371.         cout << "|--------------------------------------------------------------------------------------------|" << endl;
  372.         cout << "                            DATA SUCCESSFULLY SAVED TO BINARY FILE" << endl;
  373.         cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  374.         system("pause");
  375.     }
  376.     else {
  377.         system("cls");
  378.         cout << "|--------------------------------------------------------------------------------------------|" << endl;
  379.         cout << "                                COULD NOT OPEN BINARY DATA FILE" << endl;
  380.         cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  381.         system("pause");
  382.     }
  383. }
  384.  
  385. int readBinary(Team* T) {
  386.     long pos;
  387.     int n = 0;
  388.     Team Data;
  389.     fstream File;
  390.     File.open("Data.bin", ios::binary | ios::in);
  391.     if (!File) {
  392.         system("cls");
  393.         cout << "|--------------------------------------------------------------------------------------------|" << endl;
  394.         cout << "              WE DETECTED THAT YOU DO NOT HAVE ANY DATA SAVED INTO A BINARY FILE" << endl;
  395.         cout << "           THIS IS AN AUTOMATIC TEST THAT IS RAN EVERY TIME THIS PROGRAM IS STARTED" << endl;
  396.         cout << "                       THIS MESSAGE IS SKIPPED IF A BINARY FILE EXISTS" << endl;
  397.         cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  398.         system("pause");
  399.         return n;
  400.     }
  401.     File.seekg(0l, ios::end);
  402.     pos = File.tellg();
  403.     File.close();
  404.     n = pos / (sizeof(Team));
  405.  
  406.     File.open("Data.bin", ios::binary | ios::in);
  407.     if (!File) {
  408.         system("cls");
  409.         cout << "|--------------------------------------------------------------------------------------------|" << endl;
  410.         cout << "                                COULD NOT OPEN BINARY DATA FILE" << endl;
  411.         cout << "|--------------------------------------------------------------------------------------------|" << endl << endl;
  412.         system("pause");
  413.         exit(1);
  414.     }
  415.     for (int i = 0; i < n; i++) {
  416.         File.read((char*)&Data, sizeof(Team));
  417.         T[i] = Data;
  418.     }
  419.     File.close();
  420.     return n;
  421. }
  422.  
  423. int main() {
  424.     Team T[5];
  425.     string choiceAddAnother;
  426.     int choiceMain, choiceAdd, choiceData, choiceShowData, choiceReferenceData, choiceSortData;
  427.     int contestantAdded = readBinary(T);
  428.     do {
  429.         system("cls");
  430.         cout << "|----------------------------------------------------|" << endl;
  431.         cout << "                      MAIN MENU" << endl;
  432.         cout << "|----------------------------------------------------|" << endl << endl;
  433.         cout << "  (1) Add contestant(s)" << endl;
  434.         cout << "  (2) Hold championship" << endl;
  435.         cout << "  (3) View contestant(s) data" << endl;
  436.         cout << "  (4) Save data to binary file" << endl << endl;
  437.         cout << "  (5) EXIT" << endl << endl;
  438.         do {
  439.             cout << "  > Choose an option: ";
  440.             cin >> choiceMain;
  441.         } while (choiceMain < 1 || choiceMain > 5);
  442.         switch (choiceMain) {
  443.         case 1: {
  444.             if (contestantAdded == 5) {
  445.                 system("cls");
  446.                 cout << "|------------------------------------------------------------------|" << endl;
  447.                 cout << "  You have reached the maximum number of allowed team contestants." << endl;
  448.                 cout << "                   You cannot enter more than 5!" << endl;
  449.                 cout << "|------------------------------------------------------------------|" << endl << endl;
  450.                 system("pause");
  451.                 break;
  452.             }
  453.             else {
  454.                 do {
  455.                     system("cls");
  456.                     cout << "|----------------------------------------------------|" << endl;
  457.                     cout << "                   ADD CONTESTANT(S)" << endl;
  458.                     cout << "|----------------------------------------------------|" << endl << endl;
  459.                     cout << "  (1) Add a single contestant" << endl;
  460.                     cout << "  (2) Add multiple contestants" << endl << endl;
  461.                     cout << "  (3) GO BACK" << endl << endl;
  462.                     cout << "  > Choose an option: ";
  463.                     cin >> choiceAdd;
  464.                 } while (choiceAdd < 1 || choiceAdd > 3);
  465.                 switch (choiceAdd) {
  466.                 case 1: {
  467.                     do {
  468.                         system("cls");
  469.                         if (contestantAdded == 0) {
  470.                             cout << "|--------------------------------------------------|" << endl;
  471.                             cout << "  You haven't entered any team contestants so far." << endl;
  472.                             cout << "                  You can enter " << 5 - contestantAdded << "." << endl << endl;
  473.                             cout << "      Entering data for team contestant No" << contestantAdded + 1 << endl;
  474.                             cout << "|--------------------------------------------------|" << endl << endl;
  475.                         }
  476.                         else if (contestantAdded < 5) {
  477.                             cout << "|-----------------------------------------------|" << endl;
  478.                             cout << "  You have entered " << contestantAdded << " team contestant(s) so far." << endl;
  479.                             cout << "              You can enter " << 5 - contestantAdded << " more." << endl << endl;
  480.                             cout << "      Entering data for team contestant No" << contestantAdded + 1 << endl;
  481.                             cout << "|-----------------------------------------------|" << endl << endl;
  482.                         }
  483.                         else {
  484.                             cout << "|------------------------------------------------------------------|" << endl;
  485.                             cout << "  You have reached the maximum number of allowed team contestants." << endl;
  486.                             cout << "                   You cannot enter more than 5!" << endl;
  487.                             cout << "|------------------------------------------------------------------|" << endl << endl;
  488.                             system("pause");
  489.                             break;
  490.                         }
  491.                         addContestant(T, contestantAdded);
  492.                         if (contestantAdded == 5) {
  493.                             system("cls");
  494.                             cout << "|------------------------------------------------------------------|" << endl;
  495.                             cout << "             SUCCESSFULLY ADDED CONTESTANT(S) TO ARRAY" << endl;
  496.                             cout << "  You have reached the maximum number of allowed team contestants." << endl << endl;
  497.                             cout << "                       RETURNING TO MAIN MENU" << endl;
  498.                             cout << "|------------------------------------------------------------------|" << endl << endl;
  499.                             system("pause");
  500.                             break;
  501.                         }
  502.                         else if (contestantAdded < 5) {
  503.                             system("cls");
  504.                             cout << "|------------------------------------------------------------------|" << endl;
  505.                             cout << "             SUCCESSFULLY ADDED CONTESTANT(S) TO ARRAY" << endl;
  506.                             cout << "                     You have " << 5 - contestantAdded << " slot(s) left!" << endl << endl;
  507.                             cout << "              Would you like to add another contestant?" << endl;
  508.                             cout << "       (Y/y) to do so! | Anything else returns to main menu!" << endl;
  509.                             cout << "|------------------------------------------------------------------|" << endl << endl;
  510.                             cout << "  > Your choice: ";
  511.                             cin >> choiceAddAnother;
  512.                         }
  513.                     } while (choiceAddAnother == "Y" || choiceAddAnother == "y");
  514.                     break;
  515.                 }
  516.                 case 2: {
  517.                     do {
  518.                         system("cls");
  519.                         if (contestantAdded == 0) {
  520.                             cout << "|--------------------------------------------------|" << endl;
  521.                             cout << "  You haven't entered any team contestants so far." << endl;
  522.                             cout << "                  You can enter " << 5 - contestantAdded << "." << endl;
  523.                             cout << "|--------------------------------------------------|" << endl << endl;
  524.                         }
  525.                         else if (contestantAdded < 5) {
  526.                             cout << "|-----------------------------------------------|" << endl;
  527.                             cout << "  You have entered " << contestantAdded << " team contestant(s) so far." << endl;
  528.                             cout << "              You can enter " << 5 - contestantAdded << " more." << endl;
  529.                             cout << "|-----------------------------------------------|" << endl << endl;
  530.                         }
  531.                         else {
  532.                             cout << "|------------------------------------------------------------------|" << endl;
  533.                             cout << "  You have reached the maximum number of allowed team contestants." << endl;
  534.                             cout << "                   You cannot enter more than 5!" << endl;
  535.                             cout << "|------------------------------------------------------------------|" << endl << endl;
  536.                             system("pause");
  537.                             break;
  538.                         }
  539.                         int n;
  540.                         do {
  541.                             cout << "  How many contestants would you like to add?" << endl;
  542.                             cout << "  > ";
  543.                             cin >> n;
  544.                             system("cls");
  545.                         } while (n < 1);
  546.                         if (contestantAdded + n > 5) {
  547.                             cout << "|----------------------------------------|" << endl;
  548.                             cout << "  You cannot enter " << n << " team contestants! " << endl;
  549.                             cout << "        You can only enter " << 5 - contestantAdded << " more." << endl;
  550.                             cout << "|----------------------------------------|" << endl << endl;
  551.                             system("pause");
  552.                             break;
  553.                         }
  554.                         for (int i = 0; i < n; i++) {
  555.                             system("cls");
  556.                             if (contestantAdded == 0) {
  557.                                 cout << "|--------------------------------------------------|" << endl;
  558.                                 cout << "  You haven't entered any team contestants so far." << endl;
  559.                                 cout << "                  You can enter " << 5 - contestantAdded << "." << endl << endl;
  560.                                 cout << "      Entering data for team contestant No" << contestantAdded + 1 << endl;
  561.                                 cout << "|--------------------------------------------------|" << endl << endl;
  562.                             }
  563.                             else if (contestantAdded < 5) {
  564.                                 cout << "|-----------------------------------------------|" << endl;
  565.                                 cout << "  You have entered " << contestantAdded << " team contestant(s) so far." << endl;
  566.                                 cout << "              You can enter " << 5 - contestantAdded << " more." << endl << endl;
  567.                                 cout << "      Entering data for team contestant No" << contestantAdded + 1 << endl;
  568.                                 cout << "|-----------------------------------------------|" << endl << endl;
  569.                             }
  570.                             addContestant(T, contestantAdded);
  571.                         }
  572.                         if (contestantAdded == 5) {
  573.                             system("cls");
  574.                             cout << "|------------------------------------------------------------------|" << endl;
  575.                             cout << "             SUCCESSFULLY ADDED CONTESTANT(S) TO ARRAY" << endl;
  576.                             cout << "  You have reached the maximum number of allowed team contestants." << endl << endl;
  577.                             cout << "                       RETURNING TO MAIN MENU" << endl;
  578.                             cout << "|------------------------------------------------------------------|" << endl << endl;
  579.                             system("pause");
  580.                             break;
  581.                         }
  582.                         else if (contestantAdded < 5) {
  583.                             system("cls");
  584.                             cout << "|------------------------------------------------------------------|" << endl;
  585.                             cout << "             SUCCESSFULLY ADDED CONTESTANT(S) TO ARRAY" << endl;
  586.                             cout << "                     You have " << 5 - contestantAdded << " slot(s) left!" << endl << endl;
  587.                             cout << "              Would you like to add another contestant?" << endl;
  588.                             cout << "       (Y/y) to do so! | Anything else returns to main menu!" << endl;
  589.                             cout << "|------------------------------------------------------------------|" << endl << endl;
  590.                             cout << "  > Your choice: ";
  591.                             cin >> choiceAddAnother;
  592.                         }
  593.                     } while (choiceAddAnother == "Y" || choiceAddAnother == "y");
  594.                     break;
  595.                 }
  596.                 case 3: {
  597.                     break;
  598.                 }
  599.                 }
  600.             }
  601.             break;
  602.         }
  603.         case 2: {
  604.             if (contestantAdded < 3) {
  605.                 system("cls");
  606.                 cout << "|----------------------------------------------------------------|" << endl;
  607.                 cout << "  You must enter at least 3 team contestants to use this option." << endl;
  608.                 cout << "                    You have entered " << contestantAdded << " so far." << endl;
  609.                 cout << "|----------------------------------------------------------------|" << endl << endl;
  610.             }
  611.             else {
  612.                 holdChampionship(T, contestantAdded);
  613.             }
  614.             break;
  615.         }
  616.         case 3: {
  617.             if (contestantAdded < 3) {
  618.                 system("cls");
  619.                 cout << "|----------------------------------------------------------------|" << endl;
  620.                 cout << "  You must enter at least 3 team contestants to use this option." << endl;
  621.                 cout << "                    You have entered " << contestantAdded << " so far." << endl;
  622.                 cout << "|----------------------------------------------------------------|" << endl << endl;
  623.                 system("pause");
  624.             }
  625.             else {
  626.                 do {
  627.                     system("cls");
  628.                     cout << "|----------------------------------------------------|" << endl;
  629.                     cout << "                   CONTESTANT DATA" << endl;
  630.                     cout << "|----------------------------------------------------|" << endl << endl;
  631.                     cout << "  (1) Show contestant(s)" << endl;
  632.                     cout << "  (2) Search contestant(s)" << endl;
  633.                     cout << "  (3) Reference contestant(s)" << endl << endl;
  634.                     cout << "  (4) GO BACK" << endl << endl;
  635.                     cout << "  > Choose an option: ";
  636.                     cin >> choiceData;
  637.                 } while (choiceData < 1 || choiceData > 4);
  638.                 switch (choiceData) {
  639.                 case 1: {
  640.                     do {
  641.                         system("cls");
  642.                         cout << "|----------------------------------------------------|" << endl;
  643.                         cout << "                 VIEW CONTESTANT DATA" << endl;
  644.                         cout << "|----------------------------------------------------|" << endl << endl;
  645.                         cout << "  (1) Show contestants" << endl;
  646.                         cout << "  (2) Show contestant (Earliest date of foundation)" << endl;
  647.                         cout << "  (3) Show contestant (Least lost matches)" << endl << endl;
  648.                         cout << "  (4) GO BACK" << endl << endl;
  649.                         cout << "  > Choose an option: ";
  650.                         cin >> choiceShowData;
  651.                     } while (choiceShowData < 1 || choiceShowData > 4);
  652.                     switch (choiceShowData) {
  653.                     case 1: {
  654.                         showContestants(T, contestantAdded);
  655.                         break;
  656.                     }
  657.                     case 2: {
  658.                         showContestantDate(T, contestantAdded);
  659.                         break;
  660.                     }
  661.                     case 3: {
  662.                         showContestantLosses(T, contestantAdded);
  663.                         break;
  664.                     }
  665.                     case 4: {
  666.                         break;
  667.                     }
  668.                     }
  669.                 }
  670.                       break;
  671.                 case 2: {
  672.                     searchContestant(T, contestantAdded);
  673.                     break;
  674.                 }
  675.                 case 3: {
  676.                     do {
  677.                         system("cls");
  678.                         cout << "|----------------------------------------------------|" << endl;
  679.                         cout << "               REFERENCE CONTESTANT DATA" << endl;
  680.                         cout << "|----------------------------------------------------|" << endl << endl;
  681.                         cout << "  (1) Sort contestants" << endl;
  682.                         cout << "  (2) Show contestant (Most scored goals)" << endl;
  683.                         cout << "  (3) Show contestant (Biggest goal difference)" << endl << endl;
  684.                         cout << "  (4) GO BACK" << endl << endl;
  685.                         cout << "  > Choose an option: ";
  686.                         cin >> choiceReferenceData;
  687.                     } while (choiceReferenceData < 1 || choiceReferenceData > 4);
  688.                     switch (choiceReferenceData) {
  689.                     case 1: {
  690.                         do {
  691.                             system("cls");
  692.                             cout << "|----------------------------------------------------|" << endl;
  693.                             cout << "                 SORT CONTESTANTS LIST" << endl;
  694.                             cout << "|----------------------------------------------------|" << endl << endl;
  695.                             cout << "  (1) Sort by foundation date" << endl;
  696.                             cout << "  (2) Sort by points" << endl << endl;
  697.                             cout << "  (3) GO BACK" << endl << endl;
  698.                             cout << "  > Choose an option: ";
  699.                             cin >> choiceSortData;
  700.                         } while (choiceSortData < 1 || choiceSortData > 3);
  701.                         switch (choiceSortData) {
  702.                         case 1: {
  703.                             sortContestantsByDate(T, contestantAdded);
  704.                             system("pause");
  705.                             break;
  706.                         }
  707.                         case 2: {
  708.                             sortContestantsByPoints(T, contestantAdded);
  709.                             system("pause");
  710.                             break;
  711.                         }
  712.                         case 3: {
  713.                             break;
  714.                         }
  715.                         }
  716.                     }
  717.                           break;
  718.                     case 2: {
  719.                         mostGoalsContestant(T, contestantAdded);
  720.                         break;
  721.                     }
  722.                     case 3: {
  723.                         goalDifferenceContestant(T, contestantAdded);
  724.                         break;
  725.                     }
  726.                     case 4: {
  727.                         break;
  728.                     }
  729.                     }
  730.                 }
  731.                 case 4: {
  732.                     break;
  733.                 }
  734.                 }
  735.             }
  736.             break;
  737.         }
  738.         case 4: {
  739.             writeBinary(T, contestantAdded);
  740.             break;
  741.         }
  742.         }
  743.     } while (choiceMain != 5); {
  744.         system("cls");
  745.         cout << "|----------------------------------------------------|" << endl;
  746.         cout << "                   QUITTING PROGRAM" << endl;
  747.         cout << "|----------------------------------------------------|" << endl;
  748.         exit(0);
  749.     }
  750. }
Add Comment
Please, Sign In to add comment