Example #1
0
File: write.cpp Project: skhal/Cpp
void promptForAddress(AddressBook &book)
{
    while(true)
    {
        cout << "Enter person ID number [0 to quit]: ";

        Person person;

        {
            int id;
            cin >> id;

            if (!id)
                break;

            person.setId(id);
            cin.ignore(256, '\n');
        }

        {
            cout << "Enter name: ";
            std::string name;
            getline(cin, name);

            person.setName(name);
        }

        {
            cout << "Enter email address (blank for none): ";

            string email;
            getline(cin, email);
            if (!email.empty())
                person.setEmail(email);
        }

        while(true)
        {
            cout << "Enter a phone number [Enter to finish]: ";
            string number;
            getline(cin, number);
            if (number.empty())
                break;

            Phone *phone = person.add_phone();
            phone->setNumber(number);

            cout << "Is this a mobile, home or work phone? ";
            string type;
            getline(cin, type);

            if ("mobile" == type)
                phone->setType(Phone::MOBILE);
            else if ("home" == type)
                phone->setType(Phone::HOME);
            else if ("work" == type)
                phone->setType(Phone::WORK);
            else
                cout << "Unknown phone type. Using default." << endl;
        }

        book.push_back(person);
    }
}