-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem : Student Details, Sort, Search,.cpp
81 lines (79 loc) · 2.36 KB
/
Problem : Student Details, Sort, Search,.cpp
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
/*Implement the following functions to access the details of a particular student from a list of n students. Use three functions as follows.
a. Get the details of n students.
i. Roll number
ii. Name
iii. Programme
iv. CGPA
b. Sort the list based on their roll number
c. Search for a particular student’s details. (Use minimum number of comparison)*/
#include <stdio.h>
struct student{
int Roll_Number;
char Student_Name[80];
char Student_Programme[80];
int Student_Marks;
};
void Input(struct student list[80], int s){
int i;
for(i=0;i<s;i++)
{
printf("\nDetails of Student %d\n", i+1);
printf("Enter Roll_Number : ");
scanf("%d", &list[i].Roll_Number);
fflush(stdin);
printf("Enter Student Name : ");
gets(list[i].Student_Name);
printf("Enter Student Programme : ");
gets(list[i].Student_Programme);
printf("Enter Student Marks : ");
scanf("%d", &list[i].Student_Marks);
}
}
void Display(struct student list[80], int s){
int i;
printf("\n\nRollno\tName\tProgramme\tMarks\n");
for(i=0;i<s;i++){
printf("%d\t%s\t%s\t\t%d\n",list[i].Roll_Number,list[i].Student_Name,
list[i].Student_Programme,list[i].Student_Marks);
}
}
void Search(struct student list[80], int s, int number){
int i;
for(i=0;i<s;i++){
if (list[i].Roll_Number == number){
printf("Roll Number\t: %d\nName\t\t: %s\nProgramme\t: %s\nMarks\t\t: %d\n",list[i].Roll_Number,
list[i].Student_Name,list[i].Student_Programme,list[i].Student_Marks);
return ;
}
}
printf("Student Details not Found\n");
}
void Sort(struct student list[80],int s){
int i,j;
struct student temp;
for(i=0;i<s-1;i++){
for(j=0;j<(s-1-i);j++){
if(list[j].Roll_Number<list[j+1].Roll_Number){
temp=list[j];
list[j]=list[j + 1];
list[j+1]=temp;
}
}
}
}
int main(){
struct student data[20];
int n,choice,Roll_Number;
printf("Number of Students : ");
scanf("%d", &n);
Input(data, n);
printf("\nDisplaying Details of the Students\n");
Display(data, n);
printf("\nSorting");
Sort(data, n);
Display(data, n);
printf("\nEnter Roll Number to Search : ");
scanf("%d", &Roll_Number);
Search(data, n, Roll_Number);
return 0;
}