Untitled
unknown
plain_text
3 years ago
12 kB
13
Indexable
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct employee
{
int id;
int age, experience;
string name, nic;
};
employee emp[10];
int index = -1;
void enter();
void view();
void displayshortlisted();
void search();
void update();
void del();
bool full();
bool empty();
bool full()
{
if (index == 9)
{
return true;
}
else
{
return false;
}
}
bool empty()
{
if (index == -1)
{
return true;
}
else
{
return false;
}
}
int main()
{
fstream getindex;
getindex.open("ind.txt", ios::in);
getindex >> index;
getindex.close();
fstream getdata;
getdata.open("ee.txt", ios::in);
for (int i = 0; i <= index; i++)
{
getdata >> emp[i].id >> emp[i].name >> emp[i].age >> emp[i].nic >> emp[i].experience;
}
getdata.close();
/* fstream getdata2;
getdata2.open("ff.text", ios::in);
for (int i = 0; i <= index; i++)
{
getdata2 >> emp[i].id >> emp[i].name >> emp[i].age >> emp[i].nic >> emp[i].experience;
}
getdata2.close(); */
cout << "*******WELCOME TO EMPLOYEE RECOMMENDATION SYSTEM*********" << endl;
int choice;
char cont;
cout << "Press f or F to enter the program." << endl;
cin >> cont;
while (cont == 'f' || cont == 'F')
{
cout << "Press 1 for entering data of employee. " << endl;
cout << "Press 2 to view the data of all the employees entered. " << endl;
cout << "Press 3 to search data on any employee. " << endl;
cout << "Press 4 to update data of any employee. " << endl;
cout << "Press 5 to view shortlisted employees. " << endl;
cout << "Press 6 to delete record of any employee. " << endl;
cout << "Give your choice below." << endl;
cin >> choice;
if (choice == 1)
{
enter();
}
else if (choice == 2)
{
view();
}
else if (choice == 3)
{
search();
}
else if (choice == 4)
{
update();
}
else if (choice == 5)
{
displayshortlisted();
}
else if (choice == 6)
{
del();
}
else
{
cout << "Invalid input!" << endl;
}
cout << "\nIf you want to continue with the program press 'f' or 'F'. Else press any other key to exit the program." << endl;
cin >> cont;
}
return 0;
}
void enter()
{
if (index == 9)
{
cout << "Array is already full." << endl;
}
else
{
index++;
emp[index].id = index;
cout << "ID :" << emp[index].id << endl;
cout << "Enter employee name : ";
getline(cin>>ws, emp[index].name);
cout << "Enter age of employee : ";
cin >> emp[index].age;
/* cout << "Enter CNIC number of employee : ";
getline(cin >> ws, emp[index].nic);
for (int j = 0; j <= index; j++)
{
if (emp[index].nic == emp[j].nic)
{
cout << "CNIC should be unique of employees." << endl;
cout << "Enter a valid CNIC number : ";
getline(cin >> ws, emp[j].nic);
j = -1;
}
} */
/*cout << "Enter CNIC number of employee : ";
getline(cin >> ws, emp[index].nic);
bool is_duplicate = false;
for (int j = 0; j < index; j++)
{
if (emp[index].nic == emp[j].nic)
{
is_duplicate = true;
break;
}
}
if (is_duplicate == false)
{
cout << "CNIC should be unique of employees." << endl;
cout << "Enter a valid CNIC number : ";
getline(cin >> ws, emp[index].nic);
j = -1;
}*/
cout << "Enter CNIC number of employee : ";
getline(cin >> ws, emp[index].nic);
bool unique = true;
do {
unique = true;
for (int j = 0; j < index; j++)
{
if (emp[index].nic == emp[j].nic)
{
unique = false;
break;
}
}
if (unique == false)
{
cout << "CNIC should be unique of employees." << endl;
cout << "Enter a valid CNIC number : ";
getline(cin >> ws, emp[index].nic);
}
} while (unique == false);
cout << "Enter experience of employee in (Years) : ";
cin >> emp[index].experience;
fstream value;
value.open("ee.txt", ios::app);
value << emp[index].id << endl;
value << emp[index].name << endl;
value << emp[index].age << endl;
value << emp[index].nic << endl;
value << emp[index].experience << endl;
value.close();
fstream putindex;
putindex.open("ind.txt", ios::out);
putindex << index;
putindex.close();
}
}
void view()
{
if (index == -1)
{
cout << "No data entered to display." << endl;
}
else
{
system("cls");
for (int i = 0; i <= index; i++)
{
cout << "\nEmployee ID :" << emp[i].id;
cout << "\nEmployee name :" << emp[i].name;
cout << "\nEmployee age :" << emp[i].age;
cout << "\nEmplyee CNIC no. :" << emp[i].nic;
cout << "\nEMployee experience :" << emp[i].experience;
}
}
}
void search()
{
if (index == -1)
{
cout << "No data available to search from" << endl;
}
else
{
system("cls");
int z;
cout << "Enter ID you want to search :";
cin >> z;
bool found = false;
for (int i = 0; i <= index; i++)
{
if (emp[i].id == z)
{
found = true;
cout << "ID found!" << endl;
cout << "\nEmployee ID :" << emp[i].id;
cout << "\nEmployee name :" << emp[i].name;
cout << "\nEmployee age :" << emp[i].age;
cout << "\nEmplyee CNIC no. :" << emp[i].nic;
cout << "\nEMployee experience :" << emp[i].experience;
}
}
if (found = false)
{
cout << "ID not found." << endl;
}
}
}
void update()
{
if (index == -1)
{
cout << "No records available to update." << endl;
}
else
{
system("cls");
int k;
cout << "Enter ID of the employee whose records you want to update :";
cin >> k;
bool found = false;
for (int i = 0; i <= index; i++)
{
if (emp[i].id == k)
{
cout << "ID found." << endl;
cout << "Enter new Records.";
cout << "Employwee ID :";
cout << emp[i].id;
cout << "\nEmployee new name :";
cin >> emp[i].name;
cout << "\nEmployee new age :";
cin >> emp[i].age;
cout << "\nEmplyee new CNIC no. :";
cin >> emp[i].nic;
cout << "\nEMployee new experience :";
cin >> emp[i].experience;
}
}
remove("ee.txt");
fstream remakedata;
remakedata.open("ee.txt", ios::out);
for (int i = 0; i <= index; i++) {
remakedata << emp[i].id << endl;
remakedata << emp[i].name << endl;
remakedata << emp[i].age << endl;
remakedata << emp[i].nic << endl;
remakedata << emp[i].experience << endl;
}
remakedata.close();
}
}
void displayshortlisted()
{
if (index == -1)
{
cout << "No records to display." << endl;
}
else
{
system("cls");
for (int i = 0; i <= index; i++)
{
if (emp[i].age <= 35 && emp[i].experience >= 5)
{
cout << "********SHORT LISTED EMPLOYEES**********" << endl;
cout << "Employee ID : " << emp[i].id << endl;
cout << "Employee name : " << emp[i].name << endl;
cout << "Employee age : " << emp[i].age << endl;
cout << "Employee CNIC: " << emp[i].nic << endl;
cout << "Employee experience : " << emp[i].experience << endl;
fstream shortlisted;
shortlisted.open("ee.txt", ios::out);
shortlisted << "************SHORT LISTED EMPLOYEES*************" << endl;
shortlisted << "Employee ID : " << emp[i].id << endl;
shortlisted << "Employee name : " << emp[i].name << endl;
shortlisted << "Employee age : " << emp[i].age << endl;
shortlisted << "Employee CNIC: " << emp[i].nic << endl;
shortlisted << "Employee experience : " << emp[i].experience << endl;
shortlisted.close();
}
else {
cout << " \nThe employee " << emp[i].id << " Does not fall on the shortlisted employee criteria." << endl;
}
}
}
}
void del()
{
system("CLS");
if (index == -1)
{
cout << "No records available to delete from." << endl;
}
else
{
cout << "***************Delete record of any Employee***************" << endl;
int x;
int j = 0;
bool found = false;
cout << "Enter ID of the employee whose record you want to delete : ";
cin >> x;
for (int i = 0; i <= index; i++)
{
if (x == emp[i].id)
{
found = true;
cout << "ID FOUND!" << endl;
j = i;
cout << "Record deleted of ID no.:" << x << endl;
break;
}
}
if (found == true)
{
for (int i = j; i <= index; i++)
{
emp[j].id = emp[j + 1].id;
emp[j].name = emp[j + 1].name;
emp[j].age = emp[j + 1].age;
emp[j].nic = emp[j + 1].nic;
emp[j].experience = emp[j + 1].experience;
}
emp[index].id = NULL;
emp[index].name = " ";
emp[index].age = NULL;
emp[index].nic = " ";
emp[index].experience = NULL;
index--;
remove("ind.txt");
fstream remakeindex;
remakeindex.open("ind.txt", ios::out);
remakeindex << index;
remakeindex.close();
remove("ee.txt");
fstream remakedata;
remakedata.open("ee.txt", ios::out);
for (int i = 0; i <= index; i++)
{
remakedata << "Employee ID : " << emp[i].id << endl;
remakedata << "Employye's Name : " << emp[i].name << endl;
remakedata << "Employee's age : " << emp[i].age << endl;
remakedata << "Emplyee's CNIC no. : " << emp[i].nic << endl;
remakedata << "Emplyee's experience : " << emp[i].experience << endl;
}
remakedata.close();
}
else
{
cout << "ID NOT FOUND!" << endl;
}
}
}
Editor is loading...