本文整理汇总了C++中AddressBook类的典型用法代码示例。如果您正苦于以下问题:C++ AddressBook类的具体用法?C++ AddressBook怎么用?C++ AddressBook使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AddressBook类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int menu_choice=0;
AddressBook personal;
while(menu_choice!=4)
{
cout << "What would you like to do?" << endl;
cout << "1) Add a contact" << endl;
cout << "2) Search for a contact" << endl;
cout << "3) Display all contacts" << endl;
cout << "4) Exit program" << endl;
cout << "Please enter your choice: ";
cin >> menu_choice;
if(menu_choice<1 || menu_choice>4)
{
cout << "Error Invalid Input" << endl;
menu_choice=0;
}
if(menu_choice==1)
{
AddToBook(personal);
}
if(menu_choice==2)
{
Search(personal);
}
if(menu_choice==3)
{
personal.displayContacts();
}
}
return 0;
}
示例2: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}
示例3: main6
int main6()
{
#if 0
// read in the name from a user, which we want to search
cout << " enter name";
string name;
cin>> name;
// change 'findMatchingAddress' to 'find'
// notice that the lambda function uses the the variable 'name'
// global_address_book.findMatchingAddresses ( [&] (const string& addr) { return addr.find( name ) != string::npos; } );
global_address_book.find ( [&] (const string& addr) { return addr.find( name ) != string::npos; } );
// error: ‘class AddressBook’ has no member named ‘find’
// global_address_book.find( [&] (const string& addr) { return addr.length() >= min_len; } );
// ^
int min_len = 0;
cout << " enter min_len";
cin >> min_len;
// change 'findMatchingAddress' to 'find'
global_address_book.find( [&] (const string& addr) { return addr.length() >= min_len; } );
// error: ‘class AddressBook’ has no member named ‘find’
// global_address_book.find( [&] (const string& addr) { return addr.length() >= min_len; } );
// ^
cout << "\n";
#endif
return 0;
} // main6
示例4: print
void print(AddressBook &book)
{
for(AddressBook::const_iterator person = book.begin();
book.end() != person;
++person)
{
cout << "Person ID: " << person->id() << endl;
cout << " Name: " << person->name() << endl;
cout << " Email: " << person->email() << endl;
for(uint32_t j = 0, size = person->phones_size(); size > j; ++j)
{
const Phone *phone = person->phone(j);
switch (phone->type())
{
case Phone::MOBILE:
cout << "Mobile phone #: ";
break;
case Phone::HOME:
cout << " Home phone #: ";
break;
case Phone::WORK:
cout << " Work phone #: ";
break;
}
cout << phone->number() << endl;
}
cout << endl;
}
}
示例5: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QMainW
AddressBook addressBook;
addressBook.show();
return a.exec();
}
示例6: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AddressBook *addressBook = new AddressBook;
addressBook->show();
return app.exec();
}
示例7: main
int main( int argc, char **argv )
{
KAboutData aboutData( "bigwrite", 0, ki18n( "BigWriteKabc" ), "0.1" );
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication app( false );
AddressBook ab;
ResourceFile r( QLatin1String( "my.kabc" ), QLatin1String( "vcard" ) );
ab.addResource( &r );
for ( int i = 0; i < 5000; ++i ) {
Addressee a;
a.setGivenName( QLatin1String( "number" ) + QString::number( i ) );
a.setFamilyName( QLatin1String( "Name" ) );
a.insertEmail( QString::number( i ) + QLatin1String( "@domain" ) );
ab.insertAddressee( a );
}
printf( "\n" );
Ticket *t = ab.requestSaveTicket( &r );
if ( t ) {
struct tms start;
times( &start );
#if 0
kDebug() << "utime :" << int( start.tms_utime );
kDebug() << "stime :" << int( start.tms_stime );
kDebug() << "cutime:" << int( start.tms_cutime );
kDebug() << "cstime:" << int( start.tms_cstime );
#endif
if ( !ab.save( t ) ) {
kDebug() << "Can't save.";
}
struct tms end;
times( &end );
#if 0
kDebug() << "utime :" << int( end.tms_utime );
kDebug() << "stime :" << int( end.tms_stime );
kDebug() << "cutime:" << int( end.tms_cutime );
kDebug() << "cstime:" << int( end.tms_cstime );
#endif
kDebug() << "UTime:" << int( end.tms_utime ) - int( start.tms_utime );
kDebug() << "STime:" << int( end.tms_stime ) - int( start.tms_stime );
} else {
kDebug() << "No ticket for save.";
}
}
示例8: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!QAxFactory::isServer()) {
AddressBook addressBook;
addressBook.show();
return app.exec();
}
return app.exec();
}
示例9: main
int main(){
AddressBook test;
test.NoPeople = 2;
test.People[0].storeName("Ann", "Southall");
test.People[0].storeAddress("12 Park st");
test.People[0].storePhNo("0427854623");
test.People[1].storeName("Lawoko","Lars");
test.People[1].storeAddress("26 Wilpena Place, Vermont South, Melbourne");
test.People[1].storePhNo("0400510502");
test.printAddressBook();
}
示例10: read_write_read_with_mergefrom
void read_write_read_with_mergefrom(const string &filename, AddressBook &book)
{
{
fstream read_f(filename.c_str(), ios::in | ios::binary);
if (!read_f)
{
cerr << filename << ": file not found, exit..." << endl;
return;
}
book.ParseFromIstream(&read_f);
cout << "book: " << book.DebugString() << endl;
}
book.set_host_name("carl_update_mergefrom");
int index = 0;
for (; index < book.person_size(); ++index)
{
Person person;
person.CopyFrom(book.person(index));
person.set_age(100);
book.mutable_person(index)->MergeFrom(person);
}
{
fstream write_f(filename.c_str(), ios::out | ios::trunc | ios::binary);
if (!book.SerializeToOstream(&write_f))
{
cerr << "failed to write addressbook" << endl;
return;
}
}
{
fstream read_f(filename.c_str(), ios::in | ios::binary);
if (!read_f)
{
cerr << filename << ": file not found, exit..." << endl;
return;
}
book.ParseFromIstream(&read_f);
cout << "book: " << book.DebugString() << endl;
}
}
示例11: Search
void Search(AddressBook tempbook)
{
string tempfirst;
string templast;
Contact* tempcontact;
cout << "Please enter the first name: ";
cin >> tempfirst;
cout << endl;
cout << "Please enter the last name: ";
cin >> templast;
cout << endl;
tempbook.findContact(tempfirst,templast);
tempcontact=NULL;
}
示例12: ListPeople
//Iterates through all people in the AddressBook and prints info about them
void ListPeople(const AddressBook& address_book)
{
for(int i=0; i < address_book.person_size(); i++)
{
const Person& person = address_book.person(i);
cout << "Person ID: " << person.id() << endl;
cout << " Name: " << person.name() << endl;
if(person.has_email())
{
cout << " E-mail address: " << person.email() << endl;
}
for(int j=0; j < person.phone_size(); j++)
{
const Person::PhoneNumber& phone_number = person.phone(j);
switch(phone_number.type())
{
case Person::MOBILE:
cout << " Mobile phone #: ";
break;
case Person::HOME:
cout << " Home phone #: ";
break;
case Person::WORK:
cout << " Work phone #: ";
break;
}
cout << phone_number.number() << endl;
}
}
}
示例13: main
int main () {
AddressBook book;
book.add(Contact("John", "Doe"));
book.add(Contact("Gerald", "Weiss"));
bool value = book.checker(Contact("Gerald", "Weiss"));
bool value1 = book.checker(Contact("Jeffrey", "Dover"));
book.print();
cout << "If value is 1 then Gerald Weiss exists else it does not. Value is " << value << endl;
cout << "If value is 1 then Jeffrey Dover exists else, it does not. Value is " << value1 << endl;
return 0;
}
示例14: AddToBook
void AddToBook(AddressBook& tempbook)
{
string firsttemp;
string lasttemp;
string emailtemp;
cout << endl;
cout << "Please enter contact's first name: ";
cin >> firsttemp;
cout << endl;
cout << "Please enter contact's last name: ";
cin >> lasttemp;
cout << endl;
cout << "Please enter contact's email address: ";
cin >> emailtemp;
cout << endl;
Contact tempcontact(firsttemp,lasttemp,emailtemp);
tempbook.addContact(tempcontact);
cout << "Contact added" << endl;
}
示例15: handleInput
/****************************************************************
*
* Description: The main hander function for the phonebook. Notice
* the book is defined here (as a static value).
*
*
* Pre: none
*
* Post: Handles the input based on the value of c.
*
***************************************************************/
bool handleInput( char c ) {
static AddressBook book; // the phone book
string nameBuffer;
string phoneBuffer;
bool retval = true; // return value (false if quit)
switch( c ) {
// case A = Add entry to the phone book
case 'A':
case 'a':
cout << "Name : ";
cin >> nameBuffer;
cout << "\nNumber: ";
cin >> phoneBuffer;
book.addEntry(nameBuffer, phoneBuffer);
cout << "\nNew entry: <" << nameBuffer << "," << phoneBuffer << ">" << endl;
break;
// case D = Delete item from the phone book
case 'D':
case 'd':
cout << "Name to delete: ";
cin >> nameBuffer;
book.removeEntry( nameBuffer );
cout << "\n";
break;
// case Q = Quit
case 'Q':
case 'q':
cout << "Quit" << endl;
retval = false;
break;
// case F = Find an entry
case 'F':
case 'f':
{
cout << "Find: ";
cin >> searchString;
cout << "\n";
/**
* TODO:
*
* We ant to search for all the elements that matches some criterial specified
* by a lamda function that you pass in from here.
*
* As an example, you may return true from your lamnda function if you find parial match
* on either the name or the phone number (although, you decide what the search criteria should be
*
* Assuming you have already implemented the find function on the AddressBook,
* you should be able to write some code similar to this (IN PSEUDO CODE):
*
* list<pair<string,string> > result = book.find( YOUR_LAMBDA_FUNCTION);
* if ( result.empty() ) {
* cout << nameBuffer << " not found" << endl;
* } else {
* for( auto entry : result ) {
* cout << "Name / number : " << entry.first << " / " << entry.second << endl;
* }
* }
}
break;
// case L = List entries in the phone book
case 'L':
case 'l':
book.listEntries(cout);
break;
// default prints help
default:
cout << "Commands are:" << endl <<
"A -> Add entry" << endl <<
"D -> Delete entry" << endl <<
"F -> Find entry" << endl <<
"L -> List" << endl <<
"Q -> Quit" << endl;
break;
}
return retval;
}
/****************************************************************
*
* Description: main for the address book example
*
* Pre: none
//.........这里部分代码省略.........