-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaba2sem-2.cpp
172 lines (159 loc) · 3.21 KB
/
laba2sem-2.cpp
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <malloc.h>
#include <string>
using namespace std;
struct TelephoneS
{
int id;
char Name[10];
char Shurname[20];
int namber;
TelephoneS* Next;
TelephoneS* Prev;
};
struct List
{
TelephoneS* itsFirst;
TelephoneS* itsLast;
};
void Menu();
void AddItem(List&);
//void DellItem(list&);
void PrintList(List&);
void CreateList(List*&);
List* theList = 0 ;
int main()
{
List* itsFirst=0;
List* itsLast=0;
Menu();
return 0;
}
void Menu()
{
bool quit = false;
while (true)
{
int choice;
cout<< "\n ******* MENU ******* \n";
cout<< "(1) vvedite spisok \n";
cout<< "(2) prosmotr \n";
cout<< "(3) dobavlenie \n";
cout<< "(4) udalenie \n";
cout<< "(5) exit \n";
cin>> choice;
switch (choice)
{
case(1):
if (!theList)
{
CreateList (theList);
theList->itsFirst = NULL;
theList->itsLast = NULL;
cout<<"the list has been created ... \n";
}
else
cout<<"the List is alrealy created ... \n";
break;
case(2):
if (theList)
PrintList(*theList);
else
cout<<" the List is not created ... \n";
break;
case(3):
if (theList)
AddItem(*theList);
else
cout<<" the List is not created ... \n";
break;
//case(4):
// if (theList)
//DeleteItem(*theList);
// else
// cout<<" the List is not created .. \n";
// break;
case(5):
quit = true;
}
if (quit == true)
break;
}
}
void AddItem(List &theList)
{
cout<<"\n *** dobavit novogo abonenta ***\n";
cout<<" Vvedite name: \n";
TelephoneS* newTelephoneS = new TelephoneS;
cin>> newTelephoneS -> Name;
cout<<" Vvedite Shurname: \n";
cin>> newTelephoneS -> Shurname;
cout<< " Vvedite namber: \n";
cin>> newTelephoneS -> namber;
if (theList.itsLast)
{
theList.itsLast -> Next = newTelephoneS;
newTelephoneS -> Prev = theList.itsLast;
}
else
{
theList.itsFirst =newTelephoneS;
newTelephoneS -> Prev = 0 ;
}
theList.itsLast = newTelephoneS;
newTelephoneS -> Next = 0;
cout<<" *** item was added *** \n";
}
void CreateList (List*&)
{
bool temp=true;
string answer;
TelephoneS* pList,* p;
TelephoneS* itsFirst;
TelephoneS* itsLast;
pList = NULL;
do
{p=(TelephoneS*)malloc(sizeof(TelephoneS));
cout<<"\n *** dobavit novogo abonenta ***\n";
cout<<" Vvedite name: \n";
TelephoneS* newTelephoneS = new TelephoneS;
cin>> newTelephoneS -> Name;
cout<<" Vvedite Shurname: \n";
cin>> newTelephoneS -> Shurname;
cout<< " Vvedite namber: \n";
cin>> newTelephoneS -> namber;
p -> Prev = pList;
if (pList != NULL)
pList -> Next = p;
else
itsFirst = p;
pList=p;
//puts ("Zaconchit' - <esc>");
cout<<"\n prodolgit vvod? [yes/no]";
cin>>answer;
if((answer=="yes") || (answer=="y") || (answer=="Yes") || (answer=="Y"))
{
temp=true;
}
else if((answer=="no") || (answer=="n") || (answer=="No") || (answer=="N"))
{
break;
}
}
while (!temp);
itsLast=p;
itsLast -> Next = NULL;
}
void PrintList(List &theList)
{
cout<<"\n *** prosmotr spiska *** \n";
TelephoneS* curTelephoneS = theList.itsFirst;
while (curTelephoneS)
{
cout<< curTelephoneS -> Name;
cout<< curTelephoneS -> Shurname;
cout<< curTelephoneS -> namber;
curTelephoneS = curTelephoneS -> Next;
}
cout<<"\n *** end ***\n";
}