Write a program that will search soccer players data to check whether a name supplied by the user is on that list. For doing the search, the user may provide either the player’s full last name or one or more starting letters of the last name. If a matching last name is found, the program will display the player’s full name and date of birth. Otherwise, it will display “Not found”.
Requirements specification:
At the start, the program will ask the user to enter information about 10 soccer players constituting soccer player data. Each soccer player data will consist of the following fields:
Last name
First name
Birth month
Birth day
Birth year
The user will be asked to enter each soccer player data on a separate line with the field values separated by a space.
Once the data is entered, the program will display a menu of choices as below:
Chose an option:
(1 – input data, 2 – display original data, 3 – sort data , 4 – display sorted data 5 – search by last name 6 – exit the program )
If the user chooses option 1, the program will ask the user for a data and populate the array of structures that will hold the data for each of the soccer players.
If the user chooses option 2, the program will display data in the order provided by the user (original data).
If use chooses option 3, the program will sort data by last name.
If user chooses number 4 the program will display the data sorted by last name.
If the user chooses option 5, the program will ask the user to enter one or more starting letters of the soccer player’s last name. It will then search the soccer player data for the matching last name. If a match is found, it will display the first player found with the matching pattern. If a match is not found, the program will display “Not found”. If the user enters two forward slashes (//) for the last name, it will no longer search for the name. Instead it will display the main option menu.
If the user chooses option 6, the program will display “Thank you for using this program” and will end.
----------------------------------------------------
i need help on why my program isint executing correctly. Here is what i've so far . . . .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <iostream>
#include <string>
using namespace std;
struct data
{
string lname;
string fname;
int birthmonth;
int birthday;
int birthyear;
};
//function prototype
void getData(data &, int );
void showData(const data &, int);
int searchByLastName(const data &, string);
int main()
{
const int NUM_PLAYER = 10;
data player[NUM_PLAYER];
data p2[NUM_PLAYER];
int i;
cout << "Enter the 10 soccer players data:" << endl << endl;
for (i = 0; i < NUM_PLAYER; i++)
{
getData(player[i], i);
}
int choice;
while(choice != 6)
{
cout << "Enter 1 to input data, 2 to display original data, 3 to sort data \n";
cout << "4 to display sorted data, 5 to search by last name, 6 to exit the program: ";
cin >> choice;
cin.ignore();
cout << endl;
if (choice == 1)
{
for (i = 0; i < NUM_PLAYER; i++)
{
getData(player[i], i);
}
}
else if (choice == 2)
{
for (i = 0; i < NUM_PLAYER; i++)
{
showData(player[i], i);
}
}
else if (choice == 3)
{
for (i = 0; i < NUM_PLAYER; i++)
{
p2[i].lname = player[i].lname;
}
}
else if (choice == 5)
{
string look;
cout << "Enter part of last name to search: ";
cin >> look;
for (i = 0; i < NUM_PLAYER; i++)
{
int getNames = player[i].lname.find(look, 0);
if (getNames > 0)
{
cout << player[i].lname << endl;
}
}
}
cout << endl;
}
}
void getData(data &p, int j)
{
cout << "Last name for player " << (j + 1) << ": ";
getline(cin, p.lname);
cout << "First name for player " << (j + 1) << ": ";
getline(cin, p.fname);
cout << "birth month (2 digit format) for player " << (j + 1) << ": ";
cin >> p.birthmonth;
cin.ignore();
cout << "birth day (2 digit format) for player " << (j + 1) << ": ";
cin >> p.birthday;
cin.ignore();
cout << "birth year (4 digit format) for player " << (j + 1) << ": ";
cin >> p.birthyear;
cin.ignore();
cout << endl;
}
void showData(const data &p, int j)
{
cout << "Player " << (j + 1) << " data:" << endl;
cout << p.lname << endl;
cout << p.fname << endl;
cout << p.birthmonth << endl;
cout << p.birthday << endl;
cout << p.birthyear << endl;
cout << endl;
}
|