#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "string.h"
using namespace std;
struct Abonent
{
char fio[40];
char address[40];
int phone;
};
struct List
{
Abonent abonenty;
List *next;
};
int first_num(int num)
{
int res = 0;
while (num)
{
res = num % 10;
num /= 10;
}
return res;
}
class n_abonent
{
private:
List *head;
public:
n_abonent()
{
head = NULL;
List *node1 = new List;
Abonent a = {"Zorina.A.A","ul.Juzhnaja d.1 kv-1",243543};
node1->abonenty = a;
node1->next = head;
head = node1;
List *node2 = new List;
Abonent b = {"Petrov.I.S","ul.Juzhnaja d.2 kv-2",143565};
node2->abonenty = b;
node2->next = head;
head = node2;
List *node3 = new List;
Abonent c = {"Ivanov.V.E","ul.Juzhnaja d.3 kv-3",235412};
node3->abonenty = c;
node3->next = head;
head = node3;
}
// в нашем конструкторе будет происходить заполнение 1х 3 пользователей элемента массива, т.е при создани класса будут иметься в массиве 3 сформированные записи
void insert_before() // заполняем остальных пользователей
{
Abonent a;
char c;
cout << endl << "Vvedite abonenta " << " \n";
cout << " fio: ";
cin.getline(a.fio, 40);
cout << " address: ";
cin.getline(a.address, 40);
cout << " phone: ";
cin >> a.phone;
cin.get(c);
List *node = new List;
node->abonenty = a;
node->next = head;
head = node;
}
//выводим пользователей
void vivod_abon () // В метод передается индекс элемента массива, который будем заполнять.
{
// выводим список абонентов
List *node = head;
{
printf("----------------------------------------------------------------\n");
printf("|%20s|%20s|%20s|\n","fio","address","phone");
printf("----------------------------------------------------------------\n");
while(node != NULL)
{
printf("|%20s|%20s|%20d|\n", node->abonenty.fio, node->abonenty.address, node->abonenty.phone);
node = node->next;
}
printf("----------------------------------------------------------------\n");
}
}
// По указанному индексу выводится элемент массива, который не содержит первую цифру 3
void svivod_abon()
{
cout <<"Skorrektirovannyj spisok abonentov" <<endl;
printf("----------------------------------------------------------------\n");
printf("|%20s|%20s|%20s|\n","fio","address","phone");
printf("----------------------------------------------------------------\n");
List *node = head->next;
List *temp = head;
while((temp->next != NULL) & (temp-> next != node))
if (first_num(node->abonenty.phone)==3)
temp = temp->next;
if(temp->next == node)
{
temp->next = node->next;
delete node;
}
printf("|%20s|%20s|%20d|\n", node->abonenty.fio, node->abonenty.address, node->abonenty.phone);
printf("----------------------------------------------------------------\n");
}
};
int main()
{
n_abonent n_a;
for (int i = 3; i < 5; i++)
{
n_a.insert_before();
}
n_a.vivod_abon();
n_a.svivod_abon();
_getch();
return 0;
}