[go: up one dir, main page]

0% found this document useful (0 votes)
24 views9 pages

OOP Microproject

Uploaded by

notpruthvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

OOP Microproject

Uploaded by

notpruthvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

KCE Society's College Of

Engineering and Management,


Jalgaon
DEPARTMENT OF COMPUTER ENGINNERING
ACDEMIC YEAR 2024-25
Employee Management System
Using Inheritance in C++
Presented by: Pruthviraj A. Ingale
Rutuja Kothawade
Payal Patil

Guided by: Mr Pravin Mehenge sir


Objective

1. Develop a system to manage employee records.


2. Calculate net salary based on basic salary and leaves
taken.
3. Store data for up to 5 employees in a file.
Concept of Inheritance in C++
Inheritance
1. Allows creation of new classes based on existing ones.
2. Helps in structuring and reusing code.

Example Structure
1. Base Class: Employee - holds basic details.
2. Derived Class: SalariedEmployee - calculates salary deductions.

Required Inputs
User Inputs
Employee ID
Employee Name
Basic Salary
Leaves Taken in Month
Code Snippet - Class Definition (Employee)
class Employee {
protected:
int employeeID;
string employeeName;
float basicSalary;
int leaveTaken;
public:
Employee(int id, const string& name, float salary, int leave)
: employeeID(id), employeeName(name), basicSalary(salary), leaveTaken(leave) {}
virtual float calculateNetSalary() const = 0; // Pure virtual function
virtual void display() const {
cout << "Employee ID: " << employeeID << "\n"
<< "Employee Name: " << employeeName << "\n"
<< "Basic Salary: " << basicSalary << "\n"
<< "Leaves Taken: " << leaveTaken << endl;
}
virtual ~Employee() {} // Virtual destructor
};
Code Snippet - Class Definition (Salaried Employee)

class SalariedEmployee : public Employee {


private:
float leaveDeduction;
public:
SalariedEmployee(int id, const string& name, float salary, int leave, float
leaveDed)
: Employee(id, name, salary, leave), leaveDeduction(leaveDed) {}
float calculateNetSalary() const override {
return basicSalary - (leaveDeduction * leaveTaken);
}
void display() const override {
Employee::display();
cout << "Net Salary: " << calculateNetSalary() << endl;
}
};
Direct Input and Display of Employee Details
int main() {
int numEmployees;
cout << "Enter the number of employees: ";
cin >> numEmployees;
for (int i = 0; i < numEmployees; ++i) {
int id, leaveTaken;
string name;
float basicSalary, leaveDeduction;
cout << "\nEnter details for Employee " << i + 1 << ":\n";
cout << "ID: "; cin >> id;
cout << "Name: "; cin >> ws; getline(cin, name);
cout << "Basic Salary: "; cin >> basicSalary;
cout << "Leaves Taken: "; cin >> leaveTaken;
cout << "Leave Deduction per Day: "; cin >> leaveDeduction;
// Create a SalariedEmployee object
SalariedEmployee emp(id, name, basicSalary, leaveTaken, leaveDeduction);
// Display the employee details
cout << "\nEmployee Details:\n";
emp.display();
cout << "-------------------\n";
}

return 0;
}
Conclusion

Demonstrated inheritance through Employee and SalariedEmployee classes.


Calculated and displayed net salary with deductions.
Stored employee data in a file for up to 5 records.

Benefits
Clear structure and reusability with inheritance.
Easy to extend and manage employee information.
Thank You !

You might also like