arranged a squash closed tournament of which ten students have been chosen to participate in this prestigious annual event. The ten students will form two teams namely Team A and Team B of five each.
Before the tournament starts, there will be an exhibition game between two students taken at random from Team A and Team B.
As a coordinator of this tournament coupled with your skills in C++ programming, you have a challenge to write a program in C++ that will be able perform the following:
Accept names of ten students in Teams A and B.
Pick one student at random from Team A and one from Team B for the exhibition game.
Pair the Team A and Team B for the main games. Note: Your program should pair students from the two teams at random.
Hint:
Use rand() function for random selection
Use multidimensional arrays to capture your team members
Use user defined functions: You may consider the following:
a function to accept input (Members of both teams),
a function to perform randomizing
a function to select students to play the exhibition game
a function to generate the main games
Code:#include<iostream.h> #include<iomanip.h> #include<string> #include<cstdlib> #include<time.h> void Getnames(char [5][20]); void Display(char [5][20]); char randomize(char [5][20]); void Exhibition(char [5][20]); int main() { cout<<"Polytechnic of Namibia squash tournament "<<endl; char TeamA[5][20], TeamB[5][20], EXgame[5][20]; cout<<"Please enter Team A"<<endl; Getnames(TeamA); cout<<"THE FOLLOWING ARE MEMBERS OF TEAM A "<<endl; Display(TeamA); cout<<endl; cout<<"Please enter Team B"<<endl; Getnames(TeamB); cout<<"THE FOLLOWING ARE MEMBERS OF TEAM B "<<endl; Display(TeamB); cout<<endl; cout<<"the following is an exhibition game "<<endl; Display(TeamA); cout<<" "<<endl; return 0; } void Getnames(char names[5][20]){ for(int i=0; i<5; i++) { cin>>names[i]; } } void Display(char names[5][20]) { for(int i=0; i<5; i++) { cout<<names[i]<<" "<<endl; cout<<" "<<endl; } } void randomiz(void) { char names; names=rand()%5+1; cout<<names; } /*void Exhibition(char t[5][5]) { t[0] = randomize(); for(int i=0; i<5; i++) { t[i] = randomize(); for(int j=0; j<5; j++){ while(t[i]==t[i]){ t[i] = randomize(); } } } }*/