QuestionQuestion

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 <TeamS> & 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 <TeamS> & TeamV);

The function simply prints out the content of the vector.

4. The menu Function

Next, place 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 selects 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 protoype which will allow the user to enter the information for a team which will be added to your team vector:

void add (vector <TeamS> & 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 protoype 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 <TeamS> & 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.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

const int NUM_TEAMS = 4;
const int NUM_MEMBERS = 3;

/**
* First define struct TeamS with an integer field to hold an ID,
* and an array ofstrings with three elements to hold the names of the team members.
*/
struct TeamS {
    int id;
    string members[NUM_MEMBERS];
};

/**
* The function should place into the vector the elements of the arrays
*/
void Initialize(vector <TeamS> & TeamV, const int id[],
       const string m[][NUM_MEMBERS], int arraySize) {
    TeamS team;
    cout << "Starting Initialization\n";
    for (int i = 0; i < arraySize; i++) {
       team.id = id[i];
       for (int j = 0; j < NUM_MEMBERS; j++) {
            team.members[j] = m[i][j];
       }
       TeamV.push_back(team);
    }
    cout << "Ending   Initialization\n\n";
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats