The problem:
Given a list of imployees, create a simple program that allows the user to insert, delete, display and search an employee. The prog. shall display 10 imployees as default. Also a list of menu should be display. The menu names are insert, delete, dsplay and search.
My questions are:
1. what syntax should i use to insert character that allows 'space'?
2. is there a syntax that can 'search' name within a list,,, what is it?
*ideally, it should delete the list or name with a 'current node'.
*the bold part of the prog. is my problem....'searchng to a list'.
i created this prog. guided by the notes given to me.
#include <iostream.h>
struct node
{
char name[50], search[50];
node *nxt;
};
node *strtPtr = NULL;
node *current;
int choice;
void insert()
{
node *emp,*emp1;
emp=new node;
cout<<"Name of Employee:\n";
cin>>emp->name;
emp->nxt=NULL;
if(strtPtr==NULL)
{
strtPtr=emp;
current=strtPtr;
}
else
{
emp1= strtPtr;
while(emp1->nxt != NULL)
{
emp1=emp1->nxt;
}
emp1->nxt = emp;
current=emp;
}
cout<<"\n\n";
}
void display()
{
node *emp;
emp=strtPtr;
cout<<"\nList of the Employees: \n";
if(emp==NULL)
cout<<"List is empty\a\a\n\n";
else
{
while(emp!=NULL)
{
cout<<emp->name;
if(emp==current)
cout<<" <---";
cout<<endl;
emp=emp->nxt;
}
cout<<"\nEnd of List\n\n\n";
}
}
void del()
{
node *emp, *emp1;
current=strtPtr;
if(strtPtr==NULL)
cout<<"The List is empty\a\a\n";
else
{
emp=strtPtr;
if(emp->nxt==NULL)
{
delete emp;
strtPtr=NULL;
}
else
{
while(emp->nxt!=NULL)
{
emp1=emp;
emp=emp->nxt;
}
delete emp;
emp1->nxt=NULL;
}
}
}
void search()
{
node *emp,*emp1;
emp=strtPtr;
if(emp==NULL)
{
cout<<"List is empty\a\a\n\n";
}
else
{
emp1=new node;
cout<<"Search (name): ";
cin>>emp1->search;
cout<<endl;
if(emp==emp1)
{
emp=current;
}
else
{
while(emp!=emp1)
{
emp=emp->nxt;
emp->nxt=emp1;
current=emp;
}
}
}
}
void main()
{
strtPtr=NULL;
do
{
cout<<"Select your option\n"
<<"[0] Exit\n"
<<"[1] Insert new employee\n"
<<"[2] Display list of employees\n"
<<"[3] Delete employee\n"
<<"[4] Search employee\n\n>>";
cin>>choice;
cout<<"\n";
switch(choice)
{
case 1: insert(); break;
case 2: display(); break;
case 3: del(); break;
case 4: search(); break;
}
}
while(choice != 0);
}
Sir/madam, i'm new in making c++ program...hope you can help me with this... thank you..God bless..