-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_management.c
More file actions
140 lines (122 loc) · 3.44 KB
/
Copy pathstudent_management.c
File metadata and controls
140 lines (122 loc) · 3.44 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
//School Record Management System
#include<stdio.h>
#include<stdlib.h>
struct node{
char name[50];
float marks;
struct node*next;
int id,class;
};
struct node*head=NULL;
void addStudent(){
struct node*ptr,*temp;
ptr=(struct node*)malloc(sizeof(struct node));
printf("\nenter name:\t");
scanf("%s",&ptr->name);
printf("\nenter ID:\t");
scanf("%d",&ptr->id);
printf("\nenter class:\t");
scanf("%d",&ptr->class);
printf("\nenter marks:\t");
scanf("%f",&ptr->marks);
if(ptr==NULL){
printf("\nOVERFLOW\n");
}else{
if(head==NULL){
ptr->next=NULL;
head=ptr;
printf("\nstudent record is added\n");
}else{
temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
ptr->next=NULL;
temp->next=ptr;
printf("\nstudent record is added\n");
}
}
}
void deletestudent(){
struct node*ptr,*temp;
int id;
if(head==NULL){
printf("list is empty\n");
}else{
printf("\nenter id to deleted:\t");
scanf("%d",&id);
if(head->id==id){
ptr=head;
head=head->next;
free(ptr);
printf("\nDeleted\n");
return;
}
ptr=head;
while(ptr!=NULL && ptr->id!=id){
temp=ptr;
ptr=ptr->next;
}if(ptr==NULL){
printf("\nStudent not found\n");
return;
}
temp->next=ptr->next;
free(ptr);
printf("Student record is deleted\n");
}
}
void display(){
struct node*ptr;
if(head==NULL){
printf("No record\n");
}else{
ptr=head;
while(ptr->next!=NULL){
printf("\nName: %s\nID: %d\nclass: %d\nmarks: %f\n",ptr->name,ptr->id,ptr->class,ptr->marks);
ptr=ptr->next;
}
printf("\nName: %s\nID: %d\nclass: %d\nmarks: %f\n",ptr->name,ptr->id,ptr->class,ptr->marks);
}
}
void search(){
struct node*ptr;
int id;
ptr=head;
printf("enter the ID that you want to search:\t");
scanf("%d",&id);
if(head==NULL){
printf("\nList is empty\n");
}else{
while(ptr->next!=NULL){
if(ptr->id==id){
printf("\nName: %s\nID: %d\nclass: %d\nmarks: %f\n",ptr->name,ptr->id,ptr->class,ptr->marks);
}
ptr=ptr->next;
}
}
}
int main(){
int choice;
while(choice!=5){
printf("........................................................................\n");
printf(".................STUDENT MANAGEMENT SYSTEM..............................\n");
printf("\n1.Add student record\n2.Display student record\n3.delete record\n4.search student record\n5.exit\n");
printf("..........................................................................\n");
printf("\nenter choice:\t");
scanf("%d",&choice);
switch(choice){
case 1:addStudent();
break;
case 2:display();
break;
case 3:deletestudent();
break;
case 4: search();
break;
case 5:exit(0);
break;
default:printf("\n Invalid choice\n");
break;
}
}
}