Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose: To practice the use of a vector and the vector functions: Specification

ID: 3791501 • Letter: P

Question

Purpose: To practice the use of a vector and the vector functions: Specifications: This program will allow the user to see a list of teams, add a team to the list, or search for a team using an ID.

1. Structure Definition

First define struct TeamS with an integer field to hold an ID, and an array of strings with three elements to hold the names of the team members. In the main function, declare an empty vector of TeamV and also the following arrays: const int ID [NUM_TEAMS] ={ 123, 321, 456, 789}; const string MEMBERS [NUM_TEAMS] [NUM_MEMBERS ] = { {"Sarah", "Joe", "John"}, {"Chris", "Kevin", "James"}, {"Tom", "Kim", "Emily"}, {"Jill", "Jason", "Jim"} };

2. Creating the vector

Call a function with the following prototype and pass in the empty vector and the arrays: void Initialize (vector & TeamV, const int id[], const string m[][NUM_MEMBERS], int arraySize); The function should place into the vector the elements of the arrays. For example, the first element of the vector will have team id: 123 and members: Sarah, Joe, and John. The second element of the vector will have team id: 321 and members: Chris, Kevin, and James, and so on.

3. The print function

Back in main, call a function with the following prototype to show that your vector has been populated with the team information: void printList (const vector & TeamV); The function simply prints out the content of the vector.

4. The menu Function

Next, places a loop in your main function such that in each iteration the user sees a menu and has the chance to enter a choice. Call a function with the following prototype to display the menu: void menu(); If the users select option 1, call the printList function to display the list. 5. Adding to a vector If the user selects option 2, call a function with the following prototype which will allow the user to enter the information for a team which will be added to your team vector: void add (vector & TeamV);

6. Searching a Vector

If the user selects option 3, ask for the ID the user wants to search for and call a function with the following prototype which will perform a search on your vector and return the index of the element with the matching ID or -1 if no match is found:

int search(const vector & TeamV, int id ); Make sure that this function performs a linear search.

7. Displaying one vector entry In the search function, printout the information of the team with the matching ID In main, use the return value of the function to determine if an error message is to be displayed if no matching ID is found.

8. Ending the program If the user selects option 4, stop the program.

Display the following message: Lab X written by XXXXXX has ended. Where XXXXXX is your First and Last name. For full credit make sure that you implement the program following all the directions above and don’t add, modify, or delete any part. Use the sample output as a guide for how your program should look when it is running. All information in the C++ ProgrammingStandardsAndBestPractices.docx should be followed

Explanation / Answer

// Example program
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define NUM_TEAMS 4
#define NUM_MEMBERS 4


struct TeamS{
int ID;
string teamMembers[3];

};


/*void Initialize(vector<TeamS> *teamSVector, int id[], string m[][NUM_MEMBERS], int arraySize){
TeamS* teams;
for(int i = 0 ; i < sizeof(id); i++){
teams->ID = id[i];
for( int j = 0 ; j < arraySize ; j++){
for( int k =0; k < arraySize ; k++){
teams->teamMembers[i] = m[j][k];   
}
}
teamStruct.push_back(teams);
}
}*/

int main()
{
/*string name;
cout << "What is your name? ";
getline (cin, name);
cout << "Hello, " << name << "! "; */
  
vector<TeamS> teamSVector;
int ID [NUM_TEAMS] ={ 123, 321, 456, 789};
string MEMBERS[NUM_TEAMS][NUM_MEMBERS ] = { {"Sarah", "Joe", "John"}, {"Chris", "Kevin", "James"}, {"Tom", "Kim", "Emily"}, {"Jill", "Jason", "Jim"} };
  
//Initialize( teamSVector , ID , MEMBERS , 3);
cout << "hello" ;
TeamS* t = new TeamS;
for(int i = 0 ; i < sizeof(ID); i++){
cout << ID[i];
t->ID = ID[i];
for( int j = 0 ; j < 4 ; j++){
for( int k =0; k < 4 ; k++){
t->teamMembers[i] = MEMBERS[j][k];
cout << t->teamMembers[i];
}
}
teamSVector.push_back(*t);
}
  
cout << int(teamSVector.size()) << endl;
  
/*for(int i = 0 ; i < sizeof(teamSVector) ; i++){
cout << ((TeamS)teamSVector[i] << endl ;
}*/
  
  
return 0;
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote