include #include #define SIZE 6 struct Student{ char name[50]; int id; float mark; }; int Search1(char input[], struct Student data[]); int Search2(int input, struct Student data[]); int main() { char search_name[30]; int search_id; int result1, result2; struct Student list[SIZE] = { {"Amylia", 544199, 75.4}, {"Cheong", 143566, 92.3}, {"Harry", 109774, 65.5}, {"Krishnan", 334514, 86.7}, {"Melissa", 257890, 55.4}, {"Timothy",144656, 77.8}}; printf("Enter Student Name: "); gets(search_name); result1 = Search1(search_name, list); //Answer for part (a)(ii) – Display the matching index of result1 printf("Enter Student ID: "); scanf("%d",&search_id); result2 = Search2(search_id,list); //Answer for part (a)(iii)- Display the matching index of result2 return 0; } //Answer for part (a)(i) – function definition for Search1 //Answer for part (a)(iii) – function definition for Search2
#include <stdio.h>
#include <string.h>
#define SIZE 6
struct Student{
char name[50];
int id;
float mark;
};
int Search1(char input[], struct Student data[]);
int Search2(int input, struct Student data[]);
int main() {
char search_name[30];
int search_id;
int result1, result2;
struct Student list[SIZE] = {
{"Amylia", 544199, 75.4},
{"Cheong", 143566, 92.3},
{"Harry", 109774, 65.5},
{"Krishnan", 334514, 86.7},
{"Melissa", 257890, 55.4},
{"Timothy",144656, 77.8}};
printf("Enter Student Name: ");
gets(search_name);
result1 = Search1(search_name, list);
//Answer for part (a)(ii) – Display the matching index of result1
printf("Enter Student ID: ");
scanf("%d",&search_id);
result2 = Search2(search_id,list);
//Answer for part (a)(iii)- Display the matching index of result2
return 0;
}
//Answer for part (a)(i) – function definition for Search1
//Answer for part (a)(iii) – function definition for Search2
![Program Listing in Q4(a) intends to implement 'binary' and 'sequential' searching functions for an
array of student records. Study the code snippet carefully and answer the following questions.
(i) Write the function definition for Search1 that implements a binary search
to search for a particular student's name in an array of records. The function
takes in the search_name and array of Student structures. If a match
is found, the function returns the index of the matching element, otherwise
it returns -1.
(ii) Write a suitable C code to display the details (i.e. student name, student ID
and mark) of the matching element of search_name (from result1).
(iii) Write the function definition for sSearch2 that implements a sequential
search to search for a particular student's ID number in an array of records.
The function takes in the search_id and array of Student structures.
If a match is found, the function retums the index of the matching element,
otherwise it returns -1.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb34193a3-789b-4387-afe3-a3ecbef71476%2Ffb637ff3-7889-46b1-9e21-e7dc30be6c08%2F1l0ij2d_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)