-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
113 lines (93 loc) · 2.27 KB
/
main.cpp
File metadata and controls
113 lines (93 loc) · 2.27 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Student {
public:
int id;
string name;
float marks;
Student(int i, string n, float m) {
id = i;
name = n;
marks = m;
}
};
vector<Student> students;
// ✅ Add student
void addStudent() {
int id;
string name;
float marks;
cout << "Enter ID: ";
cin >> id;
cin.ignore();
cout << "Enter Name: ";
getline(cin, name);
cout << "Enter Marks: ";
cin >> marks;
students.push_back(Student(id, name, marks));
cout << "✅ Student added successfully!\n\n";
}
// ✅ Display students
void displayStudents() {
if (students.empty()) {
cout << "No students found.\n\n";
return;
}
cout << "\n📋 Student List:\n";
for (auto &s : students) {
cout << "ID: " << s.id
<< " | Name: " << s.name
<< " | Marks: " << s.marks << endl;
}
cout << endl;
}
// ✅ Search student
void searchStudent() {
int id;
cout << "Enter ID to search: ";
cin >> id;
for (auto &s : students) {
if (s.id == id) {
cout << "✅ Found: " << s.name << " (" << s.marks << ")\n\n";
return;
}
}
cout << "❌ Student not found.\n\n";
}
// ✅ Delete student
void deleteStudent() {
int id;
cout << "Enter ID to delete: ";
cin >> id;
for (auto it = students.begin(); it != students.end(); ++it) {
if (it->id == id) {
students.erase(it);
cout << "✅ Student deleted.\n\n";
return;
}
}
cout << "❌ Student not found.\n\n";
}
int main() {
int choice;
while (true) {
cout << "====== Student Record Manager ======\n";
cout << "1. Add Student\n";
cout << "2. Display Students\n";
cout << "3. Search Student\n";
cout << "4. Delete Student\n";
cout << "5. Exit\n";
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1: addStudent(); break;
case 2: displayStudents(); break;
case 3: searchStudent(); break;
case 4: deleteStudent(); break;
case 5: return 0;
default: cout << "Invalid choice\n\n";
}
}
}