home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
TUTORIAL
/
ICLCC
/
TUTOR5
/
EXAMPLE5.C
next >
Wrap
C/C++ Source or Header
|
1993-05-07
|
3KB
|
92 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
#include <iostream.h>
#include <tstring.h>
#include <string.h>
#include <iglobals.h>
#include <kperson.h>
//include <ikeyset.h>
//typedef IKeySet <Person , String> People;
#include <i......h>
typedef I.......Set <......, ......> People;
ostream & operator << ( ostream & sout, People people){
People::Cursor cursor(people);
cout << " Number of entries: " << people.numberOfElements() << " \n";
for (cursor.setToFirst();cursor.isValid() ;cursor.setToNext() ) {
cout << "Name :" << people.elementAt(cursor).getName();
cout << " TelephoneNumber" << people.elementAt(cursor).getTel() << "\n";
} /* endfor */
return sout;
}
class MyIterator: public IConstantIterator <Person> {
applyTo(Person const & person){
cout << "TelephoneNumber" << person.getTel() << "\n" ;
return True;
}
};
Boolean nonUSNumber (Person const & person, void*) {
if(!strncmp(person.getTel().getText()," xxx",4)){
return True;
}
return False;
}
int main () {
People people;
// ..............
people.add(Person("T. Wappler"," xxx-344543") );
people.add(Person("J. Uhl"," 001-344111"));
people.add(Person("M. Blum"," xxx-245343"));
people.add(Person("C. Ludwig"," xxx-9456543"));
people.add(Person("F. Seliger"," xxx-34835473"));
people.add(Person("H. Wingert"," 001-12345633"));
cout << people;
if (! people.removeElementWithKey("C. Ludwig")){
cout << "element not removed !\n" ;
}
MyIterator printNumbers;
people.allElementsDo(printNumbers);
People::Cursor cursor (people);
if (people.locateElementWithKey("F. Seliger", cursor)){
Person person(people.elementAt(cursor));
cout << person.getName() << person.getTel() << "\n";
} else{
cout<< "Invalid cursor \n";
}
people.removeAll(nonUSNumber);
cout << people;
return 0;
}