// GROUP 8 ASSINGMENT
//----- EMPLOYEE --------
// MEMBERS NAME ID
/* DESALEGN YETWALE TEGEGNE 1505752
ZELALEM GETAHUN SIMEGN 1508462
LIDIA ENDALAMAW BALEW 1506829
HABTAMU SEMAGN BIRHAN 1506334
BIRUH TESFA ANDUALEM 1505503
*/
#include <iostream>
using namespace std;
struct employee{
char firstName[25];
char lastName[25];
char empID[10];
int age;
int yearsOfServies;
float salary;
employee* next;
employee* previous;
};
employee* start=NULL;
employee* tail =NULL;
void insertAtEnd(){ // INSERTING AT END
employee* node = new employee;
cout<<"____________________________"<<endl;
cout<<"Inserting at the END"<<endl;
cout<<"____________________________"<<endl;
cout<<"Enter first name: ";
cin>>node->firstName;
cout<<"Enter last name: ";
cin>>node->lastName;
cout<<"Enter employee ID: ";
cin>>node->empID;
cout<<"Enter age: ";
cin>>node->age;
cout<<"Enter years of servies: ";
cin>>node->yearsOfServies;
cout<<"Enter salary: ";
cin>>node->salary;
node->next=NULL;
node->previous=NULL;
if(start == NULL){
start=node;
tail=node;
}else{
tail->next=node;
node->previous=tail;
tail=node;
void insertAtBiginning(){ // INSERTING AT THE BIGINNING
employee* node = new employee;
cout<<"____________________________"<<endl;
cout<<"Inserting at the BIGINNING"<<endl;
cout<<"____________________________"<<endl;
cout<<"Enter first name: ";
cin>>node->firstName;
cout<<"Enter last name: ";
cin>>node->lastName;
cout<<"Enter employee ID: ";
cin>>node->empID;
cout<<"Enter age: ";
cin>>node->age;
cout<<"Enter years of servies: ";
cin>>node->yearsOfServies;
cout<<"Enter salary: ";
cin>>node->salary;
node->next=NULL;
node->previous=NULL;
if(start==NULL || tail==NULL){
start=node;
tail=node;
}else{
node->next=start;
start->previous=node;
start=node;
}
void insertAtMiddle(){ // INSERTING AT THE MIDDLE OF THE LIST
employee* n = new employee;
cout<<"____________________________"<<endl;
cout<<"Inserting at the Middle"<<endl;
cout<<"____________________________"<<endl;
cout<<"Enter first name: ";
cin>>n->firstName;
cout<<"Enter last name: ";
cin>>n->lastName;
cout<<"Enter employee ID: ";
cin>>n->empID;
cout<<"Enter age: ";
cin>>n->age;
cout<<"Enter years of servies: ";
cin>>n->yearsOfServies;
cout<<"Enter salary: ";
cin>>n->salary;
n->next=NULL;
n->previous=NULL;
if(start==NULL || tail==NULL){
start=n;
tail=n;
}else if(start->next==NULL || tail->previous==NULL){
tail->next=n;
n->previous=tail;
tail=n;
}else{
employee* s1=start;
employee* t1=tail;
while(s1!=t1){
if(t1->previous==s1){
break;
s1=s1->next;
t1=t1->previous;
s1->next=n;
n->previous=s1;
n->next=t1;
t1->previous=n;
void deleteAtEnd(){ // DELETE AT END
employee* temp;
if(tail==NULL){
cout<<"Empty list"<<endl;
}else if(tail->previous==NULL){
tail=NULL;
start=NULL;
delete tail;
delete start;
}else{
temp=tail->previous;
tail->previous=NULL;
temp->next=NULL;
delete tail;
tail=temp;
void deleteAtBiginning(){ // DELETE AT THE BIGINNING
employee* temp;
if(start==NULL){
cout<<"Empty list"<<endl;
}else if(start->next==NULL){
tail=NULL;
start=NULL;
delete tail;
delete start;
}else{
temp=start->next;
start->next=NULL;
temp->previous=NULL;
delete start;
start=temp;
void deleteByName(){ // delete from list by first name
char name[25];
cout<<"Enter Employee's first name to DELETE: "<<endl;
cin>>name;
if(start==NULL){
cout<<"The list is empty!!"<<endl;
} else if(start->next==NULL){
if(strcmp(start->firstName,name)==0){
start=NULL;
delete start;
}else{
cout<<endl<<"First name NOT FOUND in list!!"<<endl;
}else{
employee* temp =start;
int result=0; // to check if found or not. 1 if found and 0 if it is not found.
while(temp!=NULL){
if(strcmp(temp->firstName,name)==0){
temp->previous->next=temp->next;
temp->next->previous=temp->previous;
temp->next=NULL;
temp->previous=NULL;
delete temp;
result=1;
temp=temp->next;
if(result==0){
cout<<endl<<"First name not found in list"<<endl;
void deleteByID(){ // delete from list by employee ID
char ID[10];
cout<<"Enter Employee's ID to DELETE: "<<endl;
cin>>ID;
if(start==NULL){
cout<<"The list is empty!!"<<endl;
} else if(start->next==NULL){
if(strcmp(start->empID,ID)==0){
start=NULL;
delete start;
}else{
cout<<endl<<"Employee ID NOT FOUND in list!!"<<endl;
}else{
employee* temp =start;
int result=0; // to check if found or not. 1 if found and 0 if it is not found.
while(temp!=NULL){
if(strcmp(temp->empID,ID)==0){
temp->previous->next=temp->next;
temp->next->previous=temp->previous;
temp->next=NULL;
temp->previous=NULL;
delete temp;
result=1;
temp=temp->next;
if(result==0){
cout<<endl<<"Employee ID not found in list!"<<endl;
}
void deleteNthNode(){ // DELETE THE NTH NODE
int n,counter=1,size=0;
cout<<endl<<"**************************************************"<<endl;
cout<<"Enter the nth node to be deleted from lists: "<<endl;
cin>>n;
while(n<=0) // VALIDATING N
cout << "Invalid input! Please enter a positive integer." << endl;
cout<<"Enter the nth node to be deleted from lists: "<<endl;
cin>>n;
if(start==NULL){
cout<<"The list is empty!!"<<endl;
} else if(start->next==NULL){
if(n==1){
start=NULL;
delete start;
cout<<endl<<"Succesfully deleted!!!"<<endl;
}else{
cout<<endl<<"There is only 1 node in the list!!"<<endl;
}else{
employee* temp=start;
while(temp!=NULL){
if(counter==n){
if(n==1){//because the 1st node is selected its previous should be null.
start=temp->next;
start->previous=NULL;
delete temp;
cout<<endl<<"Succesfully deleted!!!"<<endl;
}else if(temp->next==NULL){// now the last node is selected so the tails
next should be null after deletion
tail=temp->previous;
tail->next=NULL;
delete temp;
cout<<endl<<"Succesfully deleted!!!"<<endl;
}else{
temp->previous->next=temp->next;
temp->next->previous=temp->previous;
delete temp;
cout<<endl<<"Succesfully deleted!!!"<<endl;
counter++;
size++;
temp=temp->next;
if(n>size){
cout<<endl<<"The list size is only "<<size<<" node long"<<endl;
}
}
void updateFNameById(){ // UPDATE NAME
char ID[10];
employee* result=NULL;
employee* temp =start;
cout<<endl<<"Enter Employee ID to UPDATE the first name: "<<endl;
cin>>ID;
while(temp!=NULL){
if(strcmp(temp->empID,ID)==0){
result=temp;
temp=temp->next;
if(start==NULL){
cout<<"The list is empty!!"<<endl;
}else if(result==NULL){
cout<<"Not Found in the list"<<endl;
}else{
cout<<endl<<"************************************"<<endl;
cout<<"Now enter new Updated first NAME!"<<endl;
cin>>result->firstName;
cout<<"-------------Name UPDATED------------"<<endl;
void displayAverageAge(){ // DISPLAY THE AVERAGE AGE OF Employees from list.
int average;
int sum=0;
int size=0;
for(employee* i=start;i!=NULL;i=i->next){
sum+=i->age;
size++;
if(size!=0){
average=sum/size;
cout<<endl<<"*****************************************"<<endl;
cout<<"The Average Age of employees is: "<<average<<endl;
}else{
cout<<endl<<"The LIST is EMPTY!"<<endl;
void displayAverageSalary(){ // DISPLAY THE AVERAGE SALARY OF Employees from list.
float average;
float sum=0;
int size=0;
for(employee* i=start;i!=NULL;i=i->next){
sum+=i->salary;
size++;
if(size!=0){
average=sum/size;
cout<<endl<<"*****************************************"<<endl;
cout<<"The Average SALARY of employees is: "<<average<<endl;
}else{
cout<<endl<<"The LIST is EMPTY!"<<endl;
void displayNumberOfEmployees(){ // DISPLAY THE NUMBER OF EMPLOYEES
int size=0;
for(employee* i=start;i!=NULL;i=i->next){
size++;
if(size!=0){
cout<<endl<<"*****************************************"<<endl;
cout<<endl<<"The list has "<<size<<" employees"<<endl;
}else{
cout<<endl<<"No employee in the list."<<endl;
void numberOfOccuranceOfServiceYear(){ // COUNT THE NUMBER OF THE OCCURANCE OF THE
YEARS OF SERVICE INPUTED
int count=0;
int n;
cout<<endl<<"*****************************************"<<endl;
cout<<"The number of years of service you want the count: ";
cin>>n;
while(n<=0) // VALIDATING N
cout << "Invalid input! Please enter a positive integer." << endl;
cout<<"Enter the nth node to be deleted from lists: "<<endl;
cin>>n;
for(employee* i=start;i!=NULL;i=i->next){
if(i->yearsOfServies==n){
count++;
if(start==NULL){
cout<<endl<<"The list is empty!!"<<endl;
}else if(count==0){
cout<<endl<<"There is no employee with "<<n<<" years of service"<<endl;
}else{
cout<<endl<<"There are "<<count<<" employee's with "<<n<<" years of
service!!"<<endl;
void displayByID(){ // DISPLAY EMPLOYEEE BY ID
char ID[10];
employee* result=NULL;
employee* temp =start;
cout<<"Enter Employee ID to display: "<<endl;
cin>>ID;
while(temp!=NULL){
if(strcmp(temp->empID,ID)==0){
result=temp;
}
temp=temp->next;
if(start==NULL){
cout<<"The list is empty!!"<<endl;
}else if(result==NULL){
cout<<"Not Found in the list"<<endl;
}else{
cout<<endl<<"************************************"<<endl;
cout<<"Employee Full Name: "<<result->firstName<<" "<<result->lastName<<endl;
cout<<"Employee ID: "<<result->empID<<endl;
cout<<"Employee Age: "<<result->age<<endl;
cout<<"Employee years of servies: "<<result->yearsOfServies<<endl;
cout<<"Employee salary: "<<result->salary<<endl;
void displayByName(){ // DISPLAY AN EMPLOYEE BY NAME
char name[25];
employee* result=NULL;
employee* temp =start;
cout<<endl<<"************************************"<<endl;
cout<<"Enter Employee's first name to display: "<<endl;
cin>>name;
while(temp!=NULL){
if(strcmp(temp->firstName,name)==0){
result=temp;
cout<<endl<<"************************************"<<endl;
cout<<"Employee Full Name: "<<result->firstName<<" "<<result-
>lastName<<endl;
cout<<"Employee ID: "<<result->empID<<endl;
cout<<"Employee Age: "<<result->age<<endl;
cout<<"Employee years of servies: "<<result->yearsOfServies<<endl;
cout<<"Employee salary: "<<result->salary<<endl;
temp=temp->next;
if(start==NULL){
cout<<"The list is empty!!"<<endl;
}else if(result==NULL){
cout<<"Name Not Found in the list"<<endl;
void displayMaxAge(){ // DISPLAY THE EMPLOYEE WITH MAXIMUM AGE
employee* max=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->age>max->age){
max=i;
if(start=NULL){
cout<<"The list is empty!!"<<endl;
}else{
cout<<endl<<"**************************************"<<endl;
cout<<" Displaying The Oldest Employee"<<endl;
cout<<"**************************************"<<endl<<endl;
cout<<"Employee Full Name: "<<max->firstName<<" "<<max->lastName<<endl;
cout<<"Employee ID: "<<max->empID<<endl;
cout<<"Employee Age: "<<max->age<<endl;
cout<<"Employee years of servies: "<<max->yearsOfServies<<endl;
cout<<"Employee salary: "<<max->salary<<endl;
void displayLongestServingEmployee(){ // LONGEST SERVING EMPLOYEE
employee* max=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->yearsOfServies>max->yearsOfServies){
max=i;
if(start=NULL){
cout<<"The list is empty!!"<<endl;
}else{
cout<<endl<<"******************************************"<<endl;
cout<<" Displaying The Longest Serving Employee"<<endl;
cout<<"*****************************************"<<endl<<endl;
cout<<"Employee Full Name: "<<max->firstName<<" "<<max->lastName<<endl;
cout<<"Employee ID: "<<max->empID<<endl;
cout<<"Employee Age: "<<max->age<<endl;
cout<<"Employee years of servies: "<<max->yearsOfServies<<endl;
cout<<"Employee salary: "<<max->salary<<endl;
}
void displayMinAge(){ // DISPLAY THE EMPLOYEE WITH MINIMUM SALARY
employee* min=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->age<min->age){
min=i;
if(start=NULL){
cout<<"The list is empty!!"<<endl;
}else{
cout<<endl<<"**************************************"<<endl;
cout<<" Displaying The Youngest Employee"<<endl;
cout<<"**************************************"<<endl<<endl;
cout<<"Employee Full Name: "<<min->firstName<<" "<<min->lastName<<endl;
cout<<"Employee ID: "<<min->empID<<endl;
cout<<"Employee Age: "<<min->age<<endl;
cout<<"Employee years of servies: "<<min->yearsOfServies<<endl;
cout<<"Employee salary: "<<min->salary<<endl;
void displayMaxSalary(){ // DISPLAY THE EMPLOYEE WITH MAXIMUM SALARY
employee* max=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->salary>max->salary){
max=i;
}
}
if(start=NULL){
cout<<"The list is empty!!"<<endl;
} else{
cout<<endl<<"**************************************"<<endl;
cout<<" displaying Employee with maximum SALARY"<<endl;
cout<<"**************************************"<<endl<<endl;
cout<<"Employee Full Name: "<<max->firstName<<" "<<max->lastName<<endl;
cout<<"Employee ID: "<<max->empID<<endl;
cout<<"Employee Age: "<<max->age<<endl;
cout<<"Employee years of servies: "<<max->yearsOfServies<<endl;
cout<<"Employee salary: "<<max->salary<<endl;
void SelectionSortListByName() { // SORT LIST BY NAME
if (start == NULL) return;
for (employee* i = start; i != NULL; i = i->next) {
employee* min = i;
for (employee* j = i->next; j != NULL; j = j->next) {
if (strcmp(j->firstName, min->firstName) < 0) {
min = j;
if (min != i) {
// Swap the data of i and min nodes
char tempID[10], tempName[25], tempLName[25];
float tempSalary;
int tempAge, tempYears;
// Swap empID
strcpy(tempID, i->empID);
strcpy(i->empID, min->empID);
strcpy(min->empID, tempID);
// Swap firstName
strcpy(tempName, i->firstName);
strcpy(i->firstName, min->firstName);
strcpy(min->firstName, tempName);
// Swap salary
tempSalary = i->salary;
i->salary = min->salary;
min->salary = tempSalary;
// Swap last name
strcpy(tempLName, i->lastName);
strcpy(i->lastName, min->lastName);
strcpy(min->lastName, tempLName);
// Swap age
tempAge = i->age;
i->age = min->age;
min->age = tempAge;
// Swap yearsOfServies
tempYears = i->yearsOfServies;
i->yearsOfServies = min->yearsOfServies;
min->yearsOfServies = tempYears;
cout<<endl<<"List Sorted successfully by NAME!"<<endl;
void BubbleSortListByName() {
if (start == NULL){
cout<<endl<<"The list is empty!!"<<endl;
return;
}else if(start->next==NULL) {
return;
}else {
employee* current;
employee* last = NULL;
for (employee* i=start;i!=NULL;i=i->next) {
for (current = start; current->next != NULL; current = current->next) {
if (strcmp(current->firstName, current->next->firstName) > 0) {
// Swap the data of current and next nodes
char tempID[10], tempName[25], tempLName[25];
float tempSalary;
int tempAge, tempYears;
// Swap empID
strcpy(tempID, current->empID);
strcpy(current->empID, current->next->empID);
strcpy(current->next->empID, tempID);
// Swap firstName
strcpy(tempName, current->firstName);
strcpy(current->firstName, current->next->firstName);
strcpy(current->next->firstName, tempName);
// Swap salary
tempSalary = current->salary;
current->salary = current->next->salary;
current->next->salary = tempSalary;
// Swap lastName
strcpy(tempLName, current->lastName);
strcpy(current->lastName, current->next->lastName);
strcpy(current->next->lastName, tempLName);
// Swap age
tempAge = current->age;
current->age = current->next->age;
current->next->age = tempAge;
// Swap yearsOfService
tempYears = current->yearsOfServies;
current->yearsOfServies = current->next->yearsOfServies;
current->next->yearsOfServies = tempYears;
}
}
cout<<endl<<"List Sorted successfully by NAME!"<<endl;
void SelectionSortListByAge() {
if (start == NULL){
cout<<endl<<"The list is empty!!"<<endl;
return;
}else if(start->next==NULL) {
return;
}else {
for (employee* i = start; i != NULL; i = i->next) {
employee* min = i;
for (employee* j = i->next; j != NULL; j = j->next) {
if (j->age < min->age) {
min = j;
if (min != i) {
// Swap the data of i and min nodes
char tempID[10], tempName[25], tempLName[25];
float tempSalary;
int tempAge, tempYears;
// Swap empID
strcpy(tempID, i->empID);
strcpy(i->empID, min->empID);
strcpy(min->empID, tempID);
// Swap firstName
strcpy(tempName, i->firstName);
strcpy(i->firstName, min->firstName);
strcpy(min->firstName, tempName);
// Swap salary
tempSalary = i->salary;
i->salary = min->salary;
min->salary = tempSalary;
// Swap last name
strcpy(tempLName, i->lastName);
strcpy(i->lastName, min->lastName);
strcpy(min->lastName, tempLName);
// Swap age
tempAge = i->age;
i->age = min->age;
min->age = tempAge;
// Swap yearsOfServies
tempYears = i->yearsOfServies;
i->yearsOfServies = min->yearsOfServies;
min->yearsOfServies = tempYears;
}
cout<<endl<<"List Sorted successfully by AGE in acending order"<<endl;
void display3OldestEmp(){ // DISPLAYING THE 3 OLDEST EMPLOYEE FROM LIST
int counter=0;
SelectionSortListByAge();
cout<<endl<<endl<<"**************************************"<<endl;
cout<<" Displaying The 3 oldest employees information information"<<endl;
cout<<"**************************************"<<endl;
for(employee*i=tail;counter<3;i=i->previous){
cout<<endl<<"_________________________________"<<endl;
cout<<"Employee Full Name: "<<i->firstName<<" "<<i->lastName<<endl;
cout<<"Employee ID: "<<i->empID<<endl;
cout<<"Employee Age: "<<i->age<<endl;
cout<<"Employee years of servies: "<<i->yearsOfServies<<endl;
cout<<"Employee salary: "<<i->salary<<endl;
counter++;
void displayNTHOldestEmp(){ // DISPLAYING THE Nth OLDEST EMPLOYEE FROM LIST
int counter=0;
int n,size=0;
cout<<endl<<"*****************************************"<<endl;
cout<<"The number of OLDEST employees you want to display: ";
cin>>n;
for(employee* i=start;i!=NULL;i=i->next){
size++;
if(size<n){
cout<<endl<<"The list only have "<<size<<" employees"<<endl;
return;
SelectionSortListByAge();
cout<<endl<<endl<<"**************************************"<<endl;
cout<<" Displaying The oldest employees information information"<<endl;
cout<<"**************************************"<<endl;
for(employee*i=tail;counter<n;i=i->previous){
cout<<endl<<"_________________________________"<<endl;
cout<<"Employee Full Name: "<<i->firstName<<" "<<i->lastName<<endl;
cout<<"Employee ID: "<<i->empID<<endl;
cout<<"Employee Age: "<<i->age<<endl;
cout<<"Employee years of servies: "<<i->yearsOfServies<<endl;
cout<<"Employee salary: "<<i->salary<<endl;
counter++;
void display(){
cout<<endl<<endl<<"**************************************"<<endl;
cout<<" Displaying List information"<<endl;
cout<<"**************************************"<<endl;
for(employee*i=start;i!=NULL;i=i->next){
cout<<endl<<"_________________________________"<<endl;
cout<<"Employee Full Name: "<<i->firstName<<" "<<i->lastName<<endl;
cout<<"Employee ID: "<<i->empID<<endl;
cout<<"Employee Age: "<<i->age<<endl;
cout<<"Employee years of servies: "<<i->yearsOfServies<<endl;
cout<<"Employee salary: "<<i->salary<<endl;
int main()
int n;
cout<<"How many employees you want to enter: "<<endl;
cin>>n;
for(int i=0;i<n;i++){
insertAtEnd();
display();
return 0;