-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1-Attendance-System(Beginner).cpp
More file actions
70 lines (60 loc) · 1.62 KB
/
P1-Attendance-System(Beginner).cpp
File metadata and controls
70 lines (60 loc) · 1.62 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Student {
string name;
int rollNo;
bool present;
};
vector<Student> students;
void addStudent() {
Student s;
cout << "Enter student name: ";
cin >> s.name;
cout << "Enter roll number: ";
cin >> s.rollNo;
s.present = false;
students.push_back(s);
cout << "Student added successfully!\n";
}
void markAttendance() {
int rollNo, found = 0;
cout << "Enter roll number to mark attendance: ";
cin >> rollNo;
for (auto &s : students) {
if (s.rollNo == rollNo) {
s.present = true;
cout << "Attendance marked for " << s.name << " (Roll No: " << s.rollNo << ")\n";
found = 1;
break;
}
}
if (!found) cout << "Student not found!\n";
}
void displayAttendance() {
if (students.empty()) {
cout << "No students in the record!\n";
return;
}
cout << "\nAttendance Record:\n";
for (const auto &s : students) {
cout << "Name: " << s.name << " | Roll No: " << s.rollNo << " | Status: "
<< (s.present ? "Present" : "Absent") << endl;
}
}
int main() {
int choice;
while (true) {
cout << "\n1. Add Student\n2. Mark Attendance\n3. Display Attendance\n4. Exit\n";
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1: addStudent(); break;
case 2: markAttendance(); break;
case 3: displayAttendance(); break;
case 4: return 0;
default: cout << "Invalid choice! Try again.\n";
}
}
}