🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

This is a simple employee management system that works with three employees.
#include <iostream>
#include <string>
using namespace std;
// Employee class definition
class Employee {
private:
int id;
string name;
int age;
double salary;
public:
// Constructor to initialize with default values
Employee() : id(0), name(""), age(0), salary(0.0) {}
// Function to add employee details
void addDetails(int empId) {
id = empId;
cout << "Enter name: ";
cin.ignore(); // To clear buffer
getline(cin, name);
cout << "Enter age: ";
cin >> age;
cout << "Enter salary: ";
cin >> salary;
}
// Function to display employee details
void displayDetails() {
cout << "\nEmployee ID: " << id
<< "\nName: " << name
<< "\nAge: " << age
<< "\nSalary: $" << salary << endl;
}
// Function to edit employee details
void editDetails() {
cout << "Editing details for Employee ID: " << id << endl;
cout << "Enter new name: ";
cin.ignore();
getline(cin, name);
cout << "Enter new age: ";
cin >> age;
cout << "Enter new salary: ";
cin >> salary;
}
};
// Main function
int main() {
const int numEmployees = 3; // Managing 3 employees
Employee employees[numEmployees];
int choice, empId;
while (true) {
// Menu
cout << "\n----- Employee Management System -----";
cout << "\n1. Add employee details";
cout << "\n2. Display all employees";
cout << "\n3. Edit employee details";
cout << "\n4. Exit";
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice) {
case 1:
// Add details for all employees
for (int i = 0; i < numEmployees; ++i) {
cout << "\nAdding details for Employee " << (i + 1) << endl;
employees[i].addDetails(i + 1);
}
break;
case 2:
// Display details for all employees
cout << "\n----- Employee Details -----";
for (int i = 0; i < numEmployees; ++i) {
employees[i].displayDetails();
}
break;
case 3:
// Edit employee details
cout << "Enter Employee ID to edit: ";
cin >> empId;
if (empId > 0 && empId <= numEmployees) {
employees[empId - 1].editDetails();
} else {
cout << "Invalid Employee ID." << endl;
}
break;
case 4:
cout << "Exiting Employee Management System. Bye!" << endl;
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
}
}
return 0;
}
Employee
encapsulates the details and actions of employees.addDetails()
: Takes input to set employee data.displayDetails()
: Prints employee details to the console.editDetails()
: Allows editing employee data.employees[numEmployees]
stores multiple employees.----- Employee Management System -----
1. Add employee details
2. Display all employees
3. Edit employee details
4. Exit
Enter your choice: 1
Adding details for Employee 1
Enter name: Susan
Enter age: 30
Enter salary: 50000
Adding details for Employee 2
Enter name: Rob
Enter age: 26
Enter salary: 45000
Adding details for Employee 3
Enter name: Andrew
Enter age: 28
Enter salary: 47000
Large companies use employee management systems to track work schedules, employee details, benefits, and payroll. A basic C++ implementation can be extended to include:
Hospitals use employee management systems to maintain details of administrative staff, nurses, and doctors. Features such as leave tracking, shift scheduling, and performance evaluation can be implemented in C++ and integrated with hospital management software.
Retail companies use employee management systems to handle attendance, salaries, and work shifts. Additional features may include:
This is a great beginner-friendly project to learn C++ object-oriented programming. It can be extended to include advanced features such as:
Start with this project and enhance it step by step for real-world applications!
Comments
Post a Comment