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

Write a program that will search soccer players data to check whether a name sup

ID: 3913812 • Letter: W

Question

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 socc

er 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 lin

e 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 populat

e 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 st

arting letters of the

soccer player

s last name. It will then search the soccer player data for the matchi

ng last name. If a

match is found, it will display the first player found with the matc

hing 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 displa

y the main option menu.   

If the user chooses option 6, the program will display

Thank you for using this program

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 wis

h )   

(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

Input data, 2

display original data, 3

sort data by last name, 4

display sorted data 5

search

by last name 6

display goodbye message and exit the program )   

1   

Chose an option:   

(1

Input data, 2

display original data, 3

sort data by last name, 4

display sorted data 5

search

by last name 6

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

Input data, 2

display original data, 3

sort data by last name, 4

display sorted data 5

search

by last name 6

display goodbye message and exit the program)   

3   

Chose an option:   

(1

Input data, 2

display original data, 3

sort data by first name, 4

display sorted data 5

search by last name 6

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

Input data, 2

display original data, 3

sort data by last name, 4

display sorted data 5

search

by last name 6

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

//

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

Input data, 2

display original data, 3

sort data by last name, 4

display sorted data 5

search

by last name 6

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 fro

m the last name starting always

from the beginning of the last name)   

read pattern   

while (pattern !=

//

)

begin   

search for the last name pattern in players list   

if (found)   

display players information   

else   

display

Not found

read pattern   

end while   

break   

case 6:   

display

Thank you for using this program

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

#include<stdio.h>
#include<string.h>

struct splayer{

   char lname[20];
   char fname[20];
   int birthmonth;
   int birthday;
   int birthyear;
};

void Menu(){
    printf("1.Input Data ");
    printf("2.Display Original Data ");
    printf("3.Sort Data ");
    printf("4.Display Sorted Data ");
    printf("5.Search by last name ");
    printf("6.Exit ");
}


void sort(struct splayer data[], int count){
    int i,j,k;
    char temp1[20];
    char temp2[20];
    int temp3;
    int temp4;
    int temp5;
    for (i = 0; i<count; i++){
        for (j = i+1; j<count; j++){
            if (strcmp(data[i].lname,data[j].lname) > 0){
               //printf("-------------------------- ");
               strcpy(temp1,data[i].lname);
               strcpy(temp2,data[i].fname);
               temp3 = data[i].birthmonth;
               temp4 = data[i].birthday;
               temp5 = data[i].birthyear;

               strcpy(data[i].lname,data[j].lname);
               strcpy(data[i].fname,data[j].fname);
               data[i].birthmonth = data[j].birthmonth;
               data[i].birthday = data[j].birthday;
               data[i].birthyear = data[j].birthyear;

               strcpy(data[j].lname,temp1);
               strcpy(data[j].fname,temp2);
               data[j].birthmonth = temp3;
               data[j].birthday = temp4;
               data[j].birthyear = temp5;


              
            }
        }
    }
}

int main(){

    struct splayer data[50];
    struct splayer data1[50];
    int n,i,j,k;

    printf("Enter data for 10 soccer players ");
    int count = 0;
   
    for(i = 0; i<10; i++){
       scanf("%s%s%d%d%d",data[i].lname, data[i].fname, &data[i].birthmonth, &data[i].birthday, &data[i].birthyear);
       strcpy(data1[i].lname,data[i].lname);
       strcpy(data1[i].fname,data[i].fname);
       data1[i].birthmonth = data[i].birthmonth;
       data1[i].birthday = data[i].birthday;
       data1[i].birthyear = data[i].birthyear;
       count++;
    }
   
    //int count = 10;
    while(1){
         Menu();
         printf("Choose an option: ");
         scanf("%d", &n);
        
         if (n == 1){
            printf("Enter data for a soccer player ");
            scanf("%s%s%d%d%d",data[count].lname, data[count].fname, &data[count].birthmonth, &data[count].birthday, &data[count].birthyear);
            strcpy(data1[count].lname,data[count].lname);
            strcpy(data1[count].fname,data[count].fname);
            data1[count].birthmonth = data[count].birthmonth;
            data1[count].birthday = data[count].birthday;
            data1[count].birthyear = data[count].birthyear;
            count++;
         }
         if (n == 6){
            printf("Thank you for using the program ");
            break;
         }
         if (n == 2){
            for (i = 0; i<count; i++){
               printf("%s %s ", data[i].lname, data[i].fname);
               if (data[i].birthmonth < 10)
                  printf("%s%d ","0",data[i].birthmonth);
               else
                  printf("%d ",data[i].birthmonth);

               if (data[i].birthday < 10)
                  printf("%s%d ","0",data[i].birthday);
               else
                  printf("%d ",data[i].birthday);
               printf("%d ",data[i].birthyear);
              
            }
           
         }
         if (n == 3){
            sort(data1,count);
         }
         if (n == 4) {
            for (i = 0; i<count; i++){
               printf("%s %s ", data1[i].lname, data1[i].fname);
               if (data1[i].birthmonth < 10)
                  printf("%s%d ","0",data1[i].birthmonth);
               else
                  printf("%d ",data1[i].birthmonth);

               if (data1[i].birthday < 10)
                  printf("%s%d ","0",data1[i].birthday);
               else
                  printf("%d ",data1[i].birthday);
               printf("%d ",data1[i].birthyear);
              
            }
           
         }
         if (n == 5){
            printf("Enter starting letters of the last name:");
            char last[20];
            scanf("%s",last);
            if (strcmp(last, "\") == 0)
               continue;
            int found = 0;
            for (i = 0; i<count; i++){
                found = 1;
                for (j = 0; j<strlen(last); j++){
                    if (j < strlen(data[i].lname)){
                       if (last[j] != data[i].lname[j]){
                          found = 0;
                          break;
                       }
                    }
                }
                if (found == 1){
                   printf("%s %s ", data[i].lname, data[i].fname);
                   if (data[i].birthmonth < 10)
                      printf("%s%d ","0",data[i].birthmonth);
                   else
                      printf("%d ",data[i].birthmonth);

                   if (data[i].birthday < 10)
                      printf("%s%d ","0",data[i].birthday);
                   else
                      printf("%d ",data[i].birthday);
                   printf("%d ",data[i].birthyear);
                   break;
                }
            }
            if (found == 0){
               printf("Not found ");
            }
        }
      
    }
    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