PROBLEM Write a program that will search soccer players data to check whether a
ID: 3566591 • Letter: P
Question
PROBLEM
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%u2019s 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%u2019s full name and date of birth. Otherwise, it will display %u201CNot found%u201D.
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 %u2013 input data, 2 %u2013 display original data, 3 %u2013 sort data , 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 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%u2019s 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 %u201CNot found%u201D. 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 %u201CThank you for using this program%u201D and will end.
ANALYSIS
Input/Output:
(User input is in bold)
Enter data for 10 soccer players (you can use a txt file to input data if you wish )
(Separate the fields by spaces and enter each player data on a new line)
Note the names of the list bellow are real soccer players but the birth days are made up. You can change this list as you wish.
Roberto Baggio 01 12 1992
David Beckham 05 12 1988
Pablo Aimar 05 13 1987
Michael Ballack 11 13 1999
Gabriel Batistuta 05 05 1979
Franz Beckenbauer 18 01 1976
Dennis Bergcamp 03 14 1989
Omar Bravo 03 03 1999
Jared Borgetti 09 23 1977
Fabio Cannavaro 02 25 1990
Chose an option:
(1 %u2013 Input data, 2 %u2013 display original data, 3 %u2013 sort data by last name, 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 display goodbye message and exit the program )
1
Chose an option:
(1 %u2013 Input data, 2 %u2013 display original data, 3 %u2013 sort data by last name, 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 display goodbye message and exit the program )
2
Unsorted data:
Roberto Baggio 01 12 1992
David Beckham 05 12 1988
Pablo Aimar 05 13 1987
Michael Ballack 11 13 1999
Gabriel Batistuta 05 05 1979
Franz Beckenbauer 18 01 1976
Dennis Bergcamp 03 14 1989
Omar Bravo 03 03 1999
Jared Borgetti 09 23 1977
Fabio Cannavaro 02 25 1990
Chose an option:
(1 %u2013 Input data, 2 %u2013 display original data, 3 %u2013 sort data by last name, 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 display goodbye message and exit the program)
3
Chose an option:
(1 %u2013 Input data, 2 %u2013 display original data, 3 %u2013 sort data by first name, 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 display goodbye message and exit the program)
4
Sorted data:
David Beckham 05 12 1988
David Beckham 05 12 1988
Eric Cantona 03 14 1989
Fabio Cannavaro 02 25 1990
Franz Beckenbauer 18 01 1976
Gabriel Batistuta 05 05 1979
Jared Borgetti 09 23 1977
Michael Ballack 11 13 1999
Omar Bravo 03 3 1999
Pablo Aimar 05 13 1987
Roberto Baggio 01 12 1992
Chose an option:
(1 %u2013 Input data, 2 %u2013 display original data, 3 %u2013 sort data by last name, 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 display goodbye message and exit the program)
5
// this will run in a loop
Enter one or more starting letters of the last name ( enter %u2018//%u2019 to quit this option):
R
Roberto Baggio 01 12 1992
Enter one or more starting letters of the last name:
Mic
Michael Ballack 11 13 1999
Enter one or more starting letters of the last name:
Fabio
Fabio Cannavaro 02 25 1990
Enter one or more starting letters of the last name:
A
Not found.
Enter one or more starting letters of the last name:
Kerry
Not found.
Enter starting letter/letters from the last name:
//
Chose an option:
(1 %u2013 Input data, 2 %u2013 display original data, 3 %u2013 sort data by last name, 4 %u2013 display sorted data 5 %u2013 search by last name 6 %u2013 display goodbye message and exit the program )
6
Thank you for using this program.
DESIGN of the main module ( main function )
read celebrity list
while (1)
begin
display option menu
switch (option)
begin
case 1: input data
break;
case 2:
display players list in the order entered
break
case 3:
sort by last name
break
case 4: display sorted array:
case 5: search by last name ( user will enter one or more letters from the last name starting always from the beginning of the last name)
read pattern
while (pattern !=%u201C//%u201D)
begin
search for the last name pattern in players list
if (found)
display players information
else
display %u201CNot found%u201D
read pattern
end while
break
case 6:
display %u201CThank you for using this program%u201D
exit program
end switch
end while
IMPLEMENTATION
Bellow is the Socer player structure declaration:
struct splayer
{
char lname [20];
char fname [20];
int birthmonth;
int birthday;
int birthyear;
};
Explanation / Answer
Program:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
struct splayer {
char lname[20];
char fname[20];
int birthmonth;
int birthday;
int birthyear;
};
typedef struct splayer PLAYER;
PLAYER players[20]; // temp[20];
int count = 0;
//Function prototypes
void inputData();
void displayOriginalData();
void sortByLastName();
void displaySortedData();
void searchByLastName();
int main(void)
{
char choice;
do
{
printf("1. Input data ");
printf("2. Display original data ");
printf("3. Sort data by last name ");
printf("4. Display sorted data ");
printf("5. Search by last name ");
printf("6. Exit. ");
printf("Choose an option: ");
scanf("%c", &choice);
switch (choice)
{
case '1':
inputData();
break;
case '2':
displayOriginalData();
break;
case '3':
sortByLastName();
break;
case '4':
displaySortedData();
break;
case '5':
searchByLastName();
break;
case '6':
printf("Thank you for using the program. Good bye!");
exit(0);
default:
printf(" Please enter the correct input.");
}
} while (1);
return (0);
}
void inputData()
{
printf(" Last Name: ");
scanf("%s", players[count].lname); //counter-1 b/c arrays start at 0
printf("First Name: ");
scanf("%s", players[count].fname);
printf("Enter the date of birth information:");
printf("Month born: ");
scanf("%d", &players[count].birthmonth);
printf("Date born: ");
scanf("%d", &players[count].birthday);
printf("Year born: ");
scanf("%d", &players[count].birthyear);
count++;
}
void displayOriginalData()
{
int i;
printf("Displaying the Original Data: ");
printf("*************************************** ");
for (i = 0; i < count; i++)
{
printf("%s %s ", players[i].lname, players[i].fname);
printf("%d %d %d ", players[i].birthmonth, players[i].birthday, players[i].birthyear);
}
}
void sortByLastName()
{
PLAYER temp;
int i;
int j;
for (i = 0; i < count; i++)
{
for (j = i + 1; j < count; j++)
{
if (strcmp(players[i].lname, players[j].lname) > 0)
{
temp = players[i];
players[i] = players[j];
players[j] = temp;
}
}
}
}
void displaySortedData()
{
int i;
printf("Displaying the Sorted Data: ");
printf("*************************************** ");
for (i = 0; i < count; i++)
{
printf("%s %s ", players[i].lname, players[i].fname);
printf("%d %d %d ", players[i].birthmonth, players[i].birthday, players[i].birthyear);
}
}
void searchByLastName()
{
char input[20];
printf(" Enter one or more starting letters of the last name:");
scanf("%s", input);
for (int i = 0; i < count; i++)
{
if (strcmp(input, players[i].lname) == 0)
{
printf("%s %s ", players[i].lname, players[i].fname);
printf("%d %d %d ", players[i].birthmonth, players[i].birthday, players[i].birthyear);
}
else
{
printf(" Sorry! Not Found. ");
}
}
}
-------------------------------------------------------------------------------------------------------------------------
Sample Output:
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name: Roberto
First Name: Baggio
Enter the date of birth information:Month born: 01
Date born: 12
Year born: 1992
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name: David
First Name: Beckham
Enter the date of birth information:Month born: 05
Date born: 12
Year born: 1988
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name: Pablo
First Name: Aimar
Enter the date of birth information:Month born: 05
Date born: 13
Year born: 1987
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name: Michael
First Name: Ballack
Enter the date of birth information:Month born: 11
Date born: 13
Year born: 1999
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name: Gabriel
First Name: Batistuta
Enter the date of birth information:Month born: 05
Date born: 05
Year born: 1979
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name:
Franz
First Name: Beckenbauer
Enter the date of birth information:Month born: 18
Date born: 01
Year born: 1976
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 1
Last Name: Dennis
First Name: Bergcamp
Enter the date of birth information:Month born: 03
Date born: 14
Year born: 1989
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 2
Displaying the Original Data:
***************************************
Roberto Baggio 1 12 1992
David Beckham 5 12 1988
Pablo Aimar 5 13 1987
Michael Ballack 11 13 1999
Gabriel Batistuta 5 5 1979
Franz Beckenbauer 18 1 1976
Dennis Bergcamp 3 14 1989
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 3
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 4
Displaying the Sorted Data:
***************************************
David Beckham 5 12 1988
Dennis Bergcamp 3 14 1989
Franz Beckenbauer 18 1 1976
Gabriel Batistuta 5 5 1979
Michael Ballack 11 13 1999
Pablo Aimar 5 13 1987
Roberto Baggio 1 12 1992
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 5
Enter one or more starting letters of the last name:Pablo
Sorry! Not Found.
Sorry! Not Found.
Sorry! Not Found.
Sorry! Not Found.
Sorry! Not Found.
Pablo Aimar 5 13 1987
Sorry! Not Found.
1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option:
Please enter the correct input.1. Input data
2. Display original data
3. Sort data by last name
4. Display sorted data
5. Search by last name
6. Exit.
Choose an option: 6
Thank you for using the program. Good bye!Press any key to continue...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.