#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; } 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"); } } void svivod_abon() { cout <<"Skorrektirovannyj spisok abonentov" <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; }