[go: up one dir, main page]

0% found this document useful (0 votes)
28 views5 pages

C

The document defines an employee management system with functions to add, view, and generate payroll reports for employees. It includes structures to store employee data and functions to manage a database of employees.

Uploaded by

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

C

The document defines an employee management system with functions to add, view, and generate payroll reports for employees. It includes structures to store employee data and functions to manage a database of employees.

Uploaded by

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

#include <iostream>

#include <string>

struct Employee {
int id;
std::string name;
std::string jobTitle;
double salary;
};

const int MAX_EMPLOYEES = 100;


Employee employees[MAX_EMPLOYEES];
int numEmployees = 0;

void addNewEmployee() {
if (numEmployees >= MAX_EMPLOYEES) {
std::cout << "Maximum number of employees reached." << std::endl;
return;
}

Employee newEmployee;
std::cout << "Enter employee ID: ";
std::cin >> newEmployee.id;
std::cin.ignore();

std::cout << "Enter employee name: ";


std::getline(std::cin, newEmployee.name);

std::cout << "Enter employee job title: ";


std::getline(std::cin, newEmployee.jobTitle);
std::cout << "Enter employee salary: ";
std::cin >> newEmployee.salary;

employees[numEmployees] = newEmployee;
numEmployees++;

std::cout << "Employee added successfully." << std::endl;


}

void showAllEmployees() {
if (numEmployees == 0) {
std::cout << "No employees found." << std::endl;
return;
}

std::cout << "Employee List:" << std::endl;


for (int i = 0; i < numEmployees; i++) {
std::cout << "ID: " << employees[i].id << std::endl;
std::cout << "Name: " << employees[i].name << std::endl;
std::cout << "Job Title: " << employees[i].jobTitle << std::endl;
std::cout << "Salary: " << employees[i].salary << std::endl;
std::cout << std::endl;
}
}

double calculatePayroll() {
double totalPayroll = 0.0;
for (int i = 0; i < numEmployees; i++) {
totalPayroll += employees[i].salary;
}
return totalPayroll;
}

void generatePayslip() {
int employeeId;
std::cout << "Enter employee ID: ";
std::cin >> employeeId;

bool found = false;


for (int i = 0; i < numEmployees; i++) {
if (employees[i].id == employeeId) {
std::cout << "Name: " << employees[i].name << std::endl;
std::cout << "Job Title: " << employees[i].jobTitle << std::endl;
std::cout << "Gross Salary: " << employees[i].salary << std::endl;
std::cout << "Net Pay: " << employees[i].salary * 0.8 << std::endl;
found = true;
break;
}
}

if (!found) {
std::cout << "Employee not found." << std::endl;
}
}

void generatePayrollReport() {
if (numEmployees == 0) {
std::cout << "No employees found." << std::endl;
return;
}

double totalPayroll = calculatePayroll();

std::cout << "Payroll Report:" << std::endl;


std::cout << "Total Payroll Expenses: " << totalPayroll << std::endl;
std::cout << "Number of Employees: " << numEmployees << std::endl;
}

int main() {
int choice;

do {
std::cout << "Employee Management System" << std::endl;
std::cout << "1. Add New Employee" << std::endl;
std::cout << "2. Show All Employees" << std::endl;
std::cout << "3. Calculate Payroll" << std::endl;
std::cout << "4. Generate Payslip" << std::endl;
std::cout << "5. Generate Payroll Report" << std::endl;
std::cout << "6. Exit" << std::endl;
std::cout << "Enter your choice: ";
std::cin >> choice;

switch (choice) {
case 1:
addNewEmployee();
break;
case 2:
showAllEmployees();
break;
case 3:
std::cout << "Total Payroll Expenses: " << calculatePayroll() << std::endl;
break;
case 4:
generatePayslip();
break;
case 5:
generatePayrollReport();
break;
case 6:
std::cout << "Exiting..." << std::endl;
break;
default:
std::cout << "Invalid choice. Please try again." << std::endl;
break;
}

std::cout << std::endl;


} while (choice != 6);

return 0;
}

You might also like