279 pdfsam Cplusplus Primer Plus 4th Edition

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks meth...

0 downloads 0 Views 3KB Size
This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks

methods of iostream. Just replace one header file with the other and globally replace

getchar() and putchar() with their act-alike method equivalents. (If the old code uses a type int variable for input, you have to make further adjustments if your implementation has multiple prototypes for put().)

Table 5.3. cin.get(ch) versus cin.get() Property

cin.get(ch)

ch=cin.get()

Method for conveying

Assign to argument ch

Use function return value to assign to ch

input character Function return value for

A class istream object(true after Code for character as type

character input

bool conversion)

Function return value at

A class istream object(false after EOF

end-of-file

bool conversion)

int value

Nested Loops and Two-Dimensional Arrays Earlier you saw how the for loop is a natural tool for processing arrays. Let's go a step further and look at how a for loop within a for loop (nested loops) serves to handle two-dimensional arrays. First, let's examine what a two-dimensional array is. The arrays used so far are termed one-dimensional arrays because you can visualize each array as a single row of data. You can visualize a two-dimensional array as being more like a table, having both rows and columns of data. You can use a two-dimensional array, for example, to represent quarterly sales figures for six separate districts, with one row of data for each district. Or, you can use a two-dimensional array to represent the position of RoboDork on a computerized game board. C++ doesn't provide a special two-dimensional array type. Instead, you create an array for which each element is itself an array. For example, suppose you want to store maximum temperature data for five cities over a four-year period. In that case, you can declare an array as follows:

int maxtemps[4][5]; This declaration means that maxtemps is an array with four elements. Each of these