Linked Lists of employee Class,doesn't work

November 14, 2010 at 20:09:20
Specs: Macintosh
anybody know whats the problem PLZ

#include <iostream.h>
class employee
{
public:
char name[21];
int num;
employee* next;
public:
void show()
{
cout << "name is : " << name;
cout << "\nnumber is : " << num;
}
void input()
{
cout << "name : ";
cin >> name;
cout << "\n number : ";
cin >> num;
}
};

////////////////////////////////////////////
class employee_list
{
private:
employee* first;
public:
employee_list()
{
first =NULL;
}
void add_item(employee* emp);
void display();
};

void employee_list::add_item(employee* emp)
{
emp->next = first;

first= emp->next;
}

void employee_list::display()
{
employee* current;
current =first;
while (current != NULL) {
current->show();
current = current->next;
}
}

int main (int argc, char * const argv[]) {

employee_list l1;
employee emp1, emp2;
emp1.input();
cout << endl;
emp2.input();

l1.add_item(&emp1);
l1.add_item(&emp2);

cout << endl;

l1.display();
return 0;
}


See More: Linked Lists of employee Class,doesnt work

Report •


#1
November 14, 2010 at 21:15:08
#include <iostream.h>
class employee
{
public:
char name[21];
int num;
employee* next;
public:
void show()
{
cout << endl << "name is : " << name;
cout << endl <<"number is : " << num;
}
void input()
{
cout << "name : ";
cin >> name;
cout << "\n number : ";
cin >> num;
}
};

////////////////////////////////////////////
class employee_list
{
private:
employee* first;
public:
employee_list()
{
first =NULL;
}
void add_item(employee* emp);
void display();
};

void employee_list::add_item(employee* emp)
{
emp->next = first;

first= emp;
}

void employee_list::display()
{
employee* current;
current =first;
while (current != NULL) {
current->show();
current = current->next;
}
}


int main (int argc, char * const argv[]) {

employee_list l1;
employee emp1, emp2;
emp1.input();
cout << endl;
emp2.input();

l1.add_item(&emp1);
l1.add_item(&emp2);

cout << endl;

l1.display();
int i;
cin >> i;
return 0;
}

/////////////////////////////////////

void employee_list::add_item(employee* emp)
{
emp->next = first;

first= emp->next;
}
///////////////////////////////////////////////////////////////////////////////////////////
void employee_list::add_item(employee* emp)
{
emp->next = first;

first= emp;
}
//////////////////////////////////////////////////////////////////////////////////////////////

........................................................................................

_Adnan_


Report •

#2
November 15, 2010 at 22:21:44
thx so much _Adnan_ now can try any thing comes to my mined because i have who help me , but
why did you use this, it works without them.
int i;
cin >> i;


Report •

#3
November 15, 2010 at 23:27:04
why did you use this, it works without them.
int i;
cin >> i;

I mostly use the run button. It is just to pause the program. you can remove it.
.................................................................................................................

Have you read this?
http://www.computing.net/answers/pr...

...................................................................................................................
_Adnan_


Report •

Related Solutions


Ask Question