-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentManagement.cpp
More file actions
208 lines (175 loc) · 5.09 KB
/
StudentManagement.cpp
File metadata and controls
208 lines (175 loc) · 5.09 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <iostream>
#include<string>
#include <fstream>
#include<stdlib.h>
using namespace std;
class Node {
public:
int roll_no;
string name, father_name, qualification, phone_no;
Node* next;
};
class Linked_List {
public:
Node* head;
Linked_List() {
head = NULL;
}
void insert() {
Node* new_node = new Node();
fstream file("Items.txt", ios::app);
cout << "\nEnter roll number: ";
cin >> new_node->roll_no;
file << new_node->roll_no << endl;
cout << "\nEnter name: ";
cin >> new_node->name;
file << new_node->name << endl;
cout << "\nEnter father's name: ";
cin >> new_node->father_name;
file << new_node->father_name << endl;
cout << "\nEnter qualification: ";
cin >> new_node->qualification;
file << new_node->qualification << endl;
cout << "\nEnter phone number: ";
cin >> new_node->phone_no;
file << new_node->phone_no << endl;
new_node->next = NULL;
if (head == NULL) {
head = new_node;
} else {
Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = new_node;
}
file.close();
cout << "\nNew node inserted";
}
void search() {
int roll_no, found = 0;
cout << "\nEnter roll number to search: ";
cin >> roll_no;
Node* temp = head;
while (temp != NULL) {
if (temp->roll_no == roll_no) {
cout << "\nRecord found: ";
cout << "\nRoll number: " << temp->roll_no;
cout << "\nName: " << temp->name;
cout << "\nFather's name: " << temp->father_name;
cout << "\nQualification: " << temp->qualification;
cout << "\nPhone number: " << temp->phone_no;
found = 1;
}
temp = temp->next;
}
if (!found) {
cout << "\nRecord not found";
}
}
void display() {
Node* temp = head;
if (temp == NULL) {
cout << "\nList is empty";
} else {
while (temp != NULL) {
cout << "\nRoll number: " << temp->roll_no;
cout << "\nName: " << temp->name;
cout << "\nFather's name: " << temp->father_name;
cout << "\nQualification: " << temp->qualification;
cout << "\nPhone number: " << temp->phone_no;
temp = temp->next;
}
}
}
void update() {
int roll_no, found = 0;
cout << "\nEnter roll number to update: ";
cin >> roll_no;
Node* temp = head;
while (temp != NULL) {
if (temp->roll_no == roll_no) {
cout << "\nEnter new roll number: ";
cin >> temp->roll_no;
cout << "\nEnter new name: ";
cin >> temp->name;
cout << "\nEnter new father's name: ";
cin >> temp->father_name;
cout << "\nEnter new qualification: ";
cin >> temp->qualification;
cout << "\nEnter new phone number: ";
cin >> temp->phone_no;
found = 1;
break;
}
temp = temp->next;
}
if (!found) {
cout << "\nRecord not found";
}
}
void delete_node() {
int roll_no, found = 0;
Node* temp, *prev;
cout << "\nEnter roll number to delete: ";
cin >> roll_no;
if (head->roll_no == roll_no) {
temp = head;
head = head->next;
delete temp;
found = 1;
} else {
temp = head;
prev = NULL;
while (temp != NULL) {
if (temp->roll_no == roll_no) {
prev->next = temp->next;
delete temp;
found = 1;
break;
}
prev = temp;
temp = temp->next;
}
}
if (!found) {
cout << "\nRecord not found";
}
}
};
int main() {
Linked_List list;
int choice;
while (1) {
cout << "\n\n1. Insert record";
cout << "\n2. Search record";
cout << "\n3. Display record";
cout << "\n4. Update record";
cout << "\n5. Delete record";
cout << "\n6. Exit";
cout << "\n\nEnter your choice: ";
cin >> choice;
switch (choice) {
case 1:
list.insert();
break;
case 2:
list.search();
break;
case 3:
list.display();
break;
case 4:
list.update();
break;
case 5:
list.delete_node();
break;
case 6:
exit(0);
default:
cout << "\nInvalid choice!";
}
}
return 0;
}