Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2010, 02:03 PM
Authorized User
 
Join Date: Feb 2010
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.
 
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
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.





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 04:57 AM
Exercise Solution jgrat BOOK: Beginning Access VBA 3 October 18th, 2004 04:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.