0% found this document useful (0 votes)
25 views

Emp String String String String: Using Namespace Struct

The document defines an employee struct with fields for ID, name, age, address, role, and salary. It then declares an array of employee structs and implements a menu-driven program to allow the user to insert, search, edit, delete employees or search employees by salary. The program uses a do-while loop to repeatedly display the menu until the user chooses to exit.

Uploaded by

Muhammad Qasim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Emp String String String String: Using Namespace Struct

The document defines an employee struct with fields for ID, name, age, address, role, and salary. It then declares an array of employee structs and implements a menu-driven program to allow the user to insert, search, edit, delete employees or search employees by salary. The program uses a do-while loop to repeatedly display the menu until the user chooses to exit.

Uploaded by

Muhammad Qasim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<iostream>

#include<string>
using namespace std;
struct emp
{
string id;
string name;
int age;
string address;
string role;
float salary;

};
int main()
{
emp arr[1000];
int a, b; string x;
char c;
do
{
cout << "1.Insert an employee into the system.\n";
cout << "2.Search for an employee via their id number.\n";
cout << "3.Edit employee deatails via their id number.\n";
cout << "4.Delete an employee.\n";
cout << "5.Search for all employee with a wage higher than 15000\n";
cout << "Enter the option:";
cin >> a;

if (a == 1)
{

cout << "\nEnter the number of an employee into the system. :";
cin >> b;

for (int i = 0; i < b; i++)


{
cout << "\nEnter the ID of Employee:\t";
cin >> arr[i].id;

cout << "Enter the name of Employee:\t";


cin >> arr[i].name;

cout << "Enter the Age of Employee:\t";


cin >> arr[i].age;

cout << "Enter the Address of Employee:\t";


cin >> arr[i].address;

cout << "Enter the Role of Employee:\t";


cin >> arr[i].role;
cout << "Enter the Salary of Employee:\t";
cin >> arr[i].salary;

else if (a == 2)
{
//cout << "2.Search for an employee via their id number.\n";
cout << "\nEnter the ID of Employee: ";
cin >> x;
for (int k = 0; k < b; k++)
{
if (x == arr[k].id)
{
for (int i = 0; i < b; i++)
{
cout << "\nThe name of Employee:\t\t";
cout << arr[i].name;

cout << "\nThe Age of Employee:\t\t";


cout << arr[i].age;

cout << "\nThe Address of Employee:\t";


cout << arr[i].address;
;
cout << "\nThe Role of Employee:\t\t";
cout << arr[i].role;

cout << "\nThe Salary of Employee:\t\t";


cout << arr[i].salary;

}
}
else
{
cout << "\nThis ID does not exit in System:" <<
endl;
}
}
}
else if (a == 3)
{
string J;
//cout << "3.Edit employee deatails via their id number.

for (int k = 0; k < b; k++)


{
cout << "\nEnter the ID Number to Edit employee
detail:\t";
cin >> J;
if (J == arr[k].id)
{
cout << "\nEnter the new ID of Employee:\t\t";
cin >> arr[k].id;
cout << "Enter the new name of Employee:\t\t";
cin >> arr[k].name;
cout << "Enter the new Age of Employee:\t\t";
cin >> arr[k].age;
cout << "Enter the new Address of Employee:\t\t";
cin >> arr[k].address;
cout << "Enter the new Role of Employee:\t\t";
cin >> arr[k].role;
cout << "Enter the new Salary of Employee:\t\t";
cin >> arr[k].salary;
}

}
else if (a == 4)
{
string y;
//cout << "4.Delete an employee.\n"
cout << "\nEnter the Employee ID which you want to delete:\t";
cin >> y;
cout << endl;
for (int i = 0; i < b; i++)
{
if (y == arr[i].id)
{

arr[i].id = "0";

arr[i].name = "0";

arr[i].age = 0;

arr[i].address = "0";

arr[i].role = "0";
arr[i].salary = 0;
}
else
{
cout << "Invalid ID" << endl;
}

}
else if (a == 5)
{
//5.Search for all employee with a wage higher than 15000
cout << "\nAll employee with a wage higher than 15000:" << endl;
for (int i = 0; i < b; i++)
{
if (arr[i].salary > 15000)
{
cout << "\nEnter the ID of Employee:\t";
cout << arr[i].id << endl;

cout << "Enter the name of Employee:\t";


cout << arr[i].name << endl;

cout << "Enter the Age of Employee:\t";


cout << arr[i].age << endl;

cout << "Enter the Address of Employee:\t";


cout << arr[i].address << endl;

cout << "Enter the Role of Employee:\t";


cout << arr[i].role << endl;
cout << "Enter the Salary of Employee:\t";
cout << arr[i].salary << endl;
}
}

}
else
{
cout << "\nInvalid Input";
}

cout << "\nDo you want to go back to main menu (Y/N):";


cin >> c;
} while (c == 'y' || c == 'Y');

cout << "\n\t\t\t\t&&&&&&&&&&&&&&& Thank YOU &&&&&&&&&&&&&&&\n";


}

You might also like