Errata—Computing Fundamentals with C++, first printing

 

The author’s web page for this textbook is http://www.cs.arizona.edu/people/mercer/compfun2/

 

Chapter 2

 

page 63  First dialogue in Project 2H has changed in the following way:

Wholesale price = 133.333

 

page 63  Second dialogue in Project 2H has changed in the following way:

Wholesale price = 100

 

Chapter 3

 

page 84  The seventh line in the code should be changed to the following:

  int totalMinutes, minutes, hours;

 

Chapter 4

 

page 126                Class diagram for grid should include a putDown() member function

 

page 133                Object-Oriented program in Figure 4.2 has changed in the following way:

  eighty8()     should be      ninety()

  hundred()     should be      ninety9()

 

page 144                Second grid in Project 4J should be changed to the following:

. . . . . . . . . . . . . . . . . . . . . . .

. .       .       .       .       .       . .

      #       #       #       #       #   > .

. . . . . . . . . . . . . . . . . . . . . . .


 


Chapter 5

 

page 159                The ninth line in the code in Self-Check 5-8 should be changed to the following:

void f2(double c)

 

page 159                The third line from the bottom in the code in Self-Check 5-8 should be changed to the following:

  int e;

 

page 166                The first line of code under the first bullet should be changed to the following:

double f2(double x)

 

page 168                The second and third lines of code in Project 5D should be deleted so that the beginning looks like the following:

#include "grid"     // For the grid class

grid moveThree(grid g)

 

page 169                The second and third lines of code in Project 5E should be deleted so that the beginning looks like the following:

#include "grid"     // For the grid class

grid blockThree(grid g)

 

page 169                The last line of code on the page should be changed to the following:

  cout << round(9.999999, 4) << endl;    // 10

 

Chapter 6

 

page 205                The class definition should be changed to the following:

class room {

public:

//--constructors

  room();

  room(string initName);

//--modifiers

  void set_desiredTemp(int newTemp);

//--accessors

  int get_desiredTemp() const;

  // post: Return des. temp. setting

  int get_actualTemp() const;

  // post: Return current room temp.

  int isOccupied() const;

  // post: Return 1 if someone is in the room and 0 if no one is present

private:

  string my_roomName;

  int my_desiredTempSetting;

  actualTempDevice my_actDev;

  desiredTempDevice my_desDev;

  occupancySensorDevice my_occDev;

};

 

page 205                The second and third lines in the class diagram should be changed to the following:

int get_desiredTemp()

int get_actualTemp()

 

page 206                Exercise 8 should be changed to the following:

Set the desired temperature to 70 degrees Fahrenheit in the kitchen.

 

page 206                In Exercises 9 and 10, room should be kitchen

 

page 206                In class definition and class diagram, dispenseCash() should be dispenseCash(int)

 

page 220                Sentence in the middle of the page should be changed to the following:

On the other hand, the attempt to send nonconst messages such as grid::move results in a compiletime error like these (more cryptic errors exist):

 

page 226                Exercises 29 and 30 should be deleted

 

Chapter 7

 

page 256                The code in the middle of the page should be changed to the following:

int main()

{ // Test drive the "safe" bankAccount::withdraw

  bankAccount aSafeAccount("Krista Guido", 50.00);

  double withdrawalAmount;

 

page 263                In the code for Project 7C, the following line should be inserted between lines 2 and 3 at the top of the page:

#include <cmath>

 

page 263                In the code for Project 7C, line 14 should be changed to the following:

  cout << "Enter a, b, and c like this:  1.0  0.0  -1.0 ";

 

page 266                The eighth line of code in Project 7G should be changed to the following:

  libraryBook aBook("The Mythical Man Month", "Fred Brooks");

 

page 267                The first line of code for Step 1 in Project 7H should be changed to the following:

bankAccount anAcct("Larry", 200.00);

 

page 268                The ninth line of code for Step 4 in Project 7H should be changed to the following:

  bankAccount anAcct("Larry", 200.00);

 

page 269                The following line should be inserted before the last line of code at the bottom of the page:

  return 0;

 

page 282                The two sets of output under Exercise 16 on this page should be labeled a. and d.

 

page 283                The two sets of output on the left at the top of the page should be labeled b. and c., so that it looks like the following:

b.   ......                    e.   ......

c.   ......                    f.    ......

 

page 283                Exercise 19 should be changed to the following:

Write a function that returns the smallest of three numbers. Develop a test plan to completely test your program.

 

page 290                The fifth line of code on this page for Project 7M should be the following:

  // post: Initialize a student object with a name as "?name?", 0.0 credits,

 

page 290                The ninth line of code on this page for Project 7M should be the following:

  //       student("Delaisio, Donna", 30.0, 120.0);

 

page 291                In the code at the top of the page, the two double statements should be in reverse order

 

Chapter 8

 

page 318                The following should be inserted before the last line of code at the top of the page:

  return 0;

 

page 323                The code for Exercise 6b should be changed to the following:

j = 1;

while(j <= 7)

{

  cout << "Hello";

  j++;

}

 

page 323                Exercise 7 should be changed to the following:

Write a while loop that produces this output:

 

page 323                Exercise 8 should be changed to the following:

Write a while loop that displays 100, 95, . . ., 5, 0 on separate lines.

 

page 328                The output for Project 8D should be formatted like the following:

                 Annual      Monthly        Daily

FutureValue:    1060.00      1061.68      1061.83

 

page 341                The end of the code for Project 8J should be changed to the following:

   X        2^X

  ==     ======

   4       16.0

   5       32.0

   6       64.0

   7      128.0

   8      256.0

   9      512.0

  10     1024.0

 

Chapter 9

 

page 360                The last sentence under Tip 3 should be changed to the following:

In this case, you will need an extra getline to get beyond the end of the line.

 

Chapter 10

 

page 365                The seventh line of the code at the top of the page should be changed to the following:

   // assert: myFriends has capacity to store 20 strings

 

page 367                The sixth line of code at the top of the page should be changed to the following:

  cout << "x[" << j << "]: ";

 

page 371                The following should be inserted after the first line of code:

#include <iostream>

 

page 378                The line of code in the middle of the page should be changed to the following:

account[0] = bankAccount("Hall", 0.00);

 

page 378                The last five lines of code on this page should be changed to the following:

account[0] = bankAccount("Hall", 0.00);

account[1] = bankAccount("Small", 100.00);

account[2] = bankAccount("Ewall", 200.00);

account[3] = bankAccount("Westphall", 300.00);

// assert: The first n elements of account are initialized

 

page 387                The following should be inserted after the first line of code in Exercise 1:

using namespace std;

 

page 388                The following should be inserted at the top of the code in Exercise 6:

#include <iostream>

 

page 391                Exericses 15 and 16 should be changed to the following:

Which line(s) contain compiletime errors?

 

page 397                The output at the top of the page should be changed to the following:

Hall      100.00

Solly      53.45

Kirstein  999.99

  . . .

Pantone  8790.56

Brendle     0.00

Kentish  1234.56

 

page 397                The output at the end of Project 10D should be changed to the following:

Balance >= 1000.00:

Pantone:   8790.56

Kentish:   1234.56

 

Balance  <  100.00:

Solly:       53.45

Brendle:      0.00

 

page 403                The fourth line of code from the top of the page should be changed to the following:

   vector<vectorElementType> test;    // Default vector capacity is 0

 

page 405                The seven str lines at the top of the pages should have a ; placed at the end of them, like the following:

str[0] = "ABE";   // first == 0

str[1] = "CLAY";

 

page 410                The nine str lines in Exercise 19 should have a ; placed at the end of them, like the following:

str[0] = "ABE";

str[1] = "CLAY";

 

page 410                The 14th line of code in Exercise 19 should be deleted, so that the program looks like the following:

int first = 0;

int last = 8;

int mid;

string searchString("CLAY");

 

Chapter 11

 

page 433                The code on this page for Project 11E should be changed to the following:

// File name: test11e.cpp

#include <iostream>

using namespace std;

 

typedef int SET_ELEMENT_TYPE;

#include "set"  // Includes set.h and set.cpp

 

int main()

{ // Test drive the set class

  set aSet;

  aSet.remove(99);  // Try to remove an element

  cout << "size: " << aSet.size() << endl;

  cout << "capacity: " << aSet.capacity() << endl;

 

  aSet.add(7);

  aSet.add(9);

 

page 434                The output for Project 11E should be changed to the following:

size: 0

capacity: 16

size: 3

capacity: 16

The set: 9, 10, 8

 

Chapter 12

 

page 473                The text under Project 12A should be changed to the following:

First read the notes above. The bank teller application allows valid bank customers access to their own bank accounts through their customer numbers. Once a customer swipes the bank card and enters the personal identification number (PIN), the user, with the help of a teller, may complete any of the following transactions: withdraw money, deposit money, and query account balance. Customers may also see their own collection of transactions. The system must maintain the correct balances for all accounts and also log each and every successful transaction.

 

page 473                The last paragraph on the page should be changed to the following:

An administrator is needed to activate new mailboxes and deactivate active mailboxes.

 

page 474                Project 12D should be deleted

 

Chapter 13

 

page 484                In the code, the third line should not end in a semicolon, like the following:

    theCdCollection.next())

 

page 486                The line of code eighth from the bottom of the page should be changed to the following:

for( theCDs.first(); ! theCDs.isDone(); theCDs.next() )

 

Chapter 14

 

page 522                The tenth line of code should be changed to the following:

  double n1 = 99.9;

 

Chapter 15

 

page 567                The text in orange in the figure should be changed to the following:

"The source's memory"

 

page 570                The paragraph at the top of the page should be changed to the following:

The action of the copy constructor guarantees that the destructor does not delete two pointers to the same memory. This is accomplished for the withDestructor class by the allocation of new memory for the pointer data member my_chars.

 

page 570                The code at the top of the page should be changed to the following:

withDestructor::withDestructor(const withDestructor & source)

{ // This copy constructor allocates new memory for my_chars . . .

  my_chars = new char[strlen(source.s) + 1];

  // . . . and then copies all characters into the new memory

  strcpy(my_chars, source.s);

  // This is different from s = source.s; which only copies an address and leaves two pointer data

  // members pointing to the same memory

}

 

page 570                The first line of code in the middle of the page should be changed to the following:

string::string(const char* source)

 

page 578                The title of the figure should be the following:

An Empty List with a Dummy node

 

page 582                The last lines of code at the bottom of the page should be changed to the following:

  { // Take out the element

    prev->structs_next = current->structs_next; // Move link around

    if(current == my_last)

       my_last = prev;

    delete current;  // Deallocate memory

    my_size--;       // Maintain current size

    return true;     // Report successful removal

  }

}

 

page 585                The fourth bankAccount line under Exercise 3 should be deleted

 

page 588                The title of Project 15A should be changed to the following:

char* toLower(char*)

 

page 588                The first line of the paragraph under Project 15A should be changed to the following:

Using pointer syntax (and not a string class), write a function called toLower that converts any char* argument into its lowercase equivalent.

 

page 589                The following line should be inserted after the first line of code under Project 15C:

#include <cstring>   // For strlen

 

page 590                The following line should be inserted after the first line of code in Project 15D:

#include <cstring>  // For strlen

 

page 590                The last four lines of code in Project 15D should be changed to the following:

  cout << subString(charPtr, 15, 15) << endl;    // Stop at end

  cout << subString(charPtr, 20, 16) << endl;    // Stop at end

  return 0;

}

 

page 590                The fourth line of output for Project 15D should be changed to the following:

pqrstuvwxyz

 

page 592                The first two sections of code at the top of the page should be changed to the following:

public:

//--constructor

 

  myArray(int initMax);

  // post: Allocate memory for initMax objects

 

page 592                The first bullet should be changed to the following:

Implement all five member functions of the myArray class. Remember to

 

page 593                The sixth line of code should be changed to the following:

void show const(myArray & arrayCopy, int n)

 

page 593                The last four lines of code should be changed to the following:

  cout << a.sub(11) << endl;      // Out-of-range error

          a.set(-1, -1.1)         // Out-of-range error

  return 0;

}

 

page 593                The last three lines of output should be changed to the following:

**Error: subscript 11 not in range 0..5. Returning first element.

1.1

**Error: subscript -1 not in range 0..5. The array is unchanged.

 

page 594                Project 15I’s title should be changed to the following:

OrderedList

 

page 594                The code for Project 15I should be changed to the following:

OrderedList::insert(const orderedListElementType & newElement)

// post: Place newElement into the list, maintaining ascending order

 

Chapter 17

 

page 672                The code for Exercise 2 should be changed to the following:

// You only need one template class

plus <int> a(2, 3);

plus <double> b(2.2, 3.3);

plus <string> c("Abe", "Lincoln");

a.show();  // 5

b.show();  // 5.5

c.show();  // AbeLincoln

 

page 674                The paragraph under Project 17B should be changed to the following:

Modify the remove member function of the bag class (stored in the file named genbag) such that it checks to see if some memory can be returned to the free store. When the current number of elements falls below one of the cut-offs (64, 128, 256, 512, 1,024, and so on), return half the current memory back to the free store.

 

Chapter 18

 

page 686                The last three lines of code should be changed to the following:

  cout << "This program may bomb!";

  return 0;

}

 

page 691                The fifth line of code should be changed to the following:

#include "ltcomplx"  // For an author-supplied complex class

 

page 695                The third line of code in the middle of the page should be changed to the following:

#include "ltcomplx"    // For a lite complex class

 

page 700                The third line of code at the bottom of the page should be changed to the following:

#include "ltcomplx"

 

page 709                The title of Project 18A should be changed to the following:

Overload < and != for track Objects

 

page 709                The ninth line of code in Project 18A should be changed to the following:

if(! (a != b));

 

page 711                The code at the bottom of the page should be changed to the following:

r1 = complex( (-b + sqrt(disc)) / (2 * a), 0.0);

r2 = complex( (-b – sqrt(disc)) / (2 * a), 0.0);

 

Chapter 19

 

page 721                The fifth line of code at the bottom of the page should be changed to the following:

  void display() const

 

page 721                The seventh line of code at the bottom of the page should be changed to the following:

  void studentStats() const

 

page 722                The second line of code at the top of the page should be changed to the following:

  double average() const

 

page 723                The first line of code in the middle of the page should be changed to the following:

quizData::quizData(string filename) const

 

page 738                The two for lines in the middle section of code should be changed to the following:

  for int(row = 0; row < lastRow; row++)

and

    for int(col = 0; col < lastCol; col++)

 

page 741                The third line of code in Exercise 9 should be changed to the following:

matrix<int> t(nRows, nCols);

 

page 743                The text for Project 19A should be changed to the following:

Implement and test quizData::average in quizdata.cpp as described on pages 726-727.

 

page 743                The text for Project 19B should be changed to the following:

Implement and test quizData::quizStats in quizdata.cpp as described on page 727.

 

page 745                The first sentence in Project 19F should be changed to the following:

A magic square is an n-by-n vector where the intergers 1 to n2 appear exactly once and the sum of the integers in every row, column, and on both diagonals is the same.