Practical C++ Programming by Steve Oualline The following are the changes made in the 6/01 printing. Here's the key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification {58} Example 4-3: floating = (1/2) + (1/2) assign floating 1.0 now reads floating = (1/2) + (1/2) assign floating 0.0. {78} first paragraph: 10010100 base 2 now reads 1001 0100 (not 1000 0100), which is 94 base 16 (not 84). (89) The sentence before the last sentence now reads: ... by putting current_number into old_number and putting next_number into current_number. {106} In the example at the bottom, the undefined variable operator was replaced with oper_char (three times). {107} Example 7-2: The filename now reads calc3.cc (not calc3.c). {111} Example 7-3: The alignment on the right side of the example has been fixed. (128) In Answer 8-1 the variable: centigrade now reads: celsius (x2) according to the Example 8-3 on page 119. {137} 1st paragraph under "Reference Parameters and Return Values": In the first line, "Chapter 4, Basic Declarations and Expressions" now reads "Chapter 5, Arrays, Qualifiers, and Reading Numbers." [138] Example 9-7: This example now reads: int &biggest(int array[], int n_elements) { int index; // Current index int biggest; // Index of the biggest element // Assume the first is the biggest biggest = 0; for (index = 1; index < n_elements; ++index) { if (array[biggest] < array[index]) biggest = index; } return (array[biggest]); } {139} The 3rd line in the first block of code now reads: biggest(item_array, 5) << '\n'; {139} The 5th paragraph now reads: The function biggest returns a reference to item_array[2]. Remember that in the following code, biggest() is item_array[2]. The following three code sections all perform equivalent operations. The actual variable, item_array[2], is used in all three: The last line of the 3rd code block now reads: biggest() = 0 Also, the last line of code on the page now reads: biggest() = 0 {143} In the first four blocks of code in the section "Default Parameters": ...(const rectangle &rectangle... now reads: ...(const int width, const int height... and: draw(big_rectangle... now reads: draw(3,5... [155] Question 10-2 now reads: 1 //Warning, spacing is very important 2 3 #include 4 5 #define MAX = 10 6 7 int main() 8 { 9 int counter; 10 11 for (counter =MAX, counter > 0; 12 --counter) 13 cout << "Hi there\n"; 14 15 return (0); 16 } (155) The text for Question 10-3 now reads: Example 10-5 computes... {157} 2nd line on page: const box pink_box(1.0, 4.5); now reads: const box pink_box(1, 4); {164} In Answer 10-4, the line: void exit(); was removed. {167-168} All of Table 11-1 now appears on page 168 so the two lists of values are not broken up. {169} In the detailed explanation after "This is because:", the value 0x41 has been placed under 0x71. It was too far left. {170} explanation for & operator: The "&" has been placed above the line. {171} explanation for | operator: The "|" has been placed above the line. {171} explanation for ^ operator: The"^" has been placed above the line. {178} code at bottom: The line: graphics[(x)/8][y] |= (0x80 >> ((x)%8)) now reads: graphics[x/8][y] |= (0x80 >> (x%8)); {179} Example 11-2: The line: graphics[(x)/8][y] |= (0x80 >> ((x)%8)) now reads: graphics[x/8][y] |= (0x80 >> (x%8)); {180-181} The sentence Finally, at the heart ... now follows the table as introduction for the programming code. {186} code at top: field-type field-name now reads: field-type field-name; (x2) {190} 1st line of code under "typedef": typedef type-declaration now reads: typedef type-declaration; {192} 2nd block of code: enum enum-name {tag-1, tag-2, . . .} variable-name now reads: enum enum-name {tag-1, tag-2, . . .} variable-name; (209) The first sentence now reads: The copy constructor... instead of: The copy operator... {262} In Example 16-3 the parentheses in the line: (cerr << "Cannot open output file\n"); were removed. {262} Example 16-3: out_file << cur_char; now reads: out_file.put(cur_char); {268} Example 16-4: Cast (unsigned int) is not necessary and it is not the recommended C++ style, so it has been removed. {283} Example 17-1, top of page: The declaration reads: int lookup(char *); The author recommends the use of variables in declarations. It now reads: int lookup(char *name); {284} Example 17-2: The line: istream &extended_getline(char *line, int size, ifstream &file) now reads: istream &extended_getline(char *line, int size, istream &file) {284} Example 17-2: At the bottom of the page the line: istream result; /* Result of gets */ now reads: istream result; /* Result of getline */ {285} Example 17-3: The line: char *extended_getline... now reads: void *extended_getline... {288} Example 17-5, top of page: 4th line now reads: ifstream playback_file... and the 9th line now reads: void *extended_getline... {307} The last sentence before "Runtime Errors" now reads: ...break 49 if point_number == 735... (not part_number). {323} 2nd line of code at top of page now reads: complex operator +(real v1, real v2); // Illegal {327} In the middle of the page the function number.set() is used, but it has not been defined yet. number.set(real, imaginary); now reads: number.set_real(real); number.set_imaginary(imaginary); {342} Answers to Chapter Questions: The following was added to the end of the section: Unfortunately, this only solves part of the problem. Now we don't call the copy constructor going into the operator = function. But when we return (*this), the return value has to be copied, so we still call the copy constructor. The solution is to return a reference to the class instead of a copy of the class. Thus our declaration of the operator = function should be: trouble &trouble::operator = (const trouble &old_trouble) { {344} In Table 19-1: 33000.0 now reads: 330000.0 {345} In "Multiplication" under item 3, the normalized result: +1.3200E+0 now reads: +1.320E+0 {347} At the top of the page the line: 1/3 as floating point is 3.333-1 now reads: 1/3 as floating point is 3.333E-1 {360} 5th line of code now reads: int data; //Data in this element {361} 1st line of code now reads: (*new_ptr).data = item {362} Example 20-2: name -- name to look for in the list now reads: value -- value to look for in the list and: int linked_list::find(char *name) now reads: int linked_list::find(int value) and: while ((strcmp(current_ptr->data, name != 0) && now reads: while (current_ptr->data == value) && (363) 2nd paragraph: The sentence: The variable after_ptr is set to point to the previous value. now reads: The variable after_ptr is set to point to the next value. {363} code: The lines: linked_list_item *before_ptr; // Insert before this element linked_list_item *after_ptr; // Insert after this element now reads: linked_list_item *before_ptr; // Insert after this element linked_list_item *after_ptr; // Insert before this element (366) In the middle of the page, the sentence: Notice that we do not have to keep track of the variable after_ptr. now reads: Notice that we do not have to keep track of the variable before_ptr. (367) The 6th paragraph now refers to Figure 20-10, not 20-11. (368) The order of the steps does not fit to the order of the steps described in the text (confusing). The indents before step 3 and 4 have been removed. (368-369) Figures 20-9 and 20-10 were switched. (369) "private:" was added to the top of class tree. (370-371) Figures 20-12 and 20-13 were switched. {372} code: result = strcmp(node->word, word); now reads: result = strcmp(node->data, word); {375} Example 20-3, middle of page: for (index = 1; index < sizeof(word); ++index) { now reads: for (index = 1; index < sizeof(word) -1; ++index) { {387} In the middle of the page, the line: b_stack::b_stack(cont unsigned ... now reads: b_stack::b_stack(const unsigned ... {389} 2nd block of code: The line: letter.send(); now reads: letter.send_it(); (Compare class mail definition on page 388). {389} 2nd paragraph: The sentence: The trouble is that letter is a mail class, so when we call letter.send() we call the send of the base class mail. now reads: The trouble is that letter is a mail class, so when we call letter.send_it() we call the send_it of the base class mail.