include stdafx include iostream include conio include string using nam

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#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" <<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;
}