Leave Management System In C++ With Source Code

Leave Management System In C++ With Source Code

The Leave Management System In C++ With Source Code is developed using C++ programming language, this method is built on the idea of storing and generating all employee records and leave records.

A c++ employee leave management system goal is to assist you in organizing and maintaining the records of employees who have worked for an organization.

Additionally, the user has the ability to add, access, alter, and delete employee records as well as their leave. This project does not have a login system.

This employee leave management in c++ with source code is a basic employee database for an office or company where the user can conveniently store employee records and leave records because it is not time-consuming.

The Leave Management Framework was written in the C++ programming language and has a basic coding structure that makes it easy to understand the system’s functions.

This Leave Management System In C++ Open Source design is straightforward and clean, making it easy for users to learn, use, and navigate.

These are the following features of the system

  • Can Add new Employee
  • Modify Current Data
  • View All Employee List
  • Apply New Leave Application
  • Modify Current Leave Application

Anyway if you want level up your knowledge in programming especially C/C++ Programming Language, try this new article I’ve made for you Best C Projects with Source Code for Beginners Free Download.

To run this Leave Management System In C++ Free Download make sure that you have a Code Blocks or any platform of C++ installed in your computer.

Leave Management System In C++ With Source CodeSteps On How To Run The Project

Time needed: 5 minutes

These are the steps on how to run Leave Management System In C++ With Source Code

  • Step 1: Download

    First, download the source code given below.

    Leave-Management-System-In-C++-Step-1

  • Step 2: Extract file.

    Second, after you finished download the source code, extract the zip file.

  • Step 3: Open CodeBlocks

    Third, open “CodeBlocks IDE”.

  • Step 4: Open Project.

    Fourth, open file tab and Open File after that open folder LeaveSystem then click the “Leave Management System.cpp“.

  • Step 5: Run Project

    Fifth, run the project.
    Leave-Management-System-In-C++-Step-5

  • Step 6: The actual code.

    You are free to copy the given source code below or download the downloadable source code given.

The Code Given Below is the Actual Code of System

#include <iostream>
#include <cstdio>
#include <string.h>
#include <fstream>
#include <stdlib.h>
#include <sstream>
#define s6 "\t\t\t\t\t\t"
#define s5 "\t\t\t\t\t"
#define s4 "\t\t\t\t"
#define s3 "\t\t\t"
#define s2 "\t\t"
#define s1 "\t"
#define s0 ""
#define sp0 ""
#define sp1 " "
#define sp2 "  "
#define sp3 "   "
#define sp4 "    "
#define sp5 "     "
#define nl endl
#define cyp "Choose your option : "
using namespace std;
void recover(char* , char*);
float getSal(string );
class Employee
{
	public :
	string name, ssn, sal, age, exp, casual, sick, study, parental, sdate, edate, days;
	Employee(){
		casual="20",sick="15",study="10",parental="40",sdate="-",edate="-",days="0";
	}
	void deleteLeave();
	void searchLeave();
	void modLeave();
	void dispLeave();
	void addUser();
	void modUser();
};

void addUser()
{
	Employee e;
	cout<<nl<<s2<<"--- A D D  U S E R ---"<<nl<<nl;
	cout<<s2<<sp2<<"Enter the ID : ";
	cin>>e.ssn;
	e.ssn.resize(8);
	cout<<s2<<sp2<<"Enter the Name : ";
	cin>>e.name;
	e.name.resize(8);
	cout<<s2<<sp2<<"Enter the Age : ";
	cin>>e.age;
	e.age.resize(8);
	cout<<s2<<sp2<<"Enter the Salary : ";
	cin>>e.sal;
	e.sal.resize(8);
	cout<<s2<<sp2<<"Enter the Experience : ";
	cin>>e.exp;
	e.exp.resize(8);
	fstream file1,file2,file3;
	file1.open("emp.txt",ios::binary|ios::app);
	file2.open("leave.txt",ios::binary|ios::app);
	file3.open("salary.txt",ios::binary|ios::app);
	if(!file1||!file2){
        system("cls");
		cout<<s4<<"Error Occured!"<<nl;
		return;
	}
	e.casual=e.casual+"/20-0",e.sick=e.sick+"/15-0",e.study=e.study+"/10-0",e.parental=e.parental+"/40-0";
	e.casual.resize(10),e.sick.resize(10),e.study.resize(10),e.parental.resize(10),e.sdate.resize(10),e.edate.resize(10),e.days.resize(5);
	file1<<"\t|"<<e.ssn<<"|\t"<<e.name<<"|"<<e.age<<"|"<<e.sal<<"|"<<e.exp<<"|"<<nl;
	file2<<e.ssn<<"|"<<e.name<<"|"<<e.casual<<"|"<<e.sick<<"|"<<e.study<<"|"<<e.parental<<"|"<<e.sal<<"|"<<e.sdate<<"|"<<e.edate<<"|"<<e.days<<"|"<<nl;
	file3<<e.ssn<<"|"<<e.sal<<"|"<<nl;
	file1.close();
	file2.close();
	file3.close();

	cout<<s4<<"User added successfully!"<<nl<<nl<<nl;
}

void modUser()
{
	char ch;
	string id,str;
	int found=0,count=0;
	fstream file1,file2;
	file1.open("emp.txt",ios::binary|ios::in);
	cout<<nl<<s2<<"--- M O D I F Y  U S E R ---"<<nl<<nl;
	cout<<s2<<sp4<<"Enter Employee ID : ";
	cin>>id;
	id.resize(8);
	if(!file1){
        system("cls");
		cout<<s4<<"Error Occured"<<nl;
		return;
	}
	int index=5;
	while(file1){
		file1.seekg(index, ios::beg);
		getline(file1,str,'|');

		if(str==id){
			found=1;
			break;
	    }
		else{
			index+=51;
			str.clear();
			count++;
		}
	}
	file1.close();
	if(found==1)
	{
		start:
		int ch,beg,end;
		string newstr,str;
		cout<<s4<<"1. EDIT AGE"<<nl;
		cout<<s4<<"2. EDIT SALARY"<<nl;
		cout<<s4<<"3. EDIT EXPERIENCE"<<nl<<nl;
		cout<<s4<<cyp;
		cin>>ch;
		cout<<nl;
		if(ch==1 || ch==2 || ch==3){
			cout<<s4<<"Enter the new value : ";
			cin>>newstr;
		}
		else
			goto start;
		newstr.resize(8);

		file1.open("emp.txt",ios::binary|ios::in);
		file2.open("temp.txt",ios::binary|ios::app);

		while(count--){
		getline(file1,str);
		file2<<str<<endl;
	    }
	    if(ch==1)
	    beg=3,end=2;
		else if(ch==2)
		beg=4,end=1;
		else if(ch==3)
		beg=5,end=0;
	    for(int i=0;i<beg;i++){
	    	getline(file1,str,'|');
	    	file2<<str<<"|";
	    }

	    file2<<newstr<<"|";
	    getline(file1,str,'|');
	    for(int i=0;i<end;i++){
	    	getline(file1,str,'|');
	    	file2<<str<<"|";
	    }

	    while(file1){
	    	getline(file1,str);
	    	file2<<str;
	    	if(file1)
	    	file2<<endl;
	    }
	    file1.close();
	    file2.close();
	    cout<<s4<<"Employee has been updated!"<<nl<<nl;
	    char fn1[]="emp.txt",fn2[]="temp.txt";
	   	recover(fn1,fn2);


	}
	else
		cout<<s2<<sp4<<"Employee not found!"<<nl<<nl;

}
void recover(char *fn1,char *fn2)
{
	remove(fn1);
	rename(fn2,fn1);
}

void displayUsers()
{
	string str;
	fstream file;
	file.open("emp.txt",ios::binary|ios::in);
	if(!file){
        system("cls");
		cout<<s4<<"Error Occured"<<nl;
		return;
	}
	cout<<nl<<"\tEmployee ID"<<s2<<"Name"<<s2<<"Age"<<s2<<"Salary"<<s1<<sp2<<"Experience"<<nl<<nl;
	while(file){
		getline(file,str,'|');
		cout<<str;
	}
	file.close();
	int t=80;
	cout<<nl;
	while(t--)
		cout<<"-";
	cout<<nl<<nl;
	file.close();
}

void modLeave()
{
	string id,str;
	int found=0,count=0;
	fstream file1,file2;
	file1.open("leave.txt",ios::binary|ios::in);
	cout<<nl<<s2<<"--- A P P L Y  L E A V E ---"<<nl<<nl;
	cout<<s2<<sp4<<"Enter the Employee ID : ";
	cin>>id;
	cout<<nl;
	id.resize(8);
	if(!file1){
        system("cls");
		cout<<s4<<"Error Occured"<<nl;
		return;
	}
	int index=0;
	while(file1){
		file1.seekg(index, ios::beg);
		getline(file1,str,'|');
		if(str==id){
			found=1;
			break;
		}
		else{
			index+=100;
			str.clear();
			count--;
		}
	}
	file1.close();
	if(found==1)
	{
		start:
		string sdate,edate;
		int ch,com=7,beg,end,nol,ex=0,lea,tot,days=0,leave,nod;
		float sal,per;
		cout<<s2<<sp4<<"1. CASUAL LEAVE"<<nl;
		cout<<s2<<sp4<<"2. SICK LEAVE"<<nl;
		cout<<s2<<sp4<<"3. STUDY LEAVE"<<nl;
		cout<<s2<<sp4<<"4. PARENTAL LEAVE"<<nl<<nl;
		cout<<s0<<cyp;
		cin>>ch;
		cout<<"=========================================================";
		cout<<nl;
		if(ch==1){ beg=0,end=3,tot=20,per=.08; }
		else if(ch==2){ beg=1,end=2,tot=15,per=0.05;}
		else if(ch==3){ beg=2,end=1,tot=10,per=0.03;}
		else if(ch==4){ beg=3,end=0,tot=40,per=0.15;}
		file1.open("leave.txt",ios::binary|ios::in);
		file2.open("temp1.txt",ios::binary|ios::app);
		while(count--){
			getline(file1,str);
			file2<<str<<endl;
		}
		for(int i=0;i<2;i++){
			getline(file1,str,'|');
			file2<<str<<"|";
		}
		for(int i=0;i<beg;i++){
			getline(file1,str,'|');
			file2<<str<<"|";
		}
		cout<<s2<<sp4<<"Enter the number of leaves : ";
		cin>>nol;
		getline(file1,str,'|');
		stringstream buf1(str);
		buf1>>lea;
		leave=lea;
		if(lea-nol<0)
		days=abs(lea-nol);
		lea=lea-nol;
		if(days!=0)
		lea=0;
		fstream buf2;
		buf2.open("mod.txt",ios::binary|ios::out);
		buf2<<lea<<"/"<<tot<<"-"<<days;
		buf2.close();
		buf2.open("mod.txt",ios::binary|ios::in);
		getline(buf2,str);
		buf2.close();
		remove("mod.txt");
		str.resize(10);
		file2<<str<<"|";
		for(int i=0;i<end;i++){
			getline(file1,str,'|');
			file2<<str<<"|";
		}
		getline(file1,str,'|');
		sal=getSal(id);

		if(leave-nol<0)
		sal=sal-(float)sal*per*abs(tot-leave);

		ostringstream buf4;
		buf4<<sal;
		str=buf4.str();;
		str.resize(8);
		file2<<str<<"|";

		cout<<s2<<sp4<<"Enter the Start Date(dd/mm/yyyy) : ";
		cin>>sdate;
		cout<<s2<<sp4<<"Enter the End Date(dd/mm/yyy) : ";
		cin>>edate;
		sdate.resize(10);
		edate.resize(10);
		file2<<sdate<<"|";
		file2<<edate<<"|";
		for(int i=0;i<3;i++)
		getline(file1,str,'|');

		stringstream buf5(str);
		buf5>>nod;
		nod=nod+nol;

		ostringstream buf6;
		buf6<<nod;
		str=buf6.str();
		str.resize(5);
		file2<<str<<"|";

		while(file1){
			getline(file1,str);
			file2<<str;
			if(file1)
			file2<<endl;
		}
		file1.close();
		file2.close();
		char fn1[]="leave.txt",fn2[]="temp1.txt";
		recover(fn1,fn2);
		cout<<s4<<"Leave updated!"<<nl<<nl;
	}
	else
		cout<<s4<<"User not found!"<<nl<<nl;
}

void dispLeave()
{
	string str;
	fstream file;
	file.open("leave.txt",ios::binary|ios::in);
	if(!file){
        system("cls");
		cout<<s4<<"Error Occured"<<nl;
		return;
	}
	cout<<nl<<"Employee ID\t"<<"Name\t\t"<<"CL(20)\t\t"<<"SL(15)\t\t"<<"STL(10)\t\t"<<"PL(40)\t\t"<<"Salary\t\t"<<"Start Date"<<sp2<<sp2<<"End Date"<<sp2<<sp2<<"NoofLeaves"<<nl<<nl;
	while(file){
		getline(file,str,'|');
		cout<<str<<"\t";
	}
	cout<<nl<<nl;
	cout<<"Note : This table shows remaining leaves."<<nl<<sp2<<"CL : CASUAL LEAVE"<<nl<<sp2<<"SL : SICK LEAVESEAVE"<<nl<<sp2<<"STL : STUDY LEAVE"<<nl<<sp2<<"PL : PARENTAL LEAVE"<<nl<<sp2<<"Number after '-' sign indicates extra leaves."<<nl<<nl;
	file.close();
}

void deleteLeave()
{
	string id,str;
	int found=0,count=0;
	fstream file1,file2;
	file1.open("leave.txt",ios::binary|ios::in);
	cout<<s2<<"--- D E L E T E  L E A V E ---"<<nl<<nl;
	cout<<s2<<sp4<<"Enter the Employee ID to delete : ";
	cin>>id;
	id.resize(8);
	if(!file1){
        system("cls");
		cout<<s2<<sp4<<"Error Occured"<<nl;
		return;
	}
	int index=0;
	while(file1){
		file1.seekg(index,ios::beg);
		getline(file1,str,'|');
		if(str==id){
			found=1;
			break;
		}
		else{
			index+=100;
			str.clear();
			count=count+1;
		}
	}
	file1.close();
	if(found==1)
	{
		file1.open("leave.txt",ios::binary|ios::in);
		file2.open("temp1.txt",ios::binary|ios::app);
		while(count>0){
			getline(file1,str);
			file2<<str;
			count=count-1;
			if(count>0)
			file2<<nl;
		}
		for(int i=0;i<2;i++){
			getline(file1,str,'|');
			file2<<str<<"|";
		}
		str="20/20-0";str.resize(10);
		file2<<str<<"|";
		str="15/15-0";str.resize(10);
		file2<<str<<"|";
		str="10/10-0";str.resize(10);
		file2<<str<<"|";
		str="40/40-0";str.resize(10);
		file2<<str<<"|";
		float sal=getSal(id);
		ostringstream buf;
		buf<<sal;
		str=buf.str();
		str.resize(8);
		file2<<str<<"|";
		str="-";str.resize(10);
		file2<<str<<"|"<<str<<"|";
		str="0";str.resize(10);
		file2<<str<<"|";
		for(int i=0;i<8;i++)
			getline(file1,str,'|');
		while(file1){
			getline(file1,str);
			file2<<str;
			if(file1)
			file2<<endl;
		}
		file1.close();
		file2.close();
		char fn1[]="leave.txt",fn2[]="temp1.txt";
		recover(fn1,fn2);
	}
	else
		cout<<s2<<sp4<<"User not found!"<<nl;
}

float getSal(string id)
{
	fstream file;
	float sal;
	string str;
	file.open("salary.txt",ios::binary|ios::in);
	if(!file){
        system("cls");
		cout<<s4<<"Error Occured"<<nl;
		return 0;
	}
	while(file){
		getline(file,str,'|');
		str.resize(8);
		if(str==id)
			break;
	}
	str.clear();
	getline(file,str,'|');
	stringstream buf(str);
	buf>>sal;
	file.close();
	return sal;
}
void searchLeave()
{
	string id,str;
	cout<<nl<<s2<<"--- S E A R C H  L E A V E ---"<<nl<<nl;
	cout<<s2<<sp4<<"Enter the Employee ID : ";
	cin>>id;
	id.resize(8);
	fstream file;
	file.open("leave.txt",ios::binary|ios::in);
	if(!file){
        system("cls");
		cout<<s4<<"Error Occured"<<nl;
		return;
	}
	while(file){
		getline(file,str,'|');
		str.resize(8);
		if(str==id){
			break;
		}
	}
	cout<<nl<<"Employee ID\t"<<"Name\t\t"<<"CL(20)\t\t"<<"SL(15)\t\t"<<"STL(10)\t\t"<<"PL(40)\t\t"<<"Salary\t\t"<<"Start Date"<<sp2<<sp2<<"End Date"<<sp2<<sp2<<"NoofLeaves"<<nl<<nl;
	cout<<str<<"\t";
	for(int i=0;i<9;i++){
		getline(file,str,'|');
		cout<<str<<"\t";
	}
	file.close();
	cout<<nl<<nl;
}
int main()
{
	while(true){
	start:
	int ch;
	cout<<"========================================================="<<nl;
	cout<<s0<<"------ L E A V E  M A N A G E M E N T  S Y S T E M ------"<<nl;
	cout<<"=========================================================    "<<nl<<nl;
	cout<<s2<<"--- M A I N  M E N U ---"<<nl<<nl;
	cout<<s2<<sp4<<"1. APPLY LEAVE"<<nl;
	cout<<s2<<sp4<<"2. DELETE LEAVE"<<nl;
	cout<<s2<<sp4<<"3. SEARCH LEAVE"<<nl;
	cout<<s2<<sp4<<"4. MODIFY LEAVE"<<nl;
	cout<<s2<<sp4<<"5. DISPLAY ALL LEAVES"<<nl;
	cout<<s2<<sp4<<"6. USER MANAGEMENT"<<nl;
	cout<<s2<<sp4<<"7. EXIT"<<nl;
	cout<<nl<<s0<<cyp;
	cin>>ch;
    cout<<"=========================================================";
	cout<<nl;
	switch(ch)
	{
		case 1:
			modLeave();
			break;
		case 2:
			deleteLeave();
			break;
		case 3:
			searchLeave();
			break;
		case 4:
			modLeave();
			break;
		case 5:
		 	dispLeave();
		 	break;
		case 6:
			int ch1;
			cout<<nl<<s2<<"--- U S E R  M E N U ---"<<nl<<nl;
			cout<<s2<<sp4<<"1. ADD USER"<<nl<<s2<<sp4<<"2. MODIFY USER"<<nl;
			cout<<s2<<sp4<<"3. SHOW ALL USERS"<<nl;
			cout<<nl<<s0<<cyp;
			cin>>ch1;
			cout<<"=========================================================";
			cout<<nl;
			if(ch1==1)
			addUser();
			else if(ch1==2)
			modUser();
			else if(ch1==3)
			displayUsers();
			break;

		case 7:
			exit(0);

		default : goto start;
	 }
	}
	return 0;
}

ABOUT PROJECTPROJECT DETAILS
Project Name :leave system
Project Platform :C/C++
Programming Language Used:C++ Programming Language
Developer Name :itsourcecode.com
IDE Tool (Recommended):Dev-C++/Codeblocks
Project Type :Desktop Application
Database:Stores data in .DAT file
Upload Date and Time:March 25, 2021- 9:17 am
Leave System In C++ With Source Code Information

Downloadable Source Code

Conclusion

This leave system in C++ is only a project made for school requirement purposes only.

You can download this source code and modify it to suit your client requirements, since this is a student project it means you cannot really expect 100% functionality from this.

Inquiries

If you have any questions or suggestions about leave monitoring system C++, please feel free to leave a comment below.

Leave a Comment