tailieunhanh - Ivor Horton’s BeginningVisual C++ 2008 phần 6

Nhập số điện thoại cho Bill Smith: 213 466 7688 nhập thành công. Chọn từ các tùy chọn sau đây: Thêm một mục D Xóa một mục nhập danh sách L Q Quit g Nhập một tên đầu tiên: Mary Nhập tên thứ hai: Miller Không thấy cho Mary Miller | Chapter 10 The Standard Template Library Enter the phone number for Bill Smith 213 466 7688 Entry successful. Choose from the following options A Add an entry D Delete an entry G Get an entry L List entries Q Quit g Enter a first name Mary Enter a second name Miller No entry found for Mary Miller Choose from the following options A Add an entry D Delete an entry G Get an entry L List entries Q Quit g Enter a first name Mary Enter a second name Jones The number for Mary Jones is 213 443 5671 Choose from the following options A Add an entry D Delete an entry G Get an entry L List entries Q Quit d Enter a first name Mary Enter a second name Jones Mary Jones erased. Choose from the following options A Add an entry D Delete an entry G Get an entry L List entries Q Quit L Jack Bateman 312 455 6576 Jane Junket 413 222 8134 Bill Smith 213 466 7688 Choose from the following options A Add an entry D Delete an entry G Get an entry L List entries Q Quit q How It Works You define a map container in main like this map Person string phonebook The object in an entry in the map is a string containing a phone number and the key is a Person object. You load up the map initially in a while loop while true cout Do you want to enter a phone book entry Y or N cin answer Ignore newline in buffer 661 Chapter 10 The Standard Template Library if toupper answer N break if toupper answer Y cout Invalid response. Try again. endl continue addEntry phonebook You check whether an entry is to be read by reading a character from the standard input stream. Reading a character from cin leaves a newline character in the buffer and this can cause problems for subsequent input. Calling ignore for cin ignores the next character so subsequent input will work properly. If n or N is entered the loop is terminated. When y or Y is entered an entry is created by calling the helper function addEntry that is coded like this void addEntry map Person string book pair Person string entry Stores a phone .