Repository navigation
Expand file tree
/
Copy pathAttendance_Management_System.cpp
More file actions
260 lines (212 loc) · 7.27 KB
/
Copy pathAttendance_Management_System.cpp
File metadata and controls
260 lines (212 loc) · 7.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct Attendance
{
string name;
int roll;
int present;
int leave;
int half_day;
int paid_leave;
int overtime;
float attendance;
};
// invalid input
void inputInt(string message, int &value)
{
while(true)
{
cout << message;
cin >> value;
if(cin.fail())
{
cin.clear();
cin.ignore(1000,'\n');
cout << "Invalid Input! Please enter numbers only.\n";
}
else
{
break;
}
}
}
int main()
{
int n;
int month, year;
int total_days;
int working_days;
ofstream txt("Attendance_Report.txt");
ofstream excel("Attendance_Report.csv");
cout << "==============================\n";
cout << " ATTENDANCE MANAGEMENT SYSTEM\n";
cout << "==============================\n\n";
inputInt("Enter Year : ", year);
inputInt("Enter Month (1-12) : ",month);
if(month==1 || month==3 || month==5 || month==7 ||
month==8 || month==10 || month==12)
total_days=31;
else if(month==4 || month==6 || month==9 || month==11)
total_days=30;
else if(month==2)
{
if((year%400==0) || (year%4==0 && year%100!=0))
total_days=29;
else
total_days=28;
}
else
{
cout<<"Invalid Month!";
return 0;
}
cout<<"\nTotal Days in Month : "<<total_days<<endl;
do
{
inputInt("Enter Total Working Days : ", working_days);
if(working_days<1 || working_days>total_days)
{
cout<<"Invalid! Working days must be between 1 and "
<<total_days<<endl;
}
}while(working_days<1 || working_days>total_days);
inputInt("Enter Number of Students/Employees : ", n);
Attendance data[20];
for(int i=0;i<n;i++)
{
Attendance person;
cout<<"\n-----------------------------------------";
cout<<"\nEmployee "<<i+1;
cout<<"\n-----------------------------------------";
cin.ignore(1000,'\n');
cout<<"\nEnter Name : ";
getline(cin,person.name);
inputInt("Roll No : ", person.roll);
do
{
inputInt("Present Days : ", person.present);
if(person.present<0 || person.present>working_days)
cout<<"Invalid! Present Days must be between 0 and "
<<working_days<<endl;
}while(person.present<0 || person.present>working_days);
do
{
inputInt("Paid Leave : ", person.paid_leave);
if(person.paid_leave<0 ||
person.paid_leave>working_days-person.present)
cout<<"Invalid Paid Leave!"<<endl;
}while(person.paid_leave<0 ||
person.paid_leave>working_days-person.present);
do
{
inputInt("Leave Days : ", person.leave);
if(person.leave<0 ||
person.leave>working_days-
person.present-
person.paid_leave)
cout<<"Invalid Leave Days!"<<endl;
}while(person.leave<0 ||
person.leave>working_days-
person.present-
person.paid_leave);
int remaining;
remaining = working_days -
person.present -
person.leave -
person.paid_leave;
do
{
inputInt("Half Days : ", person.half_day);
if(person.half_day < 0 || person.half_day > remaining*2)
{
cout << "Invalid! Maximum Half Days = "
<< remaining*2 << endl;
}
}while(person.half_day < 0 || person.half_day > remaining*2);
do
{
inputInt("Overtime Hours : ", person.overtime);
if(person.overtime < 0)
{
cout << "Invalid! Overtime cannot be negative." << endl;
}
}while(person.overtime < 0);
person.attendance =
((person.present +
person.paid_leave +
(person.half_day/2.0))
/ working_days) * 100;
data[i] = person;
}
txt << "================ ATTENDANCE REPORT ================\n";
txt << "Year : " << year << endl;
txt << "Month : " << month << endl;
txt << "Total Days : " << total_days << endl;
txt << "Working Days : " << working_days << endl;
txt << "===================================================\n\n";
cout << "\n\n================ ATTENDANCE REPORT ================\n";
cout << "Year : " << year << endl;
cout << "Month : " << month << endl;
cout << "Total Days : " << total_days << endl;
cout << "Working Days : " << working_days << endl;
cout << "--------------------------------------------------------------------------\n";
cout << left << setw(20) << "Name"
<< setw(8) << "Roll"
<< setw(8) << "Present"
<< setw(8) << "Leave"
<< setw(8) << "Half"
<< setw(8) << "Paid"
<< setw(10) << "OT(Hrs)"
<< setw(10) << "Att(%)" << endl;
cout << "--------------------------------------------------------------------------\n";
txt << left << setw(20) << "Name"
<< setw(8) << "Roll"
<< setw(8) << "Present"
<< setw(8) << "Leave"
<< setw(8) << "Half"
<< setw(8) << "Paid"
<< setw(10) << "OT(Hrs)"
<< setw(10) << "Att(%)" << endl;
txt << "--------------------------------------------------------------------------\n";
excel << "Name,Roll,Present,Leave,Half Day,Paid Leave,Overtime,Attendance %\n";
for(int i=0;i<n;i++)
{
cout << left << setw(20) << data[i].name
<< setw(8) << data[i].roll
<< setw(8) << data[i].present
<< setw(8) << data[i].leave
<< setw(8) << data[i].half_day
<< setw(8) << data[i].paid_leave
<< setw(10) << data[i].overtime
<< fixed << setprecision(2)
<< setw(10) << data[i].attendance << endl;
txt << left << setw(20) << data[i].name
<< setw(8) << data[i].roll
<< setw(8) << data[i].present
<< setw(8) << data[i].leave
<< setw(8) << data[i].half_day
<< setw(8) << data[i].paid_leave
<< setw(10) << data[i].overtime
<< fixed << setprecision(2)
<< setw(10) << data[i].attendance << endl;
excel << data[i].name << ","
<< data[i].roll << ","
<< data[i].present << ","
<< data[i].leave << ","
<< data[i].half_day << ","
<< data[i].paid_leave << ","
<< data[i].overtime << ","
<< fixed << setprecision(2)
<< data[i].attendance << "\n";
}
cout << "--------------------------------------------------------------------------\n";
txt << "--------------------------------------------------------------------------\n";
txt.close();
excel.close();
cout << "\nAttendance Report Saved Successfully!" << endl;
cout << "1. Attendance_Report.txt" << endl;
cout << "2. Attendance_Report.csv (Open with Microsoft Excel)" << endl;
return 0;
}