Practical No-01 Implementation of Employee Attendance and Salary Calculator
Learn to develop a C++ program for employee attendance and payroll calculation using data types, control structures, functions, ENUM, and scope resolution operator.
Practical No-01 Implementation of Employee Attendance and Salary Calculator
1.
Class: S.Y.B. Tech.Semester: III
Subject: Object Oriented Programming Laboratory (PCIT212)
Practical No.: 01
CO1: Develop C++ programs using fundamental programming constructs and object-oriented concepts
for solving practical problems.. (BTL-Apply)
---------------------------------------------------------------------------------------------------------------------------------------
1. Aim
To implement an Employee Attendance and Salary Calculator for multiple employees using data types,
operators, control structures, arrays, functions, reference variables, inline functions, scope resolution
operator, and ENUM data type in C++.
2. Course Outcome Mapping
CO1: Develop C++ programs using fundamental programming constructs and object-oriented concepts for
solving practical problems.
3. Learning Objectives
After completing this experiment, students will be able to:
1. Understand the role of fundamental C++ programming constructs in software development.
2. Apply data types, operators, arrays, and control structures to solve real-world problems.
3. Develop modular programs using functions.
4. Utilize reference variables and inline functions effectively.
5. Apply ENUM data type and scope resolution operator in application development.
6. Design a simple payroll application based on industry requirements.
4. Learning Outcomes
Upon successful completion of this experiment, students will be able to:
1. Implement C++ programs using basic programming constructs.
2. Develop a simple Human Resource Management System module.
3. Perform salary calculations using programming logic.
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 2001:2018 Certified
Department of Information Technology
NBA Accredited-UG Programme
2.
4. Analyze anddebug C++ programs.
5. Interpret and validate generated outputs.
5. Software and Hardware Requirements
1. Software Requirements
Operating System: Windows/Linux
Compiler: GCC, MinGW, Code::Blocks, Visual Studio Code
Programming Language: C++
2. Hardware Requirements
Intel Core i3 Processor or higher
4 GB RAM minimum
10 GB free disk space
6. Real-Time Industry Scenario
Human Resource Management System (HRMS)
Human Resource Management Systems are software applications used by organizations to manage
employee information, attendance records, payroll processing, leave management, and performance
evaluation.
Large organizations such as Infosys, TCS, Wipro, Accenture, Cognizant, and Capgemini maintain
attendance records for thousands of employees. At the end of every month, payroll software automatically
calculates employee salaries based on attendance, overtime, incentives, and deductions.
1. Payroll Processing Workflow
1. Employee attendance is recorded.
2. Attendance records are verified.
3. Basic salary is calculated.
4. Overtime compensation is added.
5. Leave deductions are applied.
6. Bonus is calculated.
7. Final salary slip is generated.
3.
The Employee Attendanceand Salary Calculator developed in this experiment
simulates a simplified payroll module of an HRMS.
7. Theory
7.1 Data types
Definition:
A data type specifies the type of data that can be stored in a variable. It determines
the memory allocation and operations that can be performed on the data.
Syntax:
datatype variable_name;
Example:
In an HRMS:
Information Data Type
Employee ID int
Employee Name string
Attendance
Days
int
Salary float
Grade char
Example:
int empId = 101;
string empName =
"Arun"; float salary =
45000.50;
Industry Usage:
Payroll software stores employee records using appropriate data types to ensure
efficient processing and storage.
Advantages:
Efficient memory utilization
Better data management
Improved program reliability
4.
7.2 Operators
Definition:
Operators arespecial symbols used to perform mathematical, logical, and relational
operations on variables and values.
Syntax:
operand operator operand;
Example:
Salary Calculation:
salary = attendanceDays * perDaySalary;
Bonus Calculation:
bonus = salary * 0.10;
Industry Usage:
Used extensively in payroll systems, banking applications, inventory management
systems, and billing software.
Advantages:
Simplifies calculations
Reduces coding complexity
Improves readability
7.3 Control Structures
Definition:
Control structures determine the flow of program execution.
Types:
1. Selection Statements
2. Iteration Statements
3. Jump Statements
Syntax:
If Statement:
if(condition)
{
statements;
}
5.
For Loop:
for(initialization;condition;increment)
{
statements;
}
Example:
Employee bonus eligibility:
if(attendanceDays >= 26)
{
bonus = salary * 0.10;
}
Industry Usage:
Used in decision-making processes such as:
Loan approval
Salary processing
Insurance claim validation
Student result processing
7.4 Arrays
Definition:
An array is a collection of similar data elements stored at contiguous memory locations.
Syntax:
datatype array_name[size];
Example:
Attendance records for
employees: int attendance[50];
Industry Usage:
Arrays are used to store:
Employee attendance
Student marks
Inventory quantities
Sales records
6.
Advantages:
Efficientstorage
Easy access to multiple records
Reduced coding effort
7.5 Functions
Definition:
A function is a reusable block of code that performs a specific task.
Syntax:
returnType functionName(parameters)
{
statements;
}
Example:
Payroll software commonly contains:
calculateSalary();
calculateBonus();
generateReport();
Industry Usage:
Functions improve modularity, maintainability, and code reusability.
Advantages:
Reduces code duplication
Simplifies debugging
Improves readability
7.6 Reference Variables
Definition:
A reference variable acts as an alias for another variable.
Syntax:
datatype &reference_name = variable_name;
7.
Example:
float salary= 25000;
float &netSalary =
salary; Industry
Usage:
Used for efficient parameter passing and memory optimization.
7.7 Inline Functions
Definition:
An inline function is expanded at the point where it is called, reducing function call
overhead.
Syntax:
inline returnType functionName(parameters)
{
statements;
}
Example:
inline float calculateBonus(float salary)
{
return salary * 0.10;
}
Industry Usage:
Used in performance-sensitive applications and embedded systems.
7.8 Scope Resolution Operator
Definition:
The scope resolution operator (::) is used to access global variables and class members.
Syntax:
::variable_name
Example:
string company = "ABC Technologies";
cout<<::company;
8.
Industry Usage:
Usedin large enterprise applications for accessing global configuration values.
7.9 ENUM Data Type
Definition:
ENUM is a user-defined data type consisting of named constants.
Syntax:
enum Department
{
IT,
HR,
Finance,
Sales
};
Example:
Employees belong to different departments.
Department dept = IT;
Industry Usage:
ENUM is widely used for:
Department Types
Employee Categories
Order Status
Payment Status
Leave Categories
8. Problem Statement:
Design and implement an Employee Attendance and Salary Calculator for multiple
employees using C++ programming constructs such as data types, operators,
control structures, arrays, functions, reference variables, inline functions, scope
resolution operator, and ENUM data type.
9.
The systemshould calculate:
Basic Salary
Overtime Pay
Bonus
Leave Deduction
Net Salary
and generate a payroll report for each employee.
9. Algorithm
1. Start
2. Declare company name as a global variable.
3. Define ENUM for employee departments.
4. Read the number of employees.
5. For each employee:
Accept Employee ID
Accept Employee Name
Accept Department
Accept Attendance Days
Accept Per Day Salary
Accept Overtime Hours
6. Calculate Basic Salary.
7. Calculate Overtime Pay.
8. Calculate Bonus.
9. Calculate Leave Deduction.
10. Calculate Net Salary.
11. Display employee payroll details.
12. Repeat for all employees.
13. Stop.
10.
10. Pseudo code
BEGIN
DECLAREcompanyName
ENUM Department
{
IT,
HR,
FINANCE,
SALES
}
INPUT
numberOfEmployees FOR
each employee
INPUT employeeID
INPUT employeeName
INPUT department
INPUT attendanceDays
INPUT perDaySalary
INPUT overtimeHours
basicSalary = attendanceDays *
perDaySalary overtimePay =
overtimeHours * 200
IF attendanceDays >= 26
bonus = basicSalary *
0.10
ELSE
bonus = basicSalary * 0.05
ENDIF
leaveDeduction = (30 - attendanceDays) * 100
netSalary =basicSalary + overtimePay + bonus - leaveDeduction
DISPLAY payroll report
END FOR
END
11.
11. Sample code
#include<iostream>
#include<string>
usingnamespace std;
// Global variable to demonstrate Scope Resolution Operator
string companyName = "AVI Technologies Pvt. Ltd.";
// ENUM to represent employee departments
enum Department
{
IT = 1,
HR,
FINANCE
, SALES
};
// Inline function to calculate bonus
// Employees having basic salary greater than 25000
// receive 10% bonus otherwise 5%
inline float calculateBonus(float basicSalary)
{
if(basicSalary > 25000)
return basicSalary *
0.10;
else
return basicSalary * 0.05;
}
// Function to calculate overtime payment
// Company pays Rs. 200 per overtime hour float
calculateOvertime(float overtimeHours)
{
12.
return overtimeHours *200;
}
// Function using reference variable
// Net salary is returned through reference parameter void
calculateNetSalary(float &netSalary,
float basicSalary,
float overtimePay,
float bonus,
float leaveDeduction)
{
netSalary = basicSalary + overtimePay + bonus - leaveDeduction;
}
int main()
{
int n;
// Accessing global variable using Scope Resolution
Operator cout<<"Company Name :
"<<::companyName<<endl;
cout<<"nEnter Number of Employees : ";
cin>>n;
// Arrays to store multiple employee
records int empId[50];
string empName[50];
int
attendanceDays[50];
float
perDaySalary[50];
float overtimeHours[50];
13.
// Input employeedetails
for(int i=0;i<n;i++)
{
cout<<"nEmployee "<<i+1<<" Details"<<endl;
cout<<"Enter Employee ID :
"; cin>>empId[i];
cout<<"Enter Employee Name : ";
cin>>empName[i];
cout<<"Enter Attendance Days : ";
cin>>attendanceDays[i];
cout<<"Enter Per Day Salary : ";
cin>>perDaySalary[i];
cout<<"Enter Overtime Hours : ";
cin>>overtimeHours[i];
}
cout<<"n========== PAYROLL REPORT ==========n";
// Processing payroll for all employees
for(int i=0;i<n;i++)
{
float basicSalary;
float overtimePay;
float bonus;
float leaveDeduction;
float netSalary;
14.
// Basic salarycalculation
basicSalary = attendanceDays[i] * perDaySalary[i];
// Overtime amount calculation
overtimePay =calculateOvertime(overtimeHours[i]);
// Bonus calculation using inline function
bonus =calculateBonus(basicSalary);
// Leave deduction
// Assuming 30 working days in a month
// Rs.100 deduction per absent day
leaveDeduction =(30 - attendanceDays[i]) * 100;
// Net salary calculation using reference variable
calculateNetSalary(netSalary, basicSalary, overtimePay, bonus,
leaveDeduction);
// Display payroll report
cout<<"nEmployee ID : "
<<empId[i];
cout<<"nEmployee Name : "
<<empName[i];
cout<<"nBasic Salary : "
<<basicSalary;
15.
cout<<"nOvertime Pay :"
<<overtimePay;
cout<<"nBonus : "
<<bonus;
cout<<"nLeave Deduction : "
<<leaveDeduction;
cout<<"nNet Salary : "
<<netSalary;
cout<<"n ";
}
return 0;
}
Input
Enter Number of Employees : 2
Employee 1 Details
Enter Employee ID : 101
Enter Employee Name : Arun
Enter Attendance Days : 28
Enter Per Day Salary : 1000
Enter Overtime Hours : 5
Employee 2 Details
Enter Employee ID : 102
Enter Employee Name : Rahul
Enter Attendance Days : 24
Enter Per Day Salary : 1200
Enter Overtime Hours : 3
16.
Output
Company Name :AVI Technologies Pvt. Ltd.
========== PAYROLL REPORT ==========
Employee ID : 101
Employee Name : Arun
Basic Salary : 28000
Overtime Pay : 1000
Bonus : 2800
Leave Deduction : 200
Net Salary : 31600
Employee ID : 102
Employee Name : Rahul
Basic Salary : 28800
Overtime Pay : 600
Bonus : 2880
Leave Deduction : 600
Net Salary : 31680
12. Conclusion
Thus, an Employee Attendance and Salary Calculator was successfully implemented using data types,
operators, control structures, arrays, functions, reference variables, inline functions, scope resolution
operator, and ENUM data type in C++.
13. Viva/Oral Questions
What is a data type?
What is an array?
What is a function?
What is an inline function?
What is a reference variable?
What is ENUM?
What is the purpose of the scope resolution operator?
Difference between local and global variables.
What are control structures?
Why are functions used in programming?
17.
Text Books:
1. ObjectOriented Programming with C++, E. Balagurusamy, McGraw Hill Education, 8th Edition,
2023.
2. Mastering C++, K. R. Venugopal and Rajkumar Buyya, McGraw Hill Education, 2nd Edition,
2017.
3. Programming with C++, D. Ravichandran, McGraw Hill Education, 3rd Edition, 2018.
Reference Books:
1. Programming Principles and Practice Using C++, Pearson Education, 3rd Edition, 2024.
2. The C++ Programming Language, Bjarne Stroustrup, Addison-Wesley Professional, 4th Edition,
2013.
3. C++ Primer, Stanley B. Lippman, Josée Lajoie, and Barbara E. Moo, Pearson Education, 5th
Edition, 2012.
4. Object-Oriented Programming in C++, Robert Lafore, SAMS Publishing, 4th Edition, 2002.
Prepared By, Approved By,
Mr.A.S.Dalvi Dr. M. A. Jawale
Subject In-charge HOD-IT