Index
Symbols
! (NOT) logical operator, 208, 452
! = (not equal to) relational operator, 186
# (pound sign), 114
#def i ne directive, 94, 120-128
#i ncl ude directive, 61, 107, 115-120
%(modulus) math operator, 164, 167-168
%= (compound operator), 177
& (address of) pointer operator, 542
& (ampersand), 155, 391
&& (AND) logical operator, 208 ( ) (parentheses), 46, 336, 365 “ ” (double quotation marks),
85, 117
‘ ’ (quotation marks), 89
, comma operator, 232-234, 758
* (asterisks), 345
-
(dereferencing) pointer opera- tor, 542
-
(multiplication) math operator, 64, 164
*= (compound operator), 177
+ (addition) math operator, 64, 164
++ (increment) operator, 225
+= (compound operator), 177
- (hyphen), 336
– (subtraction) math operator, 64, 164
-- (decrement) operator, 225
- = (compound operator), 177
. (dot) operator, 592, 608, 616
/ (division) math operator, 64, 164, 167-168
// (slashes), 46
/ = (compound operator), 177
: (colon), 321
; (semicolon), 56, 114, 120, 190,
339
Index ♦
< (input redirection symbol), 435
< (less than) relational operators, 186
< > (angled brackets), 117
<= (less than or equal to) rela- tional operator, 186
= (assignment operator), 63, 174-178
= (equal sign), 80, 105, 400
== (equal to) relational operator, 186
-
(greater than) relational opera- tor, 186
-
(output redirection symbol), 435
>= (greater than or equal to) relational operator, 186
[ ] (brackets), 46, 100, 523
\ (backslash), 91
\ n (newline character), 91, 135-136, 433, 635
\t (tab character), 138, 433
_ (underscore), 336
{ } (braces), 46, 56, 340
functions, 336
initializing arrays, 527
|| (OR) logical operator, 208
~Spher e( ) function, 663-670 2's complement, 692, 760
A
absolute values, 420-421, 461 access modes
random file, 648
read, 639 accessing
disks, 625
elements (arrays), 101
files, 627-628
modes, 630
random access, 627
sequential file access, 625-627
text mode, 630
members, classes, 675
RAM, 627
adapters, display, 24, 751 addition (+) math operator, 64,
164
address of (&) pointer operator, 542
addresses, 32, 559
& (address of) pointer opera- tor, 542
arrays, passing, 386 integers, assigning floating-
point variables, 549
memory, 385, 681-682, 747
passing
nonarrays, 391-396
variables, 374, 385-394, 756
pointers, 542
addressing, 679
Algol programming language, 15 allocating memory, dynamic
allocation, 665
alphabetic testing functions, 450-451
Alt keys, 25
American National Standards Insitute (ANSI), 13, 747
American Standard Code for Information Interchange, see ASCII
ampersand (&), 155, 391
analog signals, 29
AND (&&) logical operator, 208 angled brackets (< >), 117 ANSI (American National
Standards Institute), 747 appending
cout operator, 93 files, 628, 638-639
application-specific keys, 27
762
C++ By
EXAMPLE
arguments, 747
alphabetical, testing for, 451 default
lists, 415-417, 750
multiple, 417-420
member functions, 670-674
mismatched, 407 numeric, testing for, 451 passing, 364-366
receiving, 550
see also variables arithmetic
binary, 690-692
pointers, 568-574
arrays, 100, 474-479, 747
as si zeof argument, 231 assigning to arrays, 486 brackets ([ ] ), printing, 102 character pointers, 574 character, see character arrays contents, changing, 563
data types, mixing, 609 declaring, 100, 475
strings, 478
subscripts, 482 defining, data type, 475 elements, 101, 751
accessing, 101
initializing all to zero, 481 inputting to, 611
subscripts, 101-102 filling
random values, 497
user input, 389 global, see global arrays
individual characters, 105
initializing, 104-105, 479-490
assignment operator, 480 braces ({ } ), 527
brackets [ ] , 480 multidimensional, 529
mapping to memory, 524-526 members, 615-622
multidimensional, see multidi- mensional arrays
names
as pointers, 558-559
changing, 560
notation, 608-610
parallel, 756
passing, 388
by address, 386
functions, 387
to functions, 484
(of) pointers, 551-553
pointers, 493
printing with cout operator, 102
ragged-edge, 574
referencing, 508-515, 558
reserving memory, 476
searching, 494-495
f or statement, 496 for values, 496-501 i f statement, 496
sizes, 128, 476-477, 480
sorting, 494-495, 501-508, 758
ascending sort, 506
bubble sort, 502-505, 748
character arrays, 508
descending sort, 494, 506
nested loops, 504
numeric arrays, 508
quicksort, 502, 757
shell sort, 502, 758
(of) strings, 574-578 strings
printing, 563
storing, 574
(of) structures, 589, 747
structures, declaring, 606-615
subscripts, 474
two-dimensional, 525
type, specifying, 390
values, assigning, 103
see also nonarrays
763
Index ♦
arrow keys, 27
ascending sort, 506
ASCII (American Std. Code for Information Interchange), 747
characters, 683
returning, 409
files, 747
text files, 115, 630
values, printing, 154
ASCII Table, 719, 722-727
ascii ( ) function, 409 assigning
arrays to arrays, 486 floating-point variables, 549 literals
character, 89-93
integer, 83-84
string, 85
string values to character arrays, 105
values
arrays, 103
elements, 479
members, 602
out-of-range subscripts, 479
strings, 107
to pointers, 545-546
to variables, 145
variables, 80-82 assignment operator (=), 63,
174-178, 480
assignment statements, 80, 105
pointers, initializing, 548
start expressions, 274 assignments
associating, 175-176
compound, 176-178
multiple, 175-176
statements, 174-178
associating assignments, 175-176 asterisks (* ), 345
AT & T, 12
at of ( ) function, 460 at oi ( ) function, 460 at ol ( ) function, 460 aut o keyword, 369
AUTOEXEC.BAT file, 747
automatic variables, 369-374, 747
B
backslash (\ ), 91 backup files, 748
base-2 numbers, 686
base-10 numbers, 689
base-16 numbers, 695
BCPL programming language, 15 BEEP, 314
binary
arithmetic, 690-692
digits, 683, 748
file format, 631
modes, 631
operations, 165
states of electricity, 21 zeros, 88, 748
binary numbers, 17, 165, 679,
686-690, 748
converting
from hexadecimal numbers, 697
to 2's complement, 692 to hexadecimal, 697
negative, 692-694
binary state of electricity, 683 bit mask, 240, 748
bits, 682-685, 748
high-order, 686
least-significant, 686, 753
low-order, 686
most-significant, 686
order, 686
sign, 693
bitwise operators, 235-244, 748
truth tables, 235-236
764
C++ By
EXAMPLE
blank
characters, 680
expressions, see null expres- sion
lines, 136
blocks, 55
braces ({ } ), 56
case, break statements, 312 statements, 246, 748
body (program) functions, 336, 345
loops, indenting, 279
statements, 189, 342
boilerplates, 117
booting, 748
braces ({ } ), 46, 56-57, 340
functions, 336
initializing arrays, 527
loops, 287
brackets ([ ] ), 46, 100 angled (< >), 117 arrays, initializing, 480
dimensions, 523
printing arrays, 102
branching, 321
br eak statement, 256-260, 298-303
case blocks, 312
nested loops, 299
unconditional, 299
breaks, conditional, 257-258 bubble sort, see sorting arrays buffered input functions, 440-442 bugs, see debugging
built-in editors, 40
built-in functions, prototypes, 734-735
bytes, 20, 682-685, 748
K (kilobytes), 20, 753
M (megabytes), 24, 754
reserving, arrays, 476
C
C++
comparing to other languages, 16
origination, 15-16 calculations
data types, mixing, 178-182 strings, 460
structure members, 597
called functions, 364
recognizing, 368-369
return values, 398
variables, changing, 387
calling functions, 337-349
repeatedly, 417
carriage returns, 439
case blocks, br eak statements, 312
case expressions, 312
case statements, 313, 319
cathode ray tube (CRT), 24, 748
ceil ( x) function, 461 ceiling function, 461
central processing unit (CPU), 20-22, 748
cf r ont (UNIX) compiler, 43 CGA display adapter, 24 character arrays, 100-103
cont r ol _st r i ng , 149
erasing, passing to functions, 390
filenames, storing, 633
initializing, 480
pointing, to new strings, 563 reserving, 100, 480
sorting, 508
string values, assigning, 105 strings
comparing, 103-110
multiple, 512
printing, 135, 510
storing, 104
765
Index ♦
character formatting constants, defining, 440
character functions, 450-455
conversion, 453-455
t ol ower( c) , 454
t oupper( c) , 454
i sal num( c) , 451 i sal pha( c) , 450 i sdi gi t ( c) , 451 i sl ower( c) , 450 i supper( c) , 450
i sxdi gi t ( c) , 451 passing to, 451
testing, 450-453
for digits, 451
i scnt r l ( c) , 453
i sgr aphi c( c) , 453
i spr i nt ( c) , 453 i spunct ( c) , 453 i sspace( c) , 453
character I/ O functions, 432-446 character literals, 64, 89-93
character pointers, 563-568 arrays
defining, 574
storing, 574
filenames, 633
string constants, changing, 566 character strings, variables, 100 character variables, 75
character-based literals, 62 characters
\t (tab), 138
ASCII, 683, 409
comparing, 199
conversion, 151-154
individual, arrays, 105 newli ne ( \ n) , 135-136 string-terminating, 101,
457-458
ci n , 144-148, 248-249
input, keyboard, 144
values, variables, 145
classes, 661-670, 749
functions, defining, 754
member functions, 662-676 members
accessing, 675
data, 662
private, 674, 757
public, 757
visibility, 674-675
objects, 663
public, 662, 674
cl ose( ) function, 629 closing files, 629-634
code, 749
modules, see functions object, 755
source, see source code spaghetti, 759
unreachable, 305 colon (: ), 321
columns, printing, 139-140, 534 combining functions, cout and
of st r eam , 437
combining redirection symbols, 436
comma (, ) operator, 232-234, 758
comments, 46, 57-61, 749 comparing
characters, 199
data, relational operators, 186 internal data, bit-by-bit, 235 literals to variables, 192 loops, i f vs. whil e , 255 numbers, 199
variables, 192 compatibility,
AT & T, 12
with other computers, 433 compile-time operator, 231
compiled languages, 37
compilers, 37, 42-44
C++, 11
cf r ont (UNIX), 43
766
C++ By
EXAMPLE
compiling, 43, 113, 749
compound assignments, 176-178
compound operators, 177 compound relational operators,
see logical operators compound relational tests, 207 computers
digital, 29, 750
microcomputers, 754
personal (PCs), 757
see also microcomputers concatenation, 456, 749
conditional breaks, 257-258
conditional loops, 749
conditional operators, 222-225 CONFIG.SYS file, FI LES= state-
ment, 629
console, 434
const keyword, 94, 120, 749
constant variables, 94-95
constants, 94, 749, 759 defining
character formatting, 440
variables as, 120
numeric, printing, 151
pointers, 560-562 string
changing, 566
printing, 150
see also literals and pointer constants
construct statements, 246
constructor functions, 663, 749
multiple, 673
overloading, 673
constructs, loops, 276
cont i nue statement, 303-307 control characters, I/ O functions,
433
control operators, 139-144
cont r ol _st r i ng , 149, 155
controlling
format string, 149
function calls, 338
statements conditionally, 185
conversion characters, 151-154
floating-point, 151
functions, 453-455
for printing, 297
set w manipulator, 140 converting
binary numbers
to 2's complement, 692 to hexadecimal, 697
data types automatically, 179 hexadecimal numbers to
binary numbers, 697 strings to numbers, 460-461
to floating-point number, 460
to integers, 460
to uppercase, 240
copy, passing by, 379, 547, 756 copying
literals, in strings, 107 members, structure variables,
598
cos( x) function, 464 count expressions
increments, 281
loops, 274, 278
counter variables, 262, 265, 360
nested loops, 288
counters, 260-268
cout , 65, 85
\ n , 91 appending, 93
combining with of st r eam , 437 format, 134
labeling output, 136
literals, printing, 83 printing
arrays, 102
strings, 134-144
767
Index ♦
CPU (central processing unit), 20-22, 748
creating files, 628, 648 CRT (cathode-ray tube), 24 Ctrl keys, 25
ctype.h header file, 450, 734 cube( ) function, 674 cursor, 24, 27
D
data
hiding, 675
passive, 663
data comparison, 186
data members, 662, 749
data processing, 29
data types, 75-79 arrays
defining, 475
mixing, 609
casting, 179-182
converting automatically, 179
i nt , 400 members, 584
mixing, 82
in calculations, 178-182
variables, 179
pointers, 542
values, truncating, 179
variables, 72-73
weak, 16
data validation, 195, 749
data-driven programs, 185
debugging, 47, 748-749
decision statements, 189
declaring, 750
arrays, 100, 475
of pointers, 551
strings, 478
of structures, 606-615
subscripts, 482
automatic local variables, 369
elements and initializing, 479-486
global variables, 358
pointers, 543-545
file, 632
global, 542
local, 542
while initializing, 545
statements, 101
structures, 591
types, parameters, 366
variables, 62, 73
signed prefix, 166
static, 370
decrement (-- ) operator, 225, 233 decrementing
expressions, 228
pointers, 568
variables, 225-230, 282 default argument list, 415-420,
750
default line, switch statement, 312
defaults, 750
defined literals, 121
arrays, sizes, 128
replacing, 126
variables, 122 defining
arrays
character pointers, 574
data types, 475
of structures, 589 constants, character format-
ting, 440
floating-point literals, 127
functions, 340, 365
in classes, 754
in functions, 341
literals, 365
structures, 587-591
globally, 595
nested, 602
768
C++ By
EXAMPLE
variables, 365
after opening brace, 355 as constants, 120
outside functions, 355
structure, 595
definition line, 406, 750
Del key, 27
delay value, 296
delimiters, strings, 88, 759
demodulated signals, 29, 750 dereferencing (* ) pointer opera-
tor, 542, 750
descending sort, 494, 506
see also sorting arrays designating literals
floating-point, 79
long, 79
unsigned, 79
designing programs, 38-39
destructor function, 665, 750
determinate loops, 750 devices
default, overriding, 436
flushing, 458
get ( ) function, 438 I/ O (standard), 434 input, standard, 759
output, 134, 756, 759 redirecting from MS-DOS,
435-436
standard, 434
digital computer, 29, 750 digital testing, functions, 451 digits
binary, 683
testing for, character func- tions, 451
dimensions, designating with braces ({ } ), 523, 527
directives, 757 #def i ne , 94 #i ncl ude , 61
directories, 750
paths, 756
subdirectories, 750
disk drives, 23, 750
disk operating system (DOS), 751 diskettes, see floppy disks
disks, 22-24, 626-627, 750
files
accessing, 625-628
appending, 628
creating, 628
opening/ closing, 629-634 fixed, see hard disks
floppy, see floppy disks formatting, 23, 752 hard, see hard disks measurements, 680-681
sectors, 758
size, 24
tracks, 23, 760
disk drives, 23
see also hard disks display adapters, 24, 751
CGA, 24
EGA, 24
MCGA, 24
VGA, 24
see also monitors; screens displaying error messages,
nested loops, 296
division (/ ) math operator, 64, 164, 167-168
do- whil e loop, 252-255
DOS (disk operating system), 30-32, 751
dot (. ) operator, 592, 608, 616
dot-matrix printer, 25, 751, 753
double subscripts, 616
dynamic memory allocation, 665
769
Index ♦
E
EDIT editor, 41
editing, linking, 753
editors, 37-42
built-in, 40
EDIT, 41
EDLIN, 41
ISPF, 42
EGA display adapters, 24 electricity (states), 21, 683
elements (arrays), 101, 751
accessing, 101
assigning values, 479
initializing, 486-492 all to zero, 481
at declaration time, 479-486
inputting, 611
members, 584
referencing with subscripts, 476
reserving, 103
space between, 476
storing, 476
subscripts, 101-102, 474 elements (pointers),
dereferencing, 576
el se statement, 198-203 embedding functions, 668
endless loops, 323 environments
integrated, 40-41
variables, 256
equal sign (=), 80, 105, 400
equal to (==) relational operator, 186
equality testing, 187 erasing character arrays by
passing to functions, 390 error messages, 46-48
displaying, nested loops, 296 illegal initialization, 102
syntax, 46
escape key, 25
escape-sequence characters, 91-92
executable files, 42
executing, 751
functions repeatedly, 347 programs
falling through, 312
stopping, manually, 250
see also running programs
exi t ( ) function, 256-260 isolating, 256
stdlib.h header file, 256 exiting
conditional breaks, 257-258
loops, 256-260, 303
exp( x) function, 465 expanded memory, 21, 751
see also extended memory expressions
case, 312
count, 274
increments, 281
loops, 278
incrementing/ decrementing, 228
loops
start, 278
test, 275, 283
nonconditional, 190
null, 285
start, 274
swi t ch statement, 312 test, 274
parentheses, 246
extended memory, 21, 681, 751 see also expanded memory extensions (filenames), 42, 751
external functions, 117
external memory, 22
external modem, 28, 751
770
C++ By
EXAMPLE
F
f abs( x) function, 461 factorial, 290
ff l ush( ) function, 458 f get s( ) function, 457 fields, 751
file pointers, 631, 650
declaring globally, 632
positioning, 650-656 f il e_pt r pointer, 629 filenames, 751
#i ncl ude directive, 115 character pointers, 633
conventions, 43
extensions, 42, 751
recommended, 43
storing character arrays, 633 files, 751
accessing, 627-628
modes, 630, 639, 648
random access, 627 sequential file access,
625-627
text mode, 630
appending, 628, 638-639
ASCII, 630, 747
AUTOEXEC.BAT, 747
backup, 748
CONFIG.SYS, FI LES= state-
ment, 629
creating, 648
directories, 750
disk, creating, 628
executable, 42
formats, binary, 631 header, see header files include, order, 118
opening/ closing, 629-634, 647
pointing, 629
random, see random files random-access, 628, 757
reading, 639-642
reading to specific points, 649-656
records, 635, 758
fields, 646
fixed-length, 647
sequential, 627-629, 758
string.h, 107
writing to, 634-637
FI LES= statement, 629
f ill _st r uct s( ) function, 597 filling arrays
random values, 497
user input, 389
fixed disks, see hard disks fixed-length records, 647, 751 floating-point
conversion characters, 151
literals, 79
defining, 127
designating, 79
numbers, 63, 76
converting to, 460
printing, 140
value, 138
variables, 100, 142 assigning to integer
addresses, 549
printing, 152
f l oor( x) mathematical function, 462
floppy disks, 22, 750-751
flushing devices, 458
f mod( x, y) function, 462
f or loops, 273-286 body, 279 expressions
count, 274
start, 274
test, 274
nested, 286-291
tables, multidimensional, 530-537
771
Index ♦
f or statement, 274, 290, 298-303,
496
format statements, assignment, 80
formats
#i ncl ude directive, 115 conditional operator, 222 cout , 134
files, binary, 631
programs, 53-54
multiple-function, 338
strings (controlling), 149 formatted output, printing,
436-437
formatting disks, 23, 752
output, 437-446
formulas, subscripts, referencing elements, 476
f put s( s, dev) function, 457 fractions, rounding, 140
function calls, 332, 337-339
controlling, 338 increment/ decrement
operators, 233
invocation, 339
nested, 402
return values, 401
tracing, 340
function invocation, 339
function keys, 27, 752
function-calling statements, 337
functions, 331-332, 752
{ } (braces), 336
~Spher e( ) , 663-670 arrays
filling with user input, 389 passing, 387
ascii ( ) , 409 at of ( ) , 460 at oi ( ) , 460 at ol ( ) , 460
body, 336, 345
buffered/ nonbuffered, 444
built-in, prototypes, 734-735 called, changing variables, 387 calling, 337-349, 364
recognizing, 368-369
repeatedly, 417
character, 450-455
conversion, 453-455
i sal num( c) , 451 i sal pha( c) , 450 i scnt r l ( c) , 453 i sdi gi t ( c) , 451 i sgr aph( c) , 453 i sl ower( c) , 450 i spr i nt ( c) , 453 i spunct ( c) , 453 i sspace( c) , 453 i supper( c) , 450
i sxdi gi t ( c) , 451 passing to, 451
prototypes, 450
testing, 450, 453 testing for digits, 451 t ol ower( c) , 454
t oupper( c) , 454
character arrays, erasing, 390
ci n , 248
cl ose( ) , 629 constructor, 663, 673, 749 cube( ) , 674
defining, 340, 365
in classes, 754
in functions, 341
definition line, 406
destructor, 665, 750
embedding, 668
exi t ( ) , 256-260
isolating, 256
stdlib.h header file, 256 external, 117
ff l ush( ) , 458
f ill _st r uct s( ) , 597
772
C++ By
EXAMPLE
get ( ) , 438-444
get ch( ) , 444-446 I/ O, 656-658
character, 437-446
control characters, 433
f get s( s, l en, dev) , 457
f put s( s, dev) , 457
get s( ) , 457, 635
put s( ) , 457, 635
r ead( arr ay, count ) , 656
r emove( f il ename) , 656
wr i t e( arr ay, count ) , 656 in-line, 668-670, 752
input
buffered, 440
building, 442
mirror-image, 637
keyboard values, 392
length, 335
logarithmic, 465
exp( x) , 465
l og( x) , 465
l og10( x) , 465 main, 56
mai n( ) , 56-57, 61, 332, 335
OOP, 665
prototyping, 409
mathematical, 461-464
ceil ( x) , 461
f abs( x) , 461
f l oor( x) , 462
f mod( x, y) , 462
pow( ) , 463
pow( x, y) , 462
sqr t ( x) , 462 member, 754
arguments, 670-674
classes, 662-676
multiple execution, 347
naming, 335-337
_ (underscore), 336
name-mangling, 422
rules, 335
next _f un( ) , 338 nonbuffered, 444
numeric, 461-467, 755 of st r eam , 436-437 open( ) , 629, 648
overloading, 415, 420-425, 756
parentheses, 336, 365
passing arrays, 484
pr _msg( ) , 416
pr i nt _i t ( ) , 525
pr i ntf ( ) , 65, 126, 149-150,
191, 407
prototypes, 338, 397, 405-411 ctype.h header file, 734 math.h header file, 461, 735
self-prototyping, 406 stdio.h header file, 734 stdlib.h header file, 460, 735 string.h header file, 735
put ( ) , 438-444
put ch( ) , 444-446
r and( ) , 465-466, 497
receiving, 364, 382
redefining, 121-126
return statements, 337, 345
return values, 398-405
returning, 337-349
scanf ( ) , 126, 149, 154-157
passing variables, 546
prototyping, 407 seekg( ) , 649-656 separating, 345
set w( ) , 140
si zeof ( ) , 476-477 sort, saving, 508 Spher e( ) , 663-670 squar e( ) , 674
st r cat ( ) , 456
st r cpy( ) , 107, 408 string, 455-461
f get s( s, l en, dev) , 457
f put s( s, dev) , 457
773
Index ♦
get s( s) , 457 I/ O, 456-459
put s( s) , 457
st r cat ( s1, s2) , 456 st r cmp( s1, s2) , 456 st r l en( s1) , 456 testing, 456
st r l en( ) , 251
sur f ace_ar ea( ) , 663-670 testing
alphabetic conditions, 450-451
digits, 451
numeric arguments, 451 t hi r d_f un( ) , 338 trigonometric
cos( x) , 464 si n( x) , 464 t an( x) , 464
values, returning, 374
variables, types, 152 vol ume( ) , 663-670 writing, 332-337
see also routines
G
H
hard copy, 752
hard disks, 22, 751-752
see also disk drives hardware, 17-29, 752
disks, 22-24
indepedence, 17
memory, 20-22
modems, 28-29
monitors, 24
mouse, 28
printers, 25
system unit, 20-22
header files, 117-118, 752 ctype.h
function prototypes, 734
prototypes, 450
iomanip.h, 408
iostream.h, 117, 408 math.h
function prototypes, 735
prototypes, 461 stdio.h
function prototypes, 408,
734
pr i ntf ( ) function, 150
get ( ) function, 438-444 get ch( ) function, 444-446 get s( ) function, 457, 635
global arrays, initializing, 479 global pointers, declaring, 542 global variables, 73, 354-369, 752
declaring, 358
passing, 364
returning, 398
got o statement, 321-326 graphics monitors, 24
greater than (>) relational ope- rator, 186
greater than or equal to (>=) relational operator, 186
stdlib.h
exi t ( ) function, 256 function prototypes, 735
prototypes, 460
string.h, 118
function prototypes, 735
prototypes, 456
hexadecimals, 17, 83, 695-698, 752 converting
from binary, 697
to binary numbers, 697 hiding data, 675
hierarchy of operators, see order of precedence
high-order bit, 686 hyphen (- ), 336
774
C++ By
EXAMPLE
I
I/ O (input/ output), 753 character, 432-436
devices (standard), 434
functions, 656-658
character, 437-446
control characters, 433
f get s( s, l en, dev) , 457
f put s( s, dev) , 457
get s( ) , 635
get s( s) , 457
put s( ) , 457, 635
r ead( arr ay, count ) , 656 r emove( f il ename) , 656 strings, 456-459
wr i t e( arr ay, count ) , 656 rerouting, 434
statements, 17
stream, 432-436
strings, 457
i f loop, 189-199, 255, 496
i f tests, relational, 209 illegal initialization, 102
in-line functions, 668-670 include files, order, 118 increment (++) operator, 225, 233 incrementing
expressions, 228
pointers, 568
variables, 225-230
increments as count expressions, 281
indeterminate loops, 752
infinite loops, 246, 752
initial values of static variables, 370
initializing
arrays, 104-105, 479-490
assignment operator, 480 braces ({ } ), 527
brackets [ ] , 480 global, 479
multidimensional, 529 character arrays, reserved, 480 elements, 479-492
illegal, 102
members individually, 591 multidimensional arrays,
526-530
pointers, 545
assignment statements, 548
while declaring, 545
structures, 591
dot (. ) operator, 592 members, 591-600
variables
structures, 591
to zero, 176
inline functions, 752
input, 30, 753
arrays, filling, 389
buffered, 441-442
characters, echoing, 444
devices, standard, 759 functions
buffered, 440
building, 442
mirror-image, 637
keyboard, 435
statements, 17
st di n , 434-435 stream header, 117 terminating
f get s( ) , 457 get s( ) , 457 values, 248
input redirection symbol (<), 435 input-output-process model, 30 input/ output, see I/ O
Ins key, 27
i nt data type, 400 integer literals, 83-84
integer variables, 73, 152, 753
775
Index ♦
integers, 63
address, assigning floating- point variables, 549
converting to, 460
integrated environments, 40, 41
internal modem, 28, 753
internal truths, 210
interpreted languages, 37
iomanip.h header file, 139, 408
iostream.h header file, 117, 408
i sal num( c) function, 451 i sal pha( c) function, 450 i scnt r l ( c) function, 453 i sdi gi t ( c) function, 451 i sgr aph( c) function, 453 i sl ower( c) function, 450 ISPF editor, 42
i spr i nt ( c) function, 453 i spunct ( c) function, 453 i sspace( c) function, 453 i supper( c) function, 450
i sxdi gi t ( c) function, 451 iterations, 282, 296
J–K
justification, 140, 574-575
K (kilobytes), 680
keyboard, 25-28
Alt keys, 25
application-specific keys, 27
arrow keys, 27
Ctrl keys, 25
Del key, 27
escape key, 25
function keys, 27
input, 435
inputting, 144
Ins key, 27
numeric keypad, 27
PgDn, 27
PgUp key, 27
Shift keys, 25
values, 392
keys, function, 752
keywords, 733
aut o , 369
const , 94, 120, 749
voi d , 406
kilobytes (K), 20, 680, 753
L
labels
output, 86, 136
statement, 321-322 languages
Algol, 15
BCPL, 15
C, 13
compiled, 37
interpreted, 37
machine, 753
weakly typed, 16
laser printers, 25, 751, 753
least-significant bit, 686, 753 length
functions, 335
strings, 89, 251
less than (<) relational operators, 186
less than or equal to (<=) rela- tional operator, 186
line printer, 753
link editing, 753
linking, 43-44 lists
arguments, default, 416-417,
750
prototypes, multiple default arguments, 417
variables, 474
see also arrays
literals, 62, 82-93, 94, 103, 753, 759
character, 64, 89-93
character-based, 62 comparing to variables, 192 copying in strings, 107
776
C++ By
EXAMPLE
defined, 121, 365
replacing, 126
variables, 122 designating
floating-point, 79
long, 79
unsigned, 79
floating-point, 79, 127
integer, 83-84 numeric
defining, 127
overriding default, 79
octal, 83
printing with cout operator, 83 relational operators, 186
string
assigning, 85
defining, 127
endings, 87-89
printing, 85
suffixes, 79
local pointers, 542
local variables, 354-369, 753
automatic, 369, 747
changing, 354
defining, 355
multiple functions, 363
names, overlapping, 360
passing, 363-364
receiving functions, 368
value, losing, 355
l og( x) function, 465
l og10( x) function, 465 logarithmic functions, 465
exp( x) , 465
l og( x) , 465
l og10( x) , 465 logic, 211-215, 222
logical operators, 207-215
! (NOT), 208
&& (AND), 208
|| (OR), 208
bitwise, 235-244
order of precedence, 216 truth tables, 208
loop variables, 282
loop-counting variables, 361
looping statements, 246
loops, 247-252, 753
conditional, 749
constructs, 276 conversion characters for
printing, 297
determinate, 750 do- whil e , 252-255 endless, 323
exiting, 256-260, 303 expressions
count, 274, 278
start, 274, 278
test, 274-275, 283
f or , 273-286
body, indenting, 279 multidimensional tables,
530-537
nested, 286-291
i f (compared to whil e loop), 255
indeterminate, 752
infinite, 246, 752
nested, 755
braces, 287
br eak statement, 299 counter variables, 288 multidimensional tables,
530
sorting arrays, 504
timing loops, 296
statements, 277
timing, 295-298, 759
iterations, 296
nested loops, 296
whil e , 245, 255
low-order bit, 686
lowercase letters, 55, 122
777
Index ♦
M
M (megabytes), 681
machine language, 753 mailing list program, 737-746 main module, 753
mai n( ) function, 56-57, 61, 332,
335
OOP, 665
prototyping, 409 maintainability of programs, 174 manipulators, 754
mapping arrays to memory, 524-526
masking, 240
matching braces ({ }), 56 math hierarchy, see order of
precedence
math operators, 754
%(modulus or remainder), 164, 167-168
* (multiplication), 64, 164
+ (addition), 64, 164
- (subtraction), 64, 164
/ (division), 64, 164, 167-168 order of precendence, 168-174
math.h header file, function prototypes, 461, 735
mathematical calculations on strings, 460
mathematical functions
ceil ( x) , 461
f abs( x) , 461
f l oor( x) , 462
f mod( x, y) , 462
pow( ) , 463
pow( x, y) , 462
sqr t ( x) , 462 mathematical summation
symbol, 290
mathematics, factorial, 290 matrices, see multidimensional
arrays; tables
MCGA display adapter, 24 measurements
disks, 680-681
memory, 680-681
megabytes (M), 24, 754
member functions, 662, 754
arguments, 670-674
classes, 662-676
members, 584, 749, 754
arrays, 615-622 classes
accessing, 675
constructor functions, 663
data, 662
functions, 662
private, 674, 757
public, 757
visibility, 674-675
data types, 584
initializing individually, 591 structures
copying, 598
initializing, 591-600 values, assigning with dot
operator, 602
memory, 20-22, 680-682, 754
& (address of) pointer opera- tor, 543
addresses, 32, 385, 681-682,
747
arrays, mapping, 524-526
bytes, 680, 748
dynamic allocation, 665
expanded, 21, 751
extended, 21, 681, 751
external, 22
K (kilobytes), 20, 680, 753
M (megabytes), 24, 681, 754
measurements, 680-681
padding, 476 reserving
arrays, 476
structure tags, 585
volatility, 22, 760
778
C++ By
EXAMPLE
menu-driven programs, 754
menus, 754
messages, error, see error messages
microchips, 18, 754
microcomputers, 17, 754
microprocessors, 754
minimum routine, 224
mirror-image input functions, 637
models, see prototypes modems, 28-29, 754
external, 751
internal, 753 modes
binary, 631
file access, 630
text, 630
modifers, set pr eci si on , 408 modular programming, 332, 754
modulated signals, 29 modules of code, 331
modulus (%) math operator, 164, 167-168, 755
monitors, 24
graphics, 24
monochrome, 24
see also displays; screens most-significant bit, 686
mouse, 28, 755
moving cursor with arrow keys, 27
MS-DOS, 30-32, 435-436, 755
multidimensional arrays, 520-522, 755
f or loops, 530-537 initializing, 526-530
reserving, 522-524 storing, row order, 526 subscripts, 520-522
see also tables; matrices multiple-choice statement, 312 multiplication (* ) math operator,
64, 164
N
name-mangling, 422 naming
arrays
as pointers, 558-559
changing, 560
disks drives, 23
files, 751
functions, 335-337
overloading, 415
rules, 335
pointers, 542, 543
structures, 585
variables, 70-71, 360
invalid names, 71
local, overlapping, 360
spaces, 71
negative numbers, 166
binary, 692-694 nested
function calls, 402
structures, 600-603
nested loops, 755
braces, 287
br eak statement, 299 counter variables, 288 error messages, displaying,
296
f or , 286-291
multidimensional tables, 530
sorting arrays, 504
timing loops, 296
newli ne ( \ n) character, 135-136, 433, 635
next _f un( ) function, 338 nonarrays, passing by address,
391-396
nonbuffered functions, 444
nonconditional expressions, 190
nonzero values, 451
NOT (! ) logical operator, 208, 452 not equal to (! = ) relational
operator, 186
779
Index ♦
notation
array, 608-610
mixing, 609
scientific, 758
see also pointer notation null
character, 88
expression, 285
strings, 755
zero, 101, 755 numbers
2's complement, 692
absolute value, 461
binary, 17, 165, 748
see also binary numbers comparing, 199 converting from strings,
460-461
floating-point, 63, 76, 140 hexadecimal, see hexadecimal
numbers integers, 63
justification, 140
negative, 166, 692-694
printing, 139
random-number processing, 465-469
real, 76, 758
rounding, 461-462
signed, 693
square, 196
tables, printing, 138
unsigned, 693 numeric
arguments, testing functions, 451
arrays, sorting, 508
constants, printing, 151
functions, 461-467, 755
keypad, 27 literals
defining, 127
overriding default, 79
variables, printing, 151
O
object code, 755
object-oriented programming, see
OOP
objects, 663, 755
octal literals, 83
of st r eam function, 436-437 on-screen printing, 125
OOP (object-oriented program- ming), 14, 661, 665, 755
open( ) function, 629, 648
opening files, 629-634, 647-649 operations
binary, 165
direction, 175-176
operators, 16-17, 408, 755
! (NOT), 452
. (dot), 608, 616
assignment (=), 174-178
arrays, initializing, 480
binary, 165
bitwise, 234-241, 748
logical, 235-244
ci n , 144-148
comma (, ), 232-234, 758
compile-time, 231
compound, 177
conditional, 222-225
control, 139-144
cout , 83, 93, 134-148
decrement (-- ), 225, 233 dot (. ), 592
increment (++), 225, 233
logical, 207-215
! (NOT), 208
&& (AND), 208
|| (OR), 208
truth tables, 208
math, 754
* (multiplication), 64
+ (addition), 64
- (subtraction), 64
/ (division), 64
780
C++ By
EXAMPLE
order of precedence, 216, 752
overloaded, 542 pointers
& (address of), 542
* (dereferencing), 542 postfix, 225-227 precedence, 16, 756 prefix, 225-227
primary, order of precendence, 169
relational, 185-189, 209, 758
see also relational operators
si zeof , 230-232 ternary, 222
unary, 165-166, 760
OR (|| ) logical operator, 208 order of case statements, 319 order of bits, 686
order of precedence, 752, 756-757
logical operators, 216
math operators, 168-174
parentheses, 170-174
primary operators, 169
table, 729-732
origin values, 650 origins of C++, 15-16 output
controlling, operators, 139-144
devices, 134, 756
standard, 759 formatting
carriage returns, 439
printing, 436-437
labeling, 86, 136
redirecting, 134 rerouting to printer, 436 screen, 24
st dout , 435
st r eam , 434
output redirection symbol (>), 435
output statements, 17 overlapping names of local
variables, 360
overloading, 756
constructor functions, 673
functions, 415, 420-425
name-mangling, 422
operators, 542 overriding
keyboard default device, 436 passing by copy, 547
overwriting variables, 354, 363
P
padding memory, 476
parallel arrays, 756
parallel port, 756
parameters, 756
passing, 374-375
pointers, 546-551
receiving, 364
types, declaring, 366
see also variables parentheses ( ) , 46
condi t i onal _expr essi on , 223 empty, 365
functions, 336
order of precedence, 170-174, 216
type casting, 180 passing
arguments, see passing vari- ables
arrays, 388
by address, 386
functions, 387
to functions, 484
by copy, overriding, 547 local variables, 364
nonarrays by address, 391-396 one-way, 398
parameters, 374-375
values to character functions, 451
781
Index ♦
variables, 363-369
by address, 374, 385-394,
756
by copy, 379, 756
by reference, 374, 385, 756
by value, 379-384, 756
global, 364
structure, 595
to scanf ( ) function, 546 passive data, 663
paths, 756
PCs (personal computers), 18, 757
percent sign (%), 167 peripherals, 757
personal computers (PCs), 757 PgDn key, 27
PgUp key, 27
placeholders, 246
pointer arithmetic, 568-574
pointer constants, 560-562
pointer notation, 558, 561, 568,
609
pointer variables, 155
pointers, 493, 541, 757
addresses, 542
arrays, 552-553
declaring, 551
names, 558-559
assigning values, 545-546
changing, 560-562 character, see character
pointers data types, 542
declaring, 543-545
decrementing, 568
elements, dereferencing, 576
file, 631, 650
declaring globally, 632
positioning, 650-656
f il e_pt r , 629
global, declaring, 542
incrementing, 568
initializing, 545
assignment statements, 548
while declaring, 545
local, declaring, 542
naming, 542-543 operators
& (address of), 542
* (dereferencing), 542 parameters, 546-551 prefixing, 548
reference, as arrays, 561 to files, 629
ports
parallel, 756
serial, 758
positioning pointers (file), 650-656
positive relational tests, 252 postfix operator, 225-227 pound sign (#), 114
pow( ) function, 463 pow( x, y) function, 462 pr _msg( ) function, 416
precedence, see order of prece- dence
precedence table, 729-732
prefix operators, 225-227 prefixes
pointers, 548
signed, declaring variables, 166
preprocessor directives, 113-115,
757
#def i ne , 120-128
#i ncl ude , 115-120
; (semi-colon), 114
see also individual listings preprocessors, 43
primary operators, order of precendence, 169
pr i nt _i t ( ) function, 525 printers, 25, 757
dot-matrix, 25, 751-753
laser, 25, 751-753
782
C++ By
EXAMPLE
line, 753
rerouting, 436
writing to, 637-638
pr i ntf ( ) function, 65, 126, 149-150, 191
prototyping, 407 stdio.h header file, 150 strings, constants, 150
printing
arrays
brackets ([ ] ), 102
cout operator, 102 blank lines, 136
columns, 534
set w manipulator, 139-140 constants, numeric, 151
conversion characters, 297 floating-point values, zeros,
153
literals
cout operator, 83 string, 85
numbers, 139-140
on-screen, 125
output, formatted, 436-437
rows, 534
strings, 102
cout operator, 134-144 from character arrays, 135 in arrays, 563
in character arrays, 510
pr i ntf ( ) function, 150 tables, numbers, 138
titles, 535
values, ASCII, 154 variables
floating-point, 152
integer, 152
numeric, 151
private class members, 757 program editors, see editors program listings, 38 programming, object-oriented,
see OOP
programming languages, see
languages
programs, 30, 36-38, 757
comments, 749
data-driven, 185
designing, 38-39
formats, 53-54
mailing list, 737-746
maintainability, 174
menu-driven, 754
modular programming, 332
multiple-function formats, 338
readability, 54-55
routines, 332
sample, 44-46
skeleton, 333
string length, 250
structured programming, 332
typing, 37
prototypes, 338, 757
built-in functions, 397,
405-411, 734-735
character functions, 450 ctype.h header file, 734
character functions, 450
f ill _st r uct s( ) function, 597 header files, 408
lists, multiple default argu- ments, 417
mai n( ) function, 409 math.h header file, 461, 735 pr i ntf ( ) function, 407 scanf ( ) function, 407
self-prototyping functions, 406 string.h header file, 735 stdio.h header file, 408, 734
stdlib.h header file, 460, 735
at o( ) function, 460 string.h header file (string
functions), 456
public class members, 662, 674,
757
put ( ) function, 438-444 put ch( ) function, 444-446 put s( ) function, 457, 635
783
Index ♦
Q–R
quicksort, see sorting arrays quotation marks (“ ” ), 85, 89, 117
ragged-edge arrays, 574
RAM (random-access memory), 20-22, 747, 757
accessing, 627
r and( ) function, 465-466, 497
random files, 628, 757
accessing, 627, 648
creating, 648
opening, 647-649
records, 646
fields, 646
fixed-length, 647 random-number processing,
465-469
read access mode, 639
r ead( arr ay, count ) function, 656 read-only memory (ROM), 758 reading
files, 639-642
to files, specific points, 649-656 real numbers, 76, 758
receiving arguments (& prefix), 550
receiving functions, 364
local variables, 368 variables, renaming passed,
382
records, 635, 646, 758
fields, 646, 751
fixed-length, 647, 751
variable-length, 760 redefining
functions, 121-126
statements, 121-126 redirection
< (input redirection symbol), 435
- (output redirection symbol), 435
combining symbols, 436 devices from MS-DOS,
435-436
output, 134
reference, passing variables, 374, 385, 756
reference pointers as arrays, 561 referencing
* (dereferencing) pointer operator, 542
addresses (%c control code), 512
arrays, 508-515
subscripts, 558
elements, subscripts, 476-474 relational if tests, 209
relational logic, 187
relational operators, 185-189, 758
! = (not equal to), 186
< (less than), 186
<= (less than or equal to), 186
== (equal to), 186
- (greater than), 186
>= (greater than or equal to), 186
compound, 209
relational tests, 252
internal truths, 210
positive, 252
remainder (%) math operator, 164 r emove( f il ename) function, 656 renaming variables, passed, 382 replacing defined literals, 126 reserving
arrays
character, 100, 480
multidimensional, 522-524
of pointers, 551
elements, 103 memory
arrays, 476
structure tags, 585
uppercase letters, 55
variables, 365
784
C++ By
EXAMPLE
resolution (screens), 24
return statements, 337, 345
return values, 374, 402
calling functions, 398
function calls, 401
functions, 398-405
global variables, 398
type, 400
returning functions, 337-349 ROM (read-only memory), 758 rounding
fractions, 140
numbers, 461-462
routines, 332
minimum, 224
see also functions
row order, multidimensional arrays, 526
rows, printing, 534
running programs, see executing programs
S
sample programs, 44-46 saving sort functions, 508 scanf ( ) function, 126, 149,
154-157
& (ampersand), 155
passing variables, 546
pointer variables, 155
prototyping, 407 variable names scientific notation, 758
scope, variable, 760 screens
cursor, 24
output, 24
resolution, 24
see also displays; monitor scrolling text, 24
searching arrays, 494-495
f or statement, 496 for values, 496-501 i f statement, 496
sections, see blocks sectors, 758
seekg( ) function, 649-656 self-prototyping function, 406
semicolon (; ), 56, 114, 120, 190,
339
separating functions, 345 sequence point, see comma
operator
sequential files, 625-629, 758
serial ports, 758
setprecision modifier, 408
set w manipulator, 408 conversion characters, 140
printing columns, 139-140
string width, 140
set w( ) function, 140
shell sort, see sorting arrays Shift keys, 25
sign bit, 693 signals
analog, 29
demodulated, 29, 750
modulated, 29 signed
numbers, 693
prefix, variables, declaring, 166
variables, numeric, 78
si n( x) function, 464 size
arrays, 476-477, 480
variables, 76-77
si zeof operator, 230-232
si zeof ( ) function, 476-477 skeleton programs, 333 slashes (// ), 46
software, 19, 29-34, 758 sort functions, saving, 508 sor t _ascend file, 508
sor t _descend file, 508
785
Index ♦
sorting arrays, 494-495, 501-508,
758
ascending sort, 506
bubble sort, 502-505, 748
character arrays, 508
descending sort, 494, 506
nested loops, 504
numeric arrays, 508
quicksort, 502, 757
shell sort, 502, 758
source code, 40, 759
modifying, 113-115
text, including, 117 space
between elements, 476 in variable names, 71
spaghetti code, 759
specifying types in arrays, 390 Spher e( ) function, 663-670 sqr t ( x) function, 462
square numbers, 196
square root, 462
squar e( ) function, 674 standard input device, 434, 759
see also st di n
standard output device, 759
see also st dout
standards, ANSI, 13
start expressions, loops, 274, 278 statements
assignment, 80, 105, 174-178
initializing pointers, 548
start expressions, 274
assignments, multiple, 175-176
blocks, 246-748
body, 189
br eak , 256-260, 298-303
case , 313, 319 const r uct , 246 cont i nue , 303-307
controlling, conditionally, 185
cout , 85, 102
decision, 189
declaration, 101 do- whil e , 252-255 el se , 198-203
FI LES= , 629
f or , 274, 290, 298-303
function-calling, 337
got o , 321-326
I/ O (input/ output), 17
i f , 189-199
input, 17
labels, 321-322
looping, 246, 277
multiple-choice, 312
output, 17
redefining, 121-126
return functions, 337 semicolon (; ), 56 separating, 232
st r uct , 587-591
swi t ch , 312-321, 342
whil e , 246-247
states of electricity, 21, 683
static variables, 369-374, 759
declaring, 370
initial values, 370 st di n , 434-435 stdio.h header file
function prototypes, 408, 734
pr i ntf ( ) function, 150 stdlib.h header file
exi t ( ) function, 256 function prototypes, 460, 735
st dout , 434-435 storage, disks, 750 storing
arrays
character pointers, 574
strings, 574
elements (arrays), 476 filenames, character arrays,
633
multidimensional arrays, 526
786
C++ By
EXAMPLE
strings, 100, 104, 563 user input, strings, 565 variables, 385-386
st r cat ( ) function, 456
st r cmp( ) function, 456
st r cpy( ) function, 107, 408 stream I/ O, 432-436 streams, 434, 759
string constants, 566
string delimiter, 88, 759
string functions, 455-461
f get s( s, l en, dev) , 457
f put s( s, dev) , 457
get s( s) , 457 I/ O, 456-459
prototypes, string.h header file, 456
put s( s) , 457 testing, 456
st r cat ( ) , 456 st r cmp( ) , 456 st r l en( ) , 456
string length programs, 250 string literals
assigning, 85
defining, 127
endings, 87-89
printing, 85
string variables, 100
string-terminating characters, 457-458, 755
string.h header file, 107, 118
function prototypes, 456, 735
strings, 759 arrays
declaring, 478
printing, 563
storing, 574
arrays of, 574-578
character variables, 100 character arrays
comparing, 103-110
multiple, 512
concatenating, 456
constants, 759
cont r ol _st r i ng , 149, 155 converting to numbers,
460-461
empty, 755
format, controlling, 149
I/ O, 457
inputting, 442
length, 89, 251
literals, 107, 759
mathematical calculations, 460
null, 755
printing, 102
cout operator, 134-144 from character arrays, 135 in character arrays, 510
pr i ntf ( ) function, 150 reserving elements, 103
shortening, 107
storing, 100, 104, 563
terminating character, 101 user input, storing, 565 values
assigning, 107 assigning to character
arrays, 105
width, 140
st r l en( ) function, 251, 456
st r uct statement, 587-591 structured programming, 332
structures, 584-587, 759
arrays, declaring, 606-615
arrays of, 747
declaring, 591
defining, 587-591
arrays of, 589
globally, 595
initializing, 591-592 members
calculations, 597
initializing, 591-600
names, 585
787
Index ♦
nested, 600-603
tags, 585 variables
copying members, 598
defining, 595
initializing, 591
passing, 595
specifying, 588
subdirectories, 750
subfunctions, 398
subroutines, 398
subscripts, 101-102, 474, 759 arrays
declaring, 482
referencing, 558
double, 616 formulas, referencing
elements, 476
multidimensional arrays, 522 multiple (multidimensional
arrays), 520
out-of-range (nonreserved), assigning values, 479
referencing, 474
subtraction (- ) math operator, 64, 164
suffixes, literals, 79
summation symbol, 290
sur f ace_ar ea( ) function, 663-670
swapping variables, 502, 550
switch statements, 312-321
body, 342
default line, 312
expressions, 312
syntax errors, 46, 759
system unit, 20-22
T
tab (\t ) character, 138, 433 tables
arrays of structure variables, 747
hierarchy, 511
justification, 574, 575
multidimensional, 530-537
numbers, printing, 138
see also arrays; matrices; multidimensional arrays
t an( x) function, 464 terminating
string-terminating characters, 457-458
strings, 101
ternary operators, 222 test expressions
expressions, 283
loops, 274-275
parentheses, 246 testing
alphabetic conditions, functions, 450-451
character testing functions, 450, 453
compound relational tests, 207 digital, functions, 451
equality, 187
i f , relational, 209 strings, functions, 456
relational, 252
internal truths, 210
positive, 252
values, 749 text
boilerplates, 117
scrolling, 24
source code, including, 117 text mode, 630
t hi r d_f un( ) function, 338 timing loops, 295-298, 759
iterations, 296
nested loop, 296
titles, printing, 535
t ol ower( c) function, 454 totals, 260-270
t oupper( c) function, 454 tracing function calls, 340 tracks (disks), 23, 760
788
C++ By
EXAMPLE
transistors (electricity), 21 trigonometric functions
cos( x) , 464 si n( x) , 464 t an( x) , 464
truncation, 179, 760
truth tables, 208, 235-236
truths, internal, 210
two-dimensional arrays, 525
see also multidimensional arrays
two's complement, 692
type casting (data types), 179-182 types
arrays, specifying, 390
parameters, declaring, 366
return values, 400
variables, 584
see also structures
see also data types typing programs, 37
U
unary operators, 165-166, 760 unconditional break statements,
299
underscore (_ ), 336
UNIX, cf r ont compiler, 43 unreachable code, 305
unsigned literals, designating, 79 unsigned numbers, 693
unsigned variables, 84
uppercase letters, 55, 240
V
validating data, 195 values
arrays, searching for, 495, 496-501
ASCII, printing, 154 assigning
arrays, 103
elements, 479
out-of-range subscripts, 479
to pointers, 545-546
to variables, 145
data types, truncating, 179 delay, 296
floating-point, 138
initial, static variables, 370 keyboard, 392
members, assigning with dot operator, 602
nonzero, 451
origin, 650
local variables, 355
passing variables by, 379-384, 756
passing to character functions, 451
returning from functions, 374 strings, assigning, 105-107
testing, 749
totaling, 265 variables
assigning, 80-82 assignment operator (=), 63 ci n function, 145
entering directly, 154
updating, 176
see also return values variable scope, 353-362, 760
variable-length records, 760
variables, 62-63, 70-82, 760
addresses, 385-386
arrays, 747, 751
automatic, 369-374, 747 changing, called functions, 387 character, 75
character strings, 100 comparing to literals, 192 constant, 94-95
counter, 262, 265, 288, 360
data types, 179
declaring, 62, 73, 166
decrementing, 225-230
defined literals, 122
789
Index ♦
defining, 365
after opening brace, 355 as constants, 120
outside functions, 355
environment, 256
equality, determining, 186
floating-point, 100, 142, 152 global, see global variables incrementing, 225-230 initializing to zero, 176 integer, 73, 152, 753
local, see local variables loop, decrementing, 282
loop-counting, 361
lowercase letters, 122
naming, 70-71, 360
& (ampersand), 155
invalid names, 71
spaces, 71
numeric, signed, 78
overwriting, 354, 363
parameters, 756
passing, 363-369
by address, 374, 385-394,
756
by copy, 379, 756
by reference, 374, 385, 756
by value, 379-384, 756
renaming, 382
to scanf ( ) function, 546 pointer, 155, 757
scanf ( ) function, 155 printing, numeric, 151
ranges, 76-77
relational operators, 186
reserving, 365
size, 76-77
static, 369-374, 759
storing, 385-386
string, 100
see also string variables structure
copying members, 598
defining, 595
initializing, 591
passing, 595
specifying, 588
swapping, 502, 550
types, 72-79, 584
functions, 152
long, 77
see also structures unsigned, 84
values
assigning, 80-82, 145 assignment operator (=), 63 ci n function, 145
entering directly, 154
updating, 176
VGA display adapters, 24 voi d keyword, 406 volatile (memory), 22, 760
vol ume( ) function, 663-670
W
weakly typed (language), 16
see also data types
whil e loops, 245-247, 255
white space, 55
width, strings, 140
width specifiers, 153
words, 760
wr i t e( arr ay, count ) function, 656
writing
functions, 332-337
to files, 635-637
to printers, 637-638
X–Y–Z
zeros, 87-89, 101
binary, 88, 748
floating-point values, 138, 153
null, 103, 755
subscripts, 102
variables, initializing, 176
790
Order Your Disk Program T oday !
You can save yourself hours of tedious, error-prone typing by ordering the companion disk to C++ By Example. The disk contains the source code for all the complete programs and many of the shorter samples in the book. Appendix F’s complete mailing-list application is also included on the disk, as well as the answers to many of the review exercises.
You will get code that shows you how to use most the features of C++. Samples include code for keyboard control, screen control, file I/ O, control statements, structures, pointers, and more.
Disks are available in 3 1/ 2-inch format (high density). The cost is
$10 per disk. (When ordering outside the US, please add $5 for shipping and handling.)
Just make a copy of this page, fill in the blanks, and mail it with your check or money order to:
C++ Disk
Greg Perry
P.O. Box 35752
Tulsa, OK 74135-0752
Please print the following information:
Payment method: Check Money Order
Number of Disks: @ $10.00 =
Name: Street Address: City: State: ZIP:
(On foreign orders, please use a separate page to give your mailing address in the format required by your post office.)
Checks and money orders should be made payable to:
Greg Perry
(This offer is made by Greg Perry, not by Que Corporation.)