Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 20th, 2010, 02:03 PM
Authorized User
 
Join Date: Feb 2010
Location: MA
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default ch10 exercise 4 on-line solution, apparent programming error

It appears that there is a programming error in the on-line solution to the chapter 10 exercise 4 getEntry function. In the on-line solution's getEntry function, the response will be "No entry found for John Doe" only if the entered invalid person name (John Doe) is greater than the last Person in the list. Otherwise, the response wil be "The following numbers are listed for John Doe" followed by an empty line. This behavior is not what the code suggests is correct, based on the text in the two cout's.

Below is the code from the on-line solution, followed by modified code that does the intended function.

Code:
void getEntry(multimap<Person, string>& book)
{
  Person person = getPerson();
  multimap<Person, string>::iterator iter = book.lower_bound(person);
  if(iter == book.end())
    cout << "No entry found for " << person.getName() << endl;
  else
  {
    cout << "The following numbers are listed for " << person.getName() << ":" << endl;
    for(  ;  iter != book.upper_bound(person) ; iter++)
      cout << iter->second << endl;
  }
}
Code:
void getEntry(multimap<Person, string>& book)
{
  Person person = getPerson();
  multimap<Person, string>::iterator iter = book.lower_bound(person);  // refer to page 664 in book
  multimap<Person, string>::iterator iter2 = book.upper_bound(person);

//  if(iter == book.end())
  if(iter == iter2)
    cout << "No entry found for " << person.getName() << endl;
  else
	  cout << "The following numbers are listed for " << person.getName() << ":" << endl;
      for( ; iter != book.upper_bound(person); iter++)
		  cout << iter->second << endl;
}
Please comment regarding whether or not you agree, and if you have any other comments regarding this.
  #2 (permalink)  
Old July 15th, 2010, 09:16 AM
Authorized User
 
Join Date: Jan 2010
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to meteormatt Send a message via Yahoo to meteormatt Send a message via Skype™ to meteormatt
Default

Quote:
Originally Posted by fortran_ii View Post
It appears that there is a programming error in the on-line solution to the chapter 10 exercise 4 getEntry function. In the on-line solution's getEntry function, the response will be "No entry found for John Doe" only if the entered invalid person name (John Doe) is greater than the last Person in the list. Otherwise, the response wil be "The following numbers are listed for John Doe" followed by an empty line. This behavior is not what the code suggests is correct, based on the text in the two cout's.

Below is the code from the on-line solution, followed by modified code that does the intended function.

Code:
void getEntry(multimap<Person, string>& book)
{
  Person person = getPerson();
  multimap<Person, string>::iterator iter = book.lower_bound(person);
  if(iter == book.end())
    cout << "No entry found for " << person.getName() << endl;
  else
  {
    cout << "The following numbers are listed for " << person.getName() << ":" << endl;
    for(  ;  iter != book.upper_bound(person) ; iter++)
      cout << iter->second << endl;
  }
}
Code:
void getEntry(multimap<Person, string>& book)
{
  Person person = getPerson();
  multimap<Person, string>::iterator iter = book.lower_bound(person);  // refer to page 664 in book
  multimap<Person, string>::iterator iter2 = book.upper_bound(person);

//  if(iter == book.end())
  if(iter == iter2)
    cout << "No entry found for " << person.getName() << endl;
  else
      cout << "The following numbers are listed for " << person.getName() << ":" << endl;
      for( ; iter != book.upper_bound(person); iter++)
          cout << iter->second << endl;
}
Please comment regarding whether or not you agree, and if you have any other comments regarding this.
There should be no problem.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
My solution to exercise 6, on ch.2 - help rjm BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 July 28th, 2010 05:50 PM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM
exercise solution uddessjava Java Basics 1 December 29th, 2005 03:57 AM
Exercise Solution jgrat BOOK: Beginning Access VBA 3 October 18th, 2004 04:13 PM



All times are GMT -4. The time now is 09:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.