Diploma in Computer Technology: Government Polytechnic, Solapur
Diploma in Computer Technology: Government Polytechnic, Solapur
GOVERNMENT POLYTECHNIC,
SOLAPUR
Submitted by:
Roll No. 82 – Sharaneshwar Bharat Punjal
Submitted to:
Prof. A. P. Sathe
1
CERTIFICATE
ACKNOWLEDGEMENT
In the accomplishment of this micro-project successfully, many people
have best owned upon me their blessings and heart-privileged support.
Primarily, I would like to express a special thanks of gratitude to the Principal
2
Sir of the Government Polytechnic, Solapur for giving this golden opportunity
with all the required facilities for completing this micro-project of our group.
I would also like to thank my parents who have helped with their valuable
suggestions and provided the required resources needed for the micro-project.
3
ABSTRACT
As a student enrolled in the Government Polytechnic, Solapur, every
semester we require to do a micro-project on any one topic in the syllabus of the
respective subjects. Hence, I have done a micro-project to develop a Student
Attendance Management System using C++.
4
INTRODUCTION
As said earlier, this micro-project mainly shows the implementation of
file handling in C++. It includes functions like create_sheet() which is used for
creating new attendance sheet which includes roll numbers and names of all the
students of the particular class. This data is copied into a new attendance sheet.
Next function of the system is add_attendance() which is used to add the
attendance of particular date in the file. The user has to input a file which
contains the present roll numbers of that particular day. With the help of that
present roll numbers file, the attendance sheet gets updated by placing a ‘P’ for
present or ‘A’ for absent in front of the respective students. The user also has to
choice to input present roll numbers file or absent roll numbers file and
depending upon the user’s input, the attendance gets marked in the sheet.
This is how the student attendance system works. The input and output of
the program can be seen on the content that gets updated in the files. For this
attendance system, all the files are of .csv extension as these type of files are
very suitable for storing the attendance of the students.
5
REVIEW OF CONCEPTS
A short review of the important concepts of C++ used in this micro-
project is here.
1. OBJECT-ORIENTED PROGRAMMING –
Object-oriented programming aims to implement real-world entities like
inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP
is to bind together the data and the functions that operate on them so that no
other part of the code can access this data except that function. Classes and
objects are the basic building blocks of OOP.
2. FILE HANDLING -
In C++, files are mainly dealt by using three classes fstream, ifstream,
ofstream available in fstream headerfile.
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.
We can open and close files using open() and close() functions or
constructors present in fstream classes.
Default open modes:
ifstream – ios::in
ofstream – ios::out
fstream – ios::in | ios::out
6
SIGNIFICANCE OF THE PROJECT -
The main significance of this micro-project is to develop C++ programs using
file handling. This project clearly shows how file handling is implemented in
C++ and particularly its shows how to read and write .csv files.
HARDWARE REQUIREMENTS -
Laptop or PC or Mobile with Basic Configurations.
SOFTWARE REQUIREMENTS -
1. Operating System (Windows family)
2. IDE for C++ language (Turbo C++, Visual Studio Code, Dev C++, etc.)
3. Text Editor
7
C PROGRAM CODE
#include <iostream>
#include <fstream>
#include <conio.h>
#include <time.h>
using namespace std;
void heading();
void delay(int milliseconds);
class Attendance
{
ifstream fin;
ofstream fout;
string sheetfile, sourcefile;
int total;
const string p = "P", a = "A";
public:
void create_sheet()
{
heading();
cout << "Enter file name of the attendance sheet -> ";
cin >> sheetfile;
cout << endl
<< "Enter file name (.csv) to import students roll no.s
and names -> ";
cin >> sourcefile;
8
for (int i = 0; i < total; i++)
{
fout << rollno[i] << "," << name[i] << endl;
}
fout.close();
cout << endl
<< "Fetching data from file into the attendance sheet";
for (int i = 0; i < 3; i++)
{
delay(700);
cout << ".";
}
delay(500);
heading();
cout << "Successfully fetched the student details into " <<
sheetfile << ".csv file..." << endl;
getch();
}
9
int total = 0;
fin.open(filename + ".csv");
while (fin.good())
{
string line;
getline(fin, line, '\n');
total++;
}
fin.close();
return total;
}
void add_attendance()
{
int total2, choice2;
string date, presentrolls_filename;
delay(500);
heading();
cout << "Enter file name of the attendance sheet -> ";
cin >> sheetfile;
cout << endl
<< "Enter date of attendance -> ";
cin >> date;
cout << endl
<< "Enter 1 -> To input present students roll no.s" <<
endl;
cout << "Enter 2 -> To input absent students roll no.s" <<
endl;
cout << endl
<< "Enter your choice -> ";
cin >> choice2;
if (choice2 == 1)
{
cout << endl
<< "Enter file name which contains present students
roll no.s -> ";
cin >> presentrolls_filename;
total = fetch_total_students_from_file(sheetfile);
total2 =
fetch_total_students_from_file(presentrolls_filename);
10
string rollno[total], name[total];
fetch_student_details_from_file(sheetfile, total,
rollno, name);
string filedata[total];
fin.open(sheetfile + ".csv");
for (int i = 0; i < total; i++)
{
getline(fin, filedata[i]);
}
fin.close();
fout.open(sheetfile + ".csv");
for (int i = 0; i < total; i++)
{
if (filedata[i].length() == 0)
break;
else
{
if (i == 0)
fout << filedata[i] << "," << date << endl;
else
{
int flag = -1;
for (int k = 0; k < total2; k++)
{
if (rollno[i].compare(presentrolls[k])
== 0)
{
flag = 1;
break;
}
else
{
11
flag = 0;
}
}
if (flag == 0)
fout << filedata[i] << "," << a << endl;
else if (flag == 1)
fout << filedata[i] << "," << p << endl;
else
fout << filedata[i] << endl;
}
}
}
fout.close();
}
else if (choice2 == 2)
{
cout << endl
<< "Enter file name which contains absent students
roll no.s -> ";
cin >> presentrolls_filename;
total = fetch_total_students_from_file(sheetfile);
total2 =
fetch_total_students_from_file(presentrolls_filename);
string filedata[total];
fin.open(sheetfile + ".csv");
for (int i = 0; i < total; i++)
{
12
getline(fin, filedata[i]);
}
fin.close();
fout.open(sheetfile + ".csv");
for (int i = 0; i < total; i++)
{
if (filedata[i].length() == 0)
break;
else
{
if (i == 0)
fout << filedata[i] << "," << date << endl;
else
{
int flag = -1;
for (int k = 0; k < total2; k++)
{
if (rollno[i].compare(presentrolls[k])
== 0)
{
flag = 1;
break;
}
else
{
flag = 0;
}
}
if (flag == 0)
fout << filedata[i] << "," << p << endl;
else if (flag == 1)
fout << filedata[i] << "," << a << endl;
else
fout << filedata[i] << endl;
}
}
}
fout.close();
}
else
{
cout << endl
13
<< "Invalid choice..." << endl
<< "Enter again..." << endl;
}
cout << endl
<< "Marking attendance";
for (int i = 0; i < 3; i++)
{
delay(700);
cout << ".";
}
delay(500);
heading();
cout << "Successfully marked attendance of " << date << "
into " << sheetfile << ".csv file..." << endl;
getch();
}
};
int main()
{
int choice;
Attendance a;
do
{
heading();
cout << "1 -> Create new attendance sheet" << endl;
cout << "2 -> Add attendance" << endl;
cout << "3 -> Exit" << endl
<< endl;
cout << "Enter your choice -> ";
cin >> choice;
switch (choice)
{
case 1:
a.create_sheet();
break;
case 2:
a.add_attendance();
break;
case 3:
cout << endl
<< "Thank you..." << endl;
getch();
14
exit(0);
default:
cout << endl
<< "Invalid choice..." << endl
<< "Enter again..." << endl;
getch();
}
} while (1);
return 0;
}
void heading()
{
system("cls");
cout << "****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******" <<
endl;
cout << "--------------------------------------------------" <<
endl
<< endl;
}
15
PROGRAM OUTPUT
1.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
2.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
Enter file name (.csv) to import students roll no.s and names ->
studentdata
3.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
4.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
16
5.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
Enter file name which contains absent students roll no.s ->
absentstudents
Marking attendance...
6.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
7.
****** STUDENT ATTENDANCE MANAGEMENT SYSTEM ******
--------------------------------------------------
Thank you...
CONCLUSION
17
The main course outcome behind this micro-project was to implement file
handling concept in C++. Hence, after completing this micro-project, we think
that this course outcome is successfully achieved.
18
REFERENCES
www.google.com
www.youtube.com
www.geeksforgeeks.org
www.tutorialspoint.com
www.generalnote.com
www.javatpoint.com
www.programiz.com
www.w3schools.in
19