Attendance Management System Project Using C++ Language

Last updated Jan 27, 2022

In this Cpp projects list, we will see how to build the ATTENDANCE MANAGEMENT SYSTEM project using C++ programming language. This project is  control of student attendance. Admin can generate usernames and passwords for students and register them. Students may log in, indicate attendance for the same day, and view their attendance history.
 

FEATURES OF ATTENDANCE MANAGEMENT SYSTEM PROJECT

1.This project control the attendance of student.

2. Admin can generate username and password for student and register them.

3. Students may login and mark there attendance for the same day, and also view their attendance history.

4. This project written and compiled in C++ and g++ respectively.

 

IMPLEMENTATION
 

Step 1. Create a new Project in Dev C++

File > New >  Source File  or Ctrl + N

 

Step 2. First of all we will include all the header file

#include
#include
#include
#include


Step 3. using namespace std:
The using namespace statement simply means that all things in the std namespace are available in the scope in which it is present, without the need to prefix them with std:.
 

Step 4. We have to create all these function which are mentioned below:

int adminView();
int studentView();
int studentLogin();
int checkCredentials(string userName, string password);
int getAllStudentsbyRollNo();
int deleteAllStudents();
int deleteStudentbyRollno();
int checkListOfStudentsRegistered();
int checkPresenseCountbyRollno();
int getListOfStudentsWithTheirPresenseCount();
int registerStudent();
int adminLogin();
int registerStudent();
int markMyAttendance(string username);
int countMyAttendance(string username);
int delay();

 

The code of adminView() function
After entering the username and password in admin  we will this type of menu. which include some function like register a student,delete all student name registered, delete student by roll no. so on.

int adminView()
{    
int goBack = 0;
while(1)
{
system("cls");
cout<<"\n 1 Register a Student";
cout<<"\n 2 Delete All students name registered";
cout<<"\n 3 Delete student by rollno";
cout<<"\n 4 Check List of Student registered by userame";
cout<<"\n 5 Check presense count of any student by Roll No";
cout<<"\n 6 Get List of student with their attendance count";
cout<<"\n 0. Go Back <- \n";
int choice;

cout<<"\n Enter you choice: ";
cin>>choice;

switch(choice)
{
    case 1: registerStudent();break;  
    case 2: deleteAllStudents(); break;
    case 3: deleteStudentbyRollno(); break;
    case 4: checkListOfStudentsRegistered(); break;
    case 5: checkPresenseCountbyRollno(); break;
    case 6: getListOfStudentsWithTheirPresenseCount(); break;
    case 0: goBack = 1;break;
    default: cout<<"\n Invalid choice. Enter again ";
    getchar();               
}   

if(goBack == 1)
{
break;
}     

}

return 0;
}

The code of studentView() function

In student login, students will enter their username and password and mark their attendance and can also check attendance count. 

int studentView()
{
cout<<"\n ------- Student Login-------- \n";        

string username, password;

cout<<"\n Enter username : ";
cin>>username;

cout<<"\n Enter password : ";
cin>>password;

int res = checkStudentCredentials(username, password);

if(res  == 0)
{
   cout<<"\n Invalid Credentials !!";
   cout<<"\n Press any key for Main Menu..";
   getchar(); getchar();    
   return 0;

int goBack = 0;
while(1)
{
system("cls");

cout<<"\n 1 Mark Attendance fo Today ";
cout<<"\n 2 Count my Attendance";
cout<<"\n 0. Go Back <- \n";
int choice;

cout<<"\n Enter you choice: ";
cin>>choice;

switch(choice)
{
    case 1: markMyAttendance(username); break;
    case 2: countMyAttendance(username); break;
    case 0: goBack = 1;break;
    default: cout<<"\n Invalid choice. Enter again ";
    getchar();               
}   

if(goBack == 1)
{
break; //break the loop
}     
    
}
   
}

 

The code of studentLogin() function
Student login is calling two function 
1. studentView()
2. delay()

int studentLogin()
{
system("cls");
cout<<"\n -------- Student Login ---------";    
studentView();
delay();
return 0; 
}

 

The code for checkStudentCredentials(string userName, string password) function
To read or open a.dat file, you must first determine its type, and then convert it to make it easier to open. This check student is already exist or not.

int checkStudentCredentials(string username, string password)
{

ifstream read;
read.open("db.dat");

if (read) {
int recordFound = 0;
string line;
string temp = username + password + ".dat";
cout<<"\n file name is : "< while(getline(read, line)) {
    if(line == temp)
    {
        recordFound = 1;
        break;
    }
}

if(recordFound == 0)
    return 0;
else
   return 1;
}
else
{
   return 0;
}
            
}

 

The code of getAllStudentsbyRollNo() function
It shows all the student by their roll no.

int getAllStudentsbyRollNo()
{
cout<<"\n List of All Students by their Roll No \n";

cout<<"\n Please any key to continue..";
getchar();getchar();

return 0;        
    
}

 

The code of deleteAllStudents() function
It deletes the data of all student.

int deleteAllStudents()
{
cout<<"\n In delete all students !!";
cout<<"\n Please any key to continue..";
//todo: implement this functionality

getchar(); getchar();
return 0;
}

 

The code of deleteStudentbyRollno() function
This function will delete the particular student details by using their Roll no.

int deleteStudentbyRollno()
{
    
cout<<"\n Delete any Student by their Roll No \n";        

cout<<"\n Please any key to continue..";
getchar();getchar();

return 0;
}

 

The code of  checkListOfStudentsRegistered() function
It gives list of all registered student.

int checkListOfStudentRegistered()
{
cout<<"\n List of All registered registered !!";
cout<<"\n Please any key to continue..";

getchar();
getchar();
return 0;
}

 

The code of checkPresenseCountbyRollno() function
It Check presence count of any Student by Roll No.

int checkPresenseCountbyRollno()
{
cout<<"\n Check presense count of any Student by Roll No \n";    

cout<<"\n Please any key to continue.."    ;
getchar();getchar();

return 0;    
}

 

The code of getListOfStudentsWithTheirPresenseCount() function
It gives all Students with their presence count 

int getListOfStudentsWithTheirPresenseCount()
{
cout<<"\n All Students with their Presense count !!";
cout<<"\n Please any key to continue..";

getchar(); 
getchar();
return 0;
}

 

The code of registerStudent() function
This function takes all detail of student and create student username and password and it also check that student is already exist or not.

int registerStudent()
{
    cout<<"\n ----- Form to Register Student ---- \n";    

    string name, username, password, rollno, address, father, mother;
    
    cout<<"\n Enter Name : ";     cin>>name;
    cout<<"\n Enter Username : ";     cin>>username;
    cout<<"\n Enter password : ";     cin>>password;
    cout<<"\n Enter rollno : ";     cin>>rollno;
    getchar();
    
    char add[100];
    cout<<"\n Enter address : ";     cin.getline(add, 100);
    cout<<"\n Enter father : ";     cin>>father;
    cout<<"\n Enter mother : ";     cin>>mother;
    
    ifstream read;
    read.open("db.dat");
    
    if(read)
    {   int recordFound =0; 
       string line;
        while(getline(read, line)) {
        if(line == username+".dat" )
        {
            recordFound = 1 ;
            break;
        }
        }
        if(recordFound == 1)
        {
        cout<<"\n Username already Register. Please choose another username ";
        getchar(); getchar();
        delay();
        read.close();
        return 0;
        }
    }
    read.close();

    ofstream out;
    out.open("db.dat", ios::app);
    out<     out.close();

    ofstream out1;
    string temp = username+".dat";
    out1.open(temp.c_str());
    out1<     out1<     out1<     out1.close();

    cout<<"\n Student Registered Successfully !!";
    
    cout<<"\n Please any key to continue..";
    getchar(); getchar();
    return 0;        
}

 

The code of adminLogin() function
In this we enter admin username and password. then is call adminView() ,delay() functions.

int adminLogin()
{
system("cls");
cout<<"\n --------- Admin Login --------";    

string username;
string password;

cout<<"\n Enter username : ";
cin>>username;
cout<<"\n Enter password : ";
cin>>password;

if(username=="ADMIN" && password=="ADMIN@123") 
{
    adminView();
    getchar();    
    delay();
}   
else
{
cout<<"\n Error ! Invalid Credintials..";    
cout<<"\n Press any key for main menu ";
getchar();getchar();
}

return 0;
}

 

The code of markMyAttendance(string username) function
This function mark the attendance of student.

int markMyAttendance(string username)
{
cout<<"\n Mark Attendance for today !!";    
cout<<"\n Please any key to continue..";

getchar();
getchar();

return 0;    

Step 18. int countMyAttendance(string username);
Count the attendance of student. 

int countMyAttendance(string username)
{
cout<<"\n Count my attendance for today !!";    
cout<<"\n Please any key to continue..";

getchar();getchar();

return 0;    

 

The code of delay() function
It saves the record.

int delay()
{
for(int i = 0; i<3; i ++)
{
    cout<<"\n Saving Records ...";
    for(int ii = 0; ii<20000; ii ++)
    {
        for(int iii = 0; iii<20000; iii ++)
           { }
    }
}
   
cout<<"\n Exiting Now ...";
for(int i = 0; i<3; i ++){
   for(int ii = 0; ii<20000; ii ++) { 
     for(int iii = 0; iii<20000; iii ++){
     }
    } 
}

 

Step 5. Finally, we will code for main() function and run the project.
This is the very important function of every c++ program . And in this project this main function shows the main menu which include these following functions:
1. student login
2. admin login 
3. exit

Remember:
Admin Username:
"ADMIN" & Admin Password: "ADMIN@123" 

 

int main(int argc, char** argv) {
    
while(1)
{
    system("cls");
    cout<<"\n Attendance Management System \n";
    cout<<"-------------------------------------\n\n";
    
    cout<<"1. Student Login\n";
    cout<<"2. Admin Login\n";
    
    cout<<"0. Exit\n";
    int choice;
    
    cout<<"\n Enter you choice: ";
    cin>>choice;
    
    switch(choice)
    {
    case 1: studentLogin(); break;
    case 2: adminLogin(); break;
    case 0: 
            while(1)
            {
            system("cls");
            cout<<"\n Are you sure, you want to exit? y | n \n";
            char ex;
            cin>>ex;
            if(ex == 'y' || ex == 'Y')
               exit(0);
            else if(ex == 'n' || ex == 'N')
             {
                  break;
             }
             else{
                 cout<<"\n Invalid choice !!!";
                 getchar();
             }

            }
            break;
                  
    default: cout<<"\n Invalid choice. Enter again ";
    getchar();
    }                   

}
    
return 0;
}  

 

Output

Main Screen

Attendance Management System project with Cpp


Admin Login Screen

Attendance Management System project with Cpp 2


Admin View Screen

Attendance Management System project with Cpp 3


Student Registration Screen

Attendance Management System project with Cpp 4


Registered Student Screen

Attendance Management System project with Cpp 5

 

Student Login Screen

Attendance Management System project with Cpp 6


Delete All Students Screen

Attendance Management System project with Cpp 7

 

Conclusion: In this article, we have covered how to build  Attendance Management System Project using C++ programming language.

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

5646 Views