-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.cpp
More file actions
322 lines (316 loc) · 6.5 KB
/
Copy pathrecord.cpp
File metadata and controls
322 lines (316 loc) · 6.5 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*Write C++ program using STL for Sorting and searching with user-defined records such as Person Record (Name, birth date, telephone no), item record (item code, item name, quantity and cost)*/
#include <iostream>
#include<list>
using namespace std;
class record
{
list<string>name,dob,phone,ni;
list<string>::iterator it1,it2,it3,j,k,l,c,n;
list<string>code;
list<int>number;
list<float>cost;
list<int>::iterator no,j1;
list<float>::iterator f,i;
public:
void getp();
void display();
void searchp(string);
void sortp();
void checkempty();
void getlist();
void displayit();
void searchlist();
void sortitem();
};
void record::getp()
{
int count;
string n,d,p;
cout<<"Enter the number of members in record:"<<endl;
cin>>count;
for(int i=1;i<=count;i++)
{
cout<<"Enter name:"<<endl;
cin>>n;
name.push_back(n);
cout<<"Enter date of birth:"<<endl;
cin>>d;
dob.push_back(d);
cout<<"Enter phone number:"<<endl;
cin>>p;
phone.push_back(p);
}
}
void record::searchp(string data)
{
int flag=0;
it1=name.begin();
it2=dob.begin();
it3=phone.begin();
while(it1!=name.end()&&it2!=dob.end()&&it3!=phone.end())
{
if(*it1==data)
{
cout<<"Record found!"<<endl;
cout<<"Corresponding D.O.B: "<<*it2<<endl;
cout<<"Corresponding phone number: "<<*it3<<endl;
flag=1;
break;
}
if(*it2==data)
{
cout<<"Record found!"<<endl;
cout<<"Corresponding name "<<*it1<<endl;
cout<<"Corresponding phone number: "<<*it3<<endl;
flag=1;
break;
}
if(*it3==data)
{
cout<<"Record found!"<<endl;
cout<<"Corresponding name: "<<*it1<<endl;
cout<<"Corresponding D.O.B: "<<*it2<<endl;
flag=1;
break;
}
it1++;
it2++;
it3++;
}
if(flag==0)
cout<<"Record not found."<<endl;
}
void record:: display()
{
it1=name.begin();
it2=dob.begin();
it3=phone.begin();
while(it1!=name.end())
{
cout<<*it1<<"\t"<<*it2<<"\t"<<*it3<<endl;
it1++;
it2++;
it3++;
}
}
void record::sortp()
{
string temp;
it1=name.begin();
it2=dob.begin();
it3=phone.begin();
j=it1;
k=it2;
l=it3;
j++;
k++;
l++;
while(it1!=name.end())
{
while(j!=name.end())
{
if(*it1>*j)
{
temp=*it1;
*it1=*j;
*j=temp;
temp=*it2;
*it2=*k;
*k=temp;
temp=*it3;
*it3=*l;
*l=temp;
}
j++;
k++;
l++;
}
it1++;
it2++;
it3++;
}
}
void record::getlist()
{
cout<<"Enter the number of items:"<<endl;
int c,no;
string n;
float f;
cin>>c;
for(int i=1;i<=c;i++)
{
cout<<"Enter item name:"<<endl;
cin>>n;
ni.push_back(n);
cout<<"Enter item code:"<<endl;
cin>>n;
code.push_back(n);
cout<<"Enter cost:"<<endl;
cin>>f;
cost.push_back(f);
cout<<"Enter the quantity:"<<endl;
cin>>no;
number.push_back(no);
}
}
void record::displayit()
{
c=code.begin();
n=ni.begin();
no=number.begin();
f=cost.begin();
while(c!=code.end())
{
cout<<*c<<"\t"<<*n<<"\t"<<*no<<"\t"<<*f<<endl;
c++;
n++;
no++;
f++;
}
}
void record::sortitem()
{
string temp;
int tempno;
float tempf;
c=code.begin();
n=ni.begin();
no=number.begin();
f=cost.begin();
i=f;
j1=no;
k=c;
l=n;
i++;
j1++;
k++;
l++;
while(f!=cost.end())
{
while(i!=cost.end())
{
if(*f>*i)
{
tempf=*f;
*f=*i;
*i=tempf;
temp=*n;
*n=*l;
*l=temp;
temp=*c;
*c=*k;
*k=temp;
tempno=*no;
*no=*j1;
*j1=tempno;
}
i++;
j1++;
k++;
l++;
}
f++;
n++;
no++;
c++;
}
}
void record::searchlist()
{
string key;
cout<<"Enter the item code:"<<endl;
cin>>key;
c=code.begin();
n=ni.begin();
no=number.begin();
f=cost.begin();
while(c!=code.end())
{
if(key==*c)
{
cout<<"Item available!"<<endl;
cout<<"Item name: "<<*n<<endl;
cout<<"Item quantity: "<<*no<<endl;
cout<<"Item cost: "<<*f<<endl;
}
c++;
n++;
no++;
f++;
}
}
int main()
{
record obj;
string key;
int ch,chr;
char x='y';
do
{
cout<<"1. Personal record\n2. Item record\nEnter choice:\n";
cin>>ch;
do
{
if(ch==1)
{
cout<<"1. Enter details\n2. Display\n3. Search entry\n4. Sort records\nEnter choice\n";
cin>>chr;
switch(chr)
{
case 1:
obj.getp();
obj.display();
break;
case 2:
obj.display();
break;
case 3:
cout<<"Enter either name, d.o.b or phone number you want to find\n";
cin>>key;
obj.searchp(key);
break;
case 4:
obj.sortp();
obj.display();
break;
default:
cout<<"Wrong choice"<<endl;
}
}
else if(ch==2)
{
cout<<"1. Enter details\n2. Display\n3. Search entry\n4. Sort records\nEnter choice\n";
cin>>chr;
switch(chr)
{
case 1:
obj.getlist();
obj.displayit();
break;
case 2:
obj.displayit();
break;
case 3:
obj.searchlist();
break;
case 4:
obj.sortitem();
obj.displayit();
break;
default:
cout<<"Wrong choice"<<endl;
}
}
else
{
cout<<"Wrong choice"<<endl;
break;
}
cout<<"Do you wish to continue? Y or N\n";
cin>>x;
}while(x=='y'||x=='Y');
cout<<"Do you wish to select another type of record? Y or N\n";
cin>>x;
}while(x=='y'||x=='Y');
return 0;
}