-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
650 lines (515 loc) · 22.9 KB
/
main.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/* author: josef dolezal */
/* git: https://github.com/josefdolezal */
#ifndef __PROGTEST__
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <memory>
#include <vector>
#include <algorithm>
using namespace std;
#endif /* __PROGTEST__ */
class CCarList
{
public:
CCarList( void ) {}
CCarList( vector<string> p, vector<unsigned int> v ): plates(p), vins(v) {}
string RZ ( void ) const;
unsigned int VIN ( void ) const;
bool AtEnd ( void ) const;
void Next ( void );
CCarList& operator = ( const CCarList & );
friend ostream& operator << ( ostream &, const CCarList & );
private:
vector<string> plates;
vector<unsigned int> vins;
};
class COwnerList
{
public:
COwnerList( void ) {}
COwnerList( vector<string> n, vector<string> s ): names(n), surnames(s) {}
string Name ( void ) const;
string Surname ( void ) const;
bool AtEnd ( void ) const;
void Next ( void );
COwnerList& operator = ( const COwnerList & );
friend ostream& operator << ( ostream &, COwnerList & );
private:
vector<string> names;
vector<string> surnames;
};
class CRegister
{
public:
CRegister ( void ) {}
~CRegister ( void );
bool AddCar ( const string & rz,
unsigned int vin,
const string & name,
const string & surname );
bool DelCar ( const string & rz );
bool DelCar ( unsigned int vin );
bool Transfer ( const string & rz,
const string & nName,
const string & nSurname );
bool Transfer ( unsigned int vin,
const string & nName,
const string & nSurname );
CCarList ListCars ( const string & name,
const string & surname ) const;
int CountCars ( const string & name,
const string & surname ) const;
COwnerList ListOwners ( const string & RZ ) const;
int CountOwners ( const string & RZ ) const;
COwnerList ListOwners ( unsigned int vin ) const;
int CountOwners ( unsigned int vin ) const;
friend ostream& operator << ( ostream &, const CRegister & );
private:
struct Person;
struct CCar {
CCar( string rz = "", unsigned int vin = 0, Person *owner = NULL ): rz(rz), vin(vin), owner(owner) {}
bool operator == ( const CCar & );
string rz;
unsigned int vin;
vector<Person *> owners;
Person *owner;
};
struct Person {
Person( string name, string surname ): name(name), surname(surname) {}
bool operator == ( const Person & ) const;
bool operator < ( const Person & ) const;
string name;
string surname;
vector<CCar *> plates;
vector<CCar *> vins;
};
vector<Person *> m_ListByNames;
vector<CCar *> m_ListByRZ;
vector<CCar *> m_ListByVin;
bool contentsRZ( const string & ) const;
bool contentsVin( unsigned int ) const;
void addPersonRZ( Person &, CCar * );
void addPersonVin( Person &, CCar *);
void removePersonCar( const CCar & );
void DelCar( CCar & );
};
/*
* CCarList class definition
------------------------------------------------------------------ */
string CCarList::RZ( void ) const {
return plates.back();
}
unsigned int CCarList::VIN( void ) const {
return vins.back();
}
bool CCarList::AtEnd( void ) const {
return vins.rbegin() == vins.rend();
}
void CCarList::Next( void ) {
if ( plates.size() != 0 ) {
plates.pop_back();
vins.pop_back();
}
}
/* PRIVATE */
CCarList& CCarList::operator = ( const CCarList &n ) {
if( this == &n ) return *this;
plates = n.plates;
vins = n.vins;
return *this;
}
/**
* COwnerList class definition
------------------------------------------------------------------ */
string COwnerList::Name( void ) const {
return names.back();
}
string COwnerList::Surname( void ) const {
return surnames.back();
}
bool COwnerList::AtEnd( void ) const {
return names.rend() == names.rbegin();
}
void COwnerList::Next( void ) {
if( names.size() != 0 ) {
names.pop_back();
surnames.pop_back();
}
}
COwnerList& COwnerList::operator = ( const COwnerList &n ) {
if( this == &n ) return *this;
names = n.names;
surnames = n.surnames;
return *this;
}
/* PRIVATE */
/**
* CRegister class definition
------------------------------------------------------------------ */
CRegister::~CRegister( void ) {
for ( auto &n : m_ListByNames ) delete n;
for ( auto &r : m_ListByRZ ) delete r;
}
bool CRegister::AddCar( const string &rz, unsigned int vin, const string &name, const string &surname) {
if ( contentsRZ( rz ) || contentsVin( vin ) ) return false;
Person *owner = new Person( name, surname );
CCar *car = new CCar( rz, vin );
auto oIt = lower_bound( m_ListByNames.begin(), m_ListByNames.end(), owner, [] ( const Person *l, const Person *r ) { return *l < *r; } );
if ( oIt != m_ListByNames.end() && *(*oIt) == *owner ) { // majitel uz existuje
car->owner = *oIt;
car->owners.push_back( *oIt );
addPersonRZ( *(*oIt), car );
addPersonVin( *(*oIt), car );
delete owner;
} else { // novy majitel
m_ListByNames.insert( oIt, owner );
car->owner = owner;
car->owners.push_back( owner );
owner->plates.push_back( car );
owner->vins.push_back( car );
}
auto rIt = lower_bound( m_ListByRZ.begin(), m_ListByRZ.end(), car, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
m_ListByRZ.insert( rIt, car );
auto vIt = lower_bound( m_ListByVin.begin(), m_ListByVin.end(), car, [] ( const CCar *l, const CCar *r) { return l->vin < r->vin; } );
m_ListByVin.insert( vIt, car );
return true;
}
bool CRegister::DelCar( const string &rz ) {
if ( ! contentsRZ( rz ) ) return false;
CCar tmpCar( rz );
auto rIt = lower_bound( m_ListByRZ.begin(), m_ListByRZ.end(), &tmpCar, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
CCar *del = (*rIt);
tmpCar.vin = del->vin;
DelCar( *del );
delete del;
return true;
}
bool CRegister::DelCar( unsigned int vin ) {
if ( ! contentsVin( vin ) ) return false;
CCar tmpCar( "", vin );
auto vIt = lower_bound( m_ListByVin.begin(), m_ListByVin.end(), &tmpCar, [] ( const CCar *l, const CCar *r ) { return l->vin < r->vin; } );
return DelCar( (*vIt)->rz );
}
bool CRegister::Transfer( const string &rz, const string &name, const string &surname ) {
CCar tmpCar( rz );
auto cIt = lower_bound( m_ListByRZ.begin(), m_ListByRZ.end(), &tmpCar, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
if( cIt != m_ListByRZ.end() && (**cIt).rz == tmpCar.rz ) { // existujici auto
Person *owner = new Person( name, surname );
if ( *((*cIt)->owner) == *owner ) { // stejny majitel
delete owner;
return false;
}
auto oIt = lower_bound( m_ListByNames.begin(), m_ListByNames.end(), owner, [] ( const Person *l, const Person *r ) { return *l < *r; } );
removePersonCar( **cIt );
if ( oIt != m_ListByNames.end() && **oIt == *owner ) { // existujici majitel
(*cIt)->owner = *oIt;
(*cIt)->owners.push_back( *oIt );
addPersonRZ( **oIt, *cIt);
addPersonVin( **oIt, *cIt);
delete owner;
} else { // novy majitel
(*cIt)->owner = owner;
(*cIt)->owners.push_back( owner );
m_ListByNames.insert( oIt, owner );
owner->plates.push_back( *cIt );
owner->vins.push_back( *cIt );
}
return true;
}
return false;
}
bool CRegister::Transfer( unsigned int vin, const string &name, const string &surname ) {
if ( ! contentsVin( vin) ) return false;
CCar tmp( "", vin );
auto it = lower_bound(m_ListByVin.begin(), m_ListByVin.end(), &tmp, [] ( const CCar *l, const CCar *r) { return l->vin < r->vin; } );
return Transfer( (*it)->rz, name, surname );
}
CCarList CRegister::ListCars( const string &name, const string &surname ) const {
Person p( name, surname );
vector<string> plates;
vector<unsigned int> vins;
auto it = lower_bound( m_ListByNames.begin(), m_ListByNames.end(), &p, [] ( const Person *l, const Person *r ) { return *l < *r; } );
if( it != m_ListByNames.end() && **it == p ) {
for( auto &c : (*it)->vins ) {
plates.push_back( c->rz );
vins.push_back( c->vin );
}
}
return CCarList( plates, vins );
}
int CRegister::CountCars( const string &name, const string &surname ) const {
Person p( name, surname );
auto it = lower_bound( m_ListByNames.begin(), m_ListByNames.end(), &p, [] ( const Person *l, const Person *r ) { return *l < *r; } );
return ( it != m_ListByNames.end() && **it == p ) ? (int) (*it)->plates.size() : 0;
}
COwnerList CRegister::ListOwners( const string &rz ) const {
vector<string> names;
vector<string> surnames;
CCar c( rz );
auto it = lower_bound( m_ListByRZ.begin(), m_ListByRZ.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
if ( it != m_ListByRZ.end() && (*it)->rz == c.rz ) {
for ( auto &o : (*it)->owners ) {
names.push_back( o->name );
surnames.push_back( o->surname );
}
}
return COwnerList( names, surnames );
}
int CRegister::CountOwners( const string &rz ) const {
CCar c( rz );
auto it = lower_bound( m_ListByRZ.begin(), m_ListByRZ.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
return ( it != m_ListByRZ.end() && (*it)->rz == c.rz ) ? (int) (*it)->owners.size() : 0;
}
COwnerList CRegister::ListOwners( unsigned int vin ) const {
vector<string> names;
vector<string> surnames;
CCar c( "", vin );
auto it = lower_bound( m_ListByVin.begin(), m_ListByVin.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->vin < r->vin; } );
if ( it != m_ListByVin.end() && (*it)->vin == c.vin ) {
for ( auto &o : (*it)->owners ) {
names.push_back( o->name );
surnames.push_back( o->surname );
}
}
return COwnerList( names, surnames );
}
int CRegister::CountOwners( unsigned int vin ) const {
CCar c( "", vin );
auto it = lower_bound( m_ListByVin.begin(), m_ListByVin.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->vin < r->vin; } );
return ( it != m_ListByVin.end() && (*it)->vin == c.vin ) ? (int) (*it)->owners.size() : 0;
}
ostream& operator << ( ostream &os, const CRegister &c ) {
cout << "Persons" << endl;
for ( auto &p : c.m_ListByNames ) cout << p->surname << " " << p->name << ", no. of p: " << p->plates.size() << ", v: " << p->vins.size() << endl;
cout << "Plates" << endl;
for ( auto &p : c.m_ListByRZ ) cout << p->rz << " " << p->owner->surname << " " << p->owner->name << endl;
return os;
}
/* PRIVATE */
bool CRegister::contentsRZ( const string &rz ) const{
CCar tmp( rz );
return binary_search( m_ListByRZ.begin(), m_ListByRZ.end(), &tmp, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
}
bool CRegister::contentsVin( unsigned int vin ) const {
CCar tmp( "", vin );
return binary_search( m_ListByVin.begin(), m_ListByVin.end(), &tmp, [] ( const CCar *l, const CCar *r ) { return l->vin < r->vin; } );
}
void CRegister::DelCar( CCar &c ) {
removePersonCar( c );
auto rIt = lower_bound( m_ListByRZ.begin(), m_ListByRZ.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
auto vIt = lower_bound( m_ListByVin.begin(), m_ListByVin.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->vin < r->vin; } );
if( rIt != m_ListByRZ.end() && **rIt == c ) m_ListByRZ.erase( rIt );
if( vIt != m_ListByVin.end() && **vIt == c ) m_ListByVin.erase( vIt );
}
void CRegister::addPersonRZ( Person &p, CCar *c ) {
auto it = lower_bound( p.plates.begin(), p.plates.end(), c, [] ( const CRegister::CCar *l, const CRegister::CCar *r ) { return l->rz < r->rz; } );
p.plates.insert( it, c );
}
void CRegister::addPersonVin( Person &p, CCar *c ) {
auto it = lower_bound( p.vins.begin(), p.vins.end(), c, [] ( const CRegister::CCar *l, CRegister::CCar *r ) { return l->vin < r->vin; } );
p.vins.insert( it, c );
}
void CRegister::removePersonCar( const CCar &c ) {
auto orIt = lower_bound( c.owner->plates.begin(), c.owner->plates.end(), &c, [] ( const CCar *l, const CCar *r ) { return l->rz < r->rz; } );
auto ovIt = lower_bound( c.owner->vins.begin(), c.owner->vins.end(), &c, [] ( const CCar *l, const CCar *r ) {
return l->vin < r->vin; } );
if( orIt != c.owner->plates.end() && **orIt == c ) c.owner->plates.erase( orIt );
if( ovIt != c.owner->vins.end() && **ovIt == c ) c.owner->vins.erase( ovIt );
}
bool CRegister::Person::operator == ( const Person &p ) const {
return this->name == p.name && this->surname == p.surname;
}
bool CRegister::Person::operator < ( const Person &p ) const {
if( this->surname == p.surname ) return this->name < p.name;
return this->surname < p.surname;
}
bool CRegister::CCar::operator == ( const CCar &c ) {
return this->rz == c.rz && this->vin == c.vin;
}
#ifndef __PROGTEST__
void testsN( void ) {
CRegister b1;
assert ( b1 . AddCar ( "ABC-12-34", 1000, "John", "Smith" ) == true );
assert ( b1 . AddCar ( "ABC-32-22", 2000, "John", "Hacker" ) == true );
assert ( b1 . AddCar ( "XYZ-11-22", 10, "Peter", "Smith" ) == true );
assert ( b1 . CountCars ( "John", "Hacker" ) == 1 );
for ( CCarList l = b1 . ListCars ( "John", "Hacker" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
}
void testsP( void ) {
CRegister b1;
assert ( b1 . AddCar ( "ABC-12-34", 1000, "John", "Smith" ) == true );
assert ( b1 . AddCar ( "ABC-32-22", 2000, "John", "Hacker" ) == true );
assert ( b1 . AddCar ( "ABC-33-22", 2001, "John", "Hacker" ) == true );
assert ( b1 . AddCar ( "XYZ-11-22", 10, "Peter", "Smith" ) == true );
assert ( b1 . AddCar ( "XYZ-11-22", 10, "Peter", "Smith" ) == false );
CCarList l = b1 . ListCars ( "John", "Hacker" );
assert( b1.CountOwners( "ABC-12-34" ) == 1 );
assert( b1.CountOwners( 1000 ) == 1 );
assert( b1.DelCar( "ABC-12-34" ) == true );
assert( b1.DelCar( 2000 ) == true );
assert( b1.DelCar( "ABC-12-34" ) == false );
assert( b1.DelCar( 2000 ) == false );
assert( b1.Transfer( "neexistujici", "Jan", "Dolezal" ) == false );
assert( b1.Transfer( 12341234, "Jan", "Dolezal" ) == false );
assert( b1.Transfer( 2000, "Jan", "Dolezal" ) == false );
assert( b1.Transfer( "ABC-12-34", "Jan", "Dolezal" ) == false);
assert( b1.Transfer( "XYZ-11-22", "John", "Hacker" ) == true );
assert( b1.Transfer( "ABC-33-22", "Josef", "Dolezal" ) == true );
assert( b1.CountOwners( "XYZ-11-22" ) == 2 );
assert( b1.CountOwners( 10 ) == 2 );
assert( b1.CountOwners( "ABC-33-22" ) == 2 );
assert( b1.CountOwners( 2001 ) == 2 );
assert( b1.CountCars( "Josef", "Dolezal" ) == 1);
assert( b1.CountCars( "Deda", "Libor" ) == 0 );
assert( b1.CountCars( "Peter", "Smith" ) == 0 );
assert( b1.Transfer( "ABC-33-22", "Deda", "Libor" ) == true );
assert( b1.CountCars( "Deda", "Libor" ) == 1);
assert( b1.CountOwners( "ABC-33-22" ) == 3 );
assert( b1.CountOwners( 2001 ) == 3 );
cout << b1 << endl;
}
void testsV( void ) {
CRegister b1;
assert ( b1 . AddCar ( "ABC-12-34", 1000, "John", "Smith" ) == true );
assert ( b1 . AddCar ( "ABC-32-22", 2000, "John", "Hacker" ) == true );
assert ( b1 . AddCar ( "XYZ-11-22", 10, "Peter", "Smith" ) == true );
assert ( b1 . CountCars ( "John", "Hacker" ) == 1 );
for ( CCarList l = b1 . ListCars ( "John", "Hacker" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// the following license plate + VIN
// ABC-32-22, 2000
assert ( b1 . CountOwners ( "ABC-12-34" ) == 1 );
for ( COwnerList l = b1 . ListOwners ( "ABC-12-34" ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 1 owners in that order:
// Smith, John
assert ( b1 . CountOwners ( 10 ) == 1 );
for ( COwnerList l = b1 . ListOwners ( 10 ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 1 owners in that order:
// Smith, Peter
assert ( b1 . Transfer ( "XYZ-11-22", "John", "Hacker" ) == true );
assert ( b1 . Transfer ( 10, "Will", "Smith" ) == true );
assert ( b1 . Transfer ( "XYZ-11-22", "John", "Hacker" ) == true );
assert ( b1 . AddCar ( "XYZ-99-88", 20, "John", "Smith" ) == true );
assert ( b1 . CountCars ( "John", "Smith" ) == 2 );
for ( CCarList l = b1 . ListCars ( "John", "Smith" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// the following 2 license plates + VINs, in any order:
// ABC-12-34, 1000
// XYZ-99-88, 20
assert ( b1 . CountCars ( "John", "Hacker" ) == 2 );
for ( CCarList l = b1 . ListCars ( "John", "Hacker" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// the following 2 license plates + VINs, in any order:
// ABC-32-22, 2000
// XYZ-11-22, 10
assert ( b1 . CountCars ( "Peter", "Smith" ) == 0 );
for ( CCarList l = b1 . ListCars ( "Peter", "Smith" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// empty output
assert ( b1 . CountOwners ( 10 ) == 4 );
for ( COwnerList l = b1 . ListOwners ( 10 ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 4 owners in that order:
// Hacker, John
// Smith, Will
// Hacker, John
// Smith, Peter
assert ( b1 . CountOwners ( "XYZ-11-22" ) == 4 );
for ( COwnerList l = b1 . ListOwners ( "XYZ-11-22" ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 4 owners in that order:
// Hacker, John
// Smith, Will
// Hacker, John
// Smith, Peter
assert ( b1 . Transfer ( "XYZ-11-22", "Jane", "Black" ) == true );
assert ( b1 . CountCars ( "Jane", "Black" ) == 1 );
for ( CCarList l = b1 . ListCars ( "Jane", "Black" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// the following license plate + VIN
// XYZ-11-22, 10
assert ( b1 . CountCars ( "John", "Smith" ) == 2 );
for ( CCarList l = b1 . ListCars ( "John", "Smith" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// the following 2 license plates + VINs, in any order:
// ABC-12-34, 1000
// XYZ-99-88, 20
assert ( b1 . CountOwners ( 10 ) == 5 );
for ( COwnerList l = b1 . ListOwners ( 10 ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 5 owners in that order:
// Black, Jane
// Hacker, John
// Smith, Will
// Hacker, John
// Smith, Peter
assert ( b1 . CountOwners ( "XYZ-11-22" ) == 5 );
for ( COwnerList l = b1 . ListOwners ( "XYZ-11-22" ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 5 owners in that order:
// Black, Jane
// Hacker, John
// Smith, Will
// Hacker, John
// Smith, Peter
assert ( b1 . DelCar ( "XYZ-11-22" ) == true );
assert ( b1 . DelCar ( 1000 ) == true );
assert ( b1 . CountCars ( "Jane", "Black" ) == 0 );
for ( CCarList l = b1 . ListCars ( "Jane", "Black" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// empty output
assert ( b1 . AddCar ( "XYZ-11-22", 30, "George", "White" ) == true );
assert ( b1 . CountOwners ( 30 ) == 1 );
for ( COwnerList l = b1 . ListOwners ( 30 ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 1 owners in that order:
// White, George
assert ( b1 . CountOwners ( "XYZ-11-22" ) == 1 );
for ( COwnerList l = b1 . ListOwners ( "XYZ-11-22" ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 1 owners in that order:
// White, George
CRegister b2;
assert ( b2 . AddCar ( "ABC-12-34", 10, "John", "Smith" ) == true );
assert ( b2 . AddCar ( "ABC-32-22", 20, "John", "Hacker" ) == true );
assert ( b2 . AddCar ( "XYZ-11-22", 30, "Peter", "Smith" ) == true );
assert ( b2 . AddCar ( "XYZ-11-22", 30, "Jane", "Black" ) == false );
assert ( b2 . AddCar ( "XYZ-11-22", 50, "Jane", "Black" ) == false );
assert ( b2 . AddCar ( "ZZZ-11-22", 30, "Jane", "Black" ) == false );
assert ( b2 . DelCar ( "AAA-11-11" ) == false );
assert ( b2 . DelCar ( 9999 ) == false );
assert ( b2 . DelCar ( "ABC-32-22" ) == true );
assert ( b2 . DelCar ( 20 ) == false );
assert ( b2 . DelCar ( 30 ) == true );
assert ( b2 . DelCar ( "XYZ-11-22" ) == false );
assert ( b2 . Transfer ( "BBB-99-99", "John", "Smith" ) == false );
assert ( b2 . Transfer ( "ABC-12-34", "John", "Smith" ) == false );
assert ( b2 . Transfer ( 9999, "John", "Smith" ) == false );
assert ( b2 . Transfer ( 10, "John", "Smith" ) == false );
assert ( b2 . CountCars ( "George", "White" ) == 0 );
for ( CCarList l = b2 . ListCars ( "George", "White" ); ! l . AtEnd (); l . Next () )
cout << l . RZ () << ", " << l . VIN () << endl;
// empty output
assert ( b2 . CountOwners ( "AAA-AA-AA" ) == 0 );
for ( COwnerList l = b2 . ListOwners ( "AAA-AA-AA" ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 0 owners in that order:
assert ( b2 . CountOwners ( 9999 ) == 0 );
for ( COwnerList l = b2 . ListOwners ( 9999 ); ! l . AtEnd (); l . Next () )
cout << l . Surname () << ", " << l . Name () << endl;
// the following 0 owners in that order:
}
int main ( void )
{
testsP();
return 0;
}
#endif /* __PROGTEST__ */