Created
May 13, 2022 04:05
-
-
Save 0x61nas/343737bd28b9ed75a835c1651f8e984f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Employee mangemant using c++ | |
#include <iostream> | |
using namespace std; | |
struct Employee | |
{ | |
string name; | |
int age; | |
int salary; | |
char gender; | |
}; | |
void printMenu() { | |
cout << "Enter Your choice." << endl; | |
cout << "=======================" << endl; | |
cout << "1) Add a new employee" << endl; | |
cout << "2) print all employees" << endl; | |
cout << "3) Delete by age." << endl; | |
cout << "4) Update salary by name." << endl; | |
cout << "5) Exit" << endl; | |
} | |
void printEmployeeInfo(Employee emp) { | |
cout << "Name: " << emp.name << endl; | |
cout << "Age: " << emp.age << endl; | |
cout << "Salary: " << emp.salary << endl; | |
cout << "Gender: " << emp.gender << endl; | |
} | |
void resetEmp(Employee &emp) | |
{ | |
emp.name = "NULL"; | |
emp.age = 0; | |
emp.salary = 0; | |
emp.gender = 'M'; | |
} | |
int main() | |
{ | |
cout << "empolyee mangement system." << endl; | |
cout << "===========================" << endl; | |
int counter; | |
cout << "Enter number of employees:"; | |
// counter = number of employes | |
cin >> counter; | |
Employee empolyees[counter]; | |
bool exit = false; | |
while (!exit) { | |
printMenu(); | |
int choice; | |
cin >> choice; | |
switch (choice) { | |
case 1: | |
for (int i = 0; i < counter; i++) { | |
cout << "Enter employee name: "; | |
cin >> empolyees[i].name; | |
cout << "Enter employee age: "; | |
cin >> empolyees[i].age; | |
cout << "Enter employee salary:"; | |
cin >> empolyees[i].salary; | |
cout << "Enter employee gender: "; | |
cin >> empolyees[i].gender; | |
cout << "======================" << endl; | |
} | |
break; | |
case 2: | |
for (int i = 0; i < counter; i++) { | |
cout << "Employee [" << i + 1 << "]" << endl; | |
printEmployeeInfo(empolyees[i]); | |
cout << "======================" << endl; | |
} | |
break; | |
case 3: | |
int age; | |
cout << "Enter age to delete: "; | |
cin >> age; | |
for (int i = 0; i < counter; i++) { | |
if (empolyees[i].age == age) { | |
resetEmp(empolyees[i]); | |
} | |
} | |
break; | |
case 4: { | |
string name = ""; | |
cout << "Enter name to update salary: "; | |
cin >> name; | |
for (int i = 0; i < counter; i++) { | |
if (empolyees[i].name == name) { | |
cout << "Enter new salary: "; | |
cin >> empolyees[i].salary; | |
} | |
} | |
} break; | |
case 5: | |
exit = true; | |
break; | |
default: | |
cout << "Invalid choice." << endl; | |
break; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment