Код: Выделить всё
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdio.h>
class Human
{
public:
char szFirstName[128];
char szLastName[128];
int nAge;
Human* pNext;
};
Human* pHead = 0;
void addTail(Human* pH)
{
pH->pNext = 0;
if (pHead ==0)
{
pHead = pH;
return;
}
Human* pCurrent = pHead;
while(pCurrent->pNext)
{
pCurrent = pCurrent->pNext;
}
pCurrent->pNext = pH;
}
Human* getData()
{
Human* pH = new Human;
cout << "\nВведите имя: ";
cin >> pH->szFirstName;
if ((strcmp(pH->szFirstName,"exit") ==0))
{
delete pH;
return 0;
}
cout << "Введите фамилию: ";
cin >> pH->szLastName;
cout << "Введите возраст: ";
cin >> pH->nAge;
return pH;
}
void displayData(Human* pH)
{
cout << pH->szFirstName
<< " "
<< pH->szLastName
<< ",возраст - "
<< pH->nAge;
}
int main()
{
Human* pH;
while(pH = getData())
{
addTail(pH);
}
while(pH)
{
displayData(pH);
pH = pH->pNext;
}
return 0;
}