In this program you will create a linked list. Each node will have the following
ID: 3547283 • Letter: I
Question
In this program you will create a linked list.
Each node will have the following information:
Employee Number
First name
Last Name
Age
This program will have the following functions:
Display List
List the entries in the nodes.
Add Employees
Create new nodes in the list
Change Employee info
Edit and change information in a node in the list
User must specify the Employee number
Produce a meaningful message if the employee number is not in the list
Change Employee Number
Edit and change an employee number
User must specify the Old and new Employee numbers
Produce a meaningful messagej if the employee number is not in the list
Delete Employees
remove the node from the list.
Do not forget that if a node is removed from the middle you must reconnect the prior node with the next node.
Implement the nodes with both forward and backward pointers
Explanation / Answer
struct employee{
int empno;
char *fname;
char *lname;
int age;
struct employee *link;
};
void addemp(struct employee **,struct employee **);
void displaylist(struct employee);
void changeEmpNo(struct employee);
int main()
{
struct employee *fpointer,*bpointer;
fpointer=bpointer=NULL;
addemp(&fpointer,&lpointer);
displaylist(fpointer);
changeEmpNo(fpointer);
}
void addemp(struct employee **f1,struct employee **l1)
{
struct employee *temp;
char f[50],l[50];
int no,ag;
cout<<"Enter employee no.";
cin>>no;
cout<<"Enter first name";
gets(f);
cout<<"Enter last name";
gets(l);
cout<<"Enter age";
cin>>ag;
if(*f1==NULL)
{
temp=struct employee *(malloc(sizeof(struct employee)));
temp->empno=no;
temp->fname=f;
temp->lname=l;
temp->age=ag;
(*f1)=(*l1)=temp;
l1->link=NULL;
f1->link=NULL;
}
else
{
while(f1!=f2)
{
f1=f1->link;
}
temp=struct employee *(malloc(sizeof(struct employee)));
temp->empno=no;
temp->fname=f;
temp->lname=l;
temp->age=ag;
l1->link=temp;
(*l1)=temp;
l1->link=NULL;
}
}
void displaylist(struct employee *f)
{
int i=0;
while(f!=NULL)
{
i++;
cout<<""<<i<<"."<<endl;
cout<<"Employee Number "<<f->empno<<endl;
cout<<"Employee First Name"<<*(f->fname)<<endl;
cout<<"Employee last Name"<<*(f->lname)<<endl;
cout<<"Employee age"<<f->age;
f=f->link;
}
}
void changeEmpNo(struct employee *f)
{
int old,new,i=0;
cout<<"Enter old Employee No.";
cin>>old;
cout<<"Enter new Employee No.";
cin>>new;
while(f!=NULL)
{
if(f->empno==old)
{
i=1;
f->empno=new;
}
f=f->link;
}
if(i==0)
cout<<"Please Enter valid Employee No."
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.