Index

Symbols

+ (addition) operator, 314-316

& (address of) operator, 222-223, 257-258

= (assignment) operator, 50, 71, 317-320

& (bitwise AND) operator, 773

| (bitwise OR) operator, 774

{ } (braces), 27, 68

aligning, 779

nested if statements, 88-89

/* comment notation, 33

// comment notation, 33

?: (conditional) operator, 94-95

[] (brackets), 429

. (dot) operator, 150, 239

== (equal) operator, 79-80

’ escape code, 58

” escape code, 59

? escape code, 59

\ escape code, 59

00 escape code, 59

- (decrement) operator, 74-76

^ (exclusive OR) operator, 774

>> (extraction) operator, 599, 603-604

> (greater than) operator, 80

>= (greater than or equal to) operator, 80

++ (increment) operator, 74-76

* (indirection) operator, 226, 280

<< (insertion) operator, 585-589

< (less than) operator, 28, 80

<= (less than or equal to) operator, 80

&& (logical AND) operator, 91

! (logical NOT) operator, 92

|| (logical OR) operator, 91

% (modulus) operator, 73

!= (not equal) operator, 80

= 0 notation, 478

0 (null character), 600

( ) (parentheses), 96

macro syntax, 757-759

nesting, 78

-> (points-to) operator, 240-241

# (pound symbol), 26

++ (prefix) operator

compared to postfix operator, 311-313

overloading, 304-306

“(quotation marks), 759

< (redirect input) operator, 598

<< (redirection) operator, 17, 28

& (reference) operator, 256, 280-281

:: (scope resolution) operator, 640

+= (self-assigned addition) operator, 74

; (semicolon), 68, 83

- (subtraction) operator, 71-72

~ (tilde), 154, 774

A

a escape code, 58

abstract classes, 486

abstract data types (ADTs), 476-477

advantages, 488

declaring, 478

deriving from other ADTs, 482-486

example, 477-478

pure virtual functions, 477

abstraction in programming, 129

access control keywords, 150

access labels, 783

accessing

arrays, 415

contained classes, 545

data members, 143-146

on the free store, 239-241

nonstatic methods, 510-511

private members, 144, 147

public members, 145-146

static member data, 508-509, 513, 692

derived objects, 377-378

memory addresses, 229-231

accessor methods, 147-148

actors (use cases), 337

Add( ) function, 38, 313-314

adding increment operators, 303-304

adding to two lists (inheritance), 456

addition operator (+)

overloading, 314-316

self-assigned operator (+=), 74

address of operator (&), 222-223, 257-258

addresses

memory addresses, 227-228

determining, 222-223

examining, 229-231

retrieving, 226

storing in pointers, 224-225

target addresses, 257-260

ADTs (abstract data types), 473, 476-477

advantages, 488

declaring, 478

deriving from other ADTs, 482-486

example, 477-478

pure virtual functions, 477

algorithms, for_each( ), 709-710

aliases, 652

aligning braces ({ }), 779

allocating

memory, 234

pointers, 236

allocators, 694

ambiguity resolution, 463-464

American National Standards Institute (ANSI) C++ Standard, 12-13

ampersand (&)

address of operator, 222-223, 257-258

bitwise AND operator, 773

logical AND operator, 91

reference operator, 256, 280-281

analysis (use-case), 335-337

actors, 337

customer roles, 337-339

domain models, 339-343

guidelines, 344-346

interaction diagrams, 346-347

packages, 347

scenarios, 343-344

AND operators

bitwise (&), 773

logical (&&), 91

ANSI (American National Standards Institute) C++ Standard, 12-13

anthropomorphic CRC card, 355-356

appending files, 626-628

application analysis, 347

applications. See programs

Area( ) function, 104

argc (argument count), 631

arguments, 36, 101, 113

command-line processing, 631-634

defaults, 116-118

passing

to base constructors, 381-385

by reference, 262-265, 271-274

by value, 109-110, 134, 263-264

argv (argument vector), 631

arithmetic operators

combining with assignment operator, 73-74

modulus (%), 73

pointers, 423-426

subtraction (-), 71-72

arrays, 407-408

Array class templates, 663

bugs, 410

char, 432-434

classes, 444-445

combining, 446

declaring, 408, 414-415, 426

defined, 407

deleting from free store, 429

dictionary arrays, 444

elements, 408-409

accessing, 415

uninitialized, 445

fence post errors, 413

filling, 433-434

initializing, 413-414

integer arrays, 409

memory, 421

multidimensional, 417-419

names, 427-428

object arrays, 416-417

pointer arrays, 421-423, 426-428

function pointers, 521-523

method pointers, 532

resizing at runtime, 429-432

sets, 444

sizes, 415

storing

on free store, 421-423

on stack, 421

writing past the end of, 410-413

artifacts, 349-350

ASCII character sets, 46

assemblers, 747

assert( ) macro, 784

debugging functions, 762-764

exceptions, 763

source code, 761-762

assigning

addresses to references, 259-260

values to variables, 50-52, 143

variables to user-defined classes, 320-321

assignment operator (=), 50, 71, 317-320

combining with math operators, 73-74

association (domain models), 343

asterisk (*), 226, 280

at( ) function, 700

B

 escape code, 58

back( ) function, 700

backslash (), 59

backspaces, 58

base 2 numbers, 810-812

base 7 numbers, 809

base 8 numbers, 808-809

base 10 numbers, 808

converting to base 2, 813-814

converting to base 6, 810

converting to base 7, 809-810

converting to binary, 810-811

base 16 numbers, 813-816

base classes, 372

inheritance, 464-468

methods

calling, 389-390

constructors, 378, 381-385

destructors, 378

hiding, 387-389

overriding, 386-387

begin( ) function, 702

binary files, 629-631

binary numbers, 810-812

binding, dynamic, 395

bits, 773, 812

clearing, 774-775

fields, 775-778

flipping, 775

setting, 774

bitwise operators, 773-774

blocks, 68-69

catch, 719, 729-732

try, 719-722

body of functions, 36

bool data type, 46, 79

braces ({ }), 27, 68

aligning, 779

nested if statements, 88-89

brackets ([ ]), 429

branching

programs, 132-133

relational operators, 81-82

break statement, 180-183

breaking while loops, 180

breakpoints, 747

budgets (design projects), 348

buffers, 594-596

copying strings to, 435-436

flushing, 596

implementing, 597

uninitialized, 433-434

bugs, 716. See also troubleshooting

debugging, 746-747

assemblers, 747

assert( ) macro, 762-764

breakpoints, 747

examining memory, 747

inclusion guards, 755-756

printing interim values, 769-771

watch points, 747

fence post errors, 413

stray pointers, 247

built-in functions, 100

built-in text editors, 22

bulletproof programs, 716

bytes, 812

C

.c filename extension, 14

C language, 11-12, 33

calling

functions, 35-36, 129, 133

base methods, 389-390

constructors, 460-463

recursion, 124-125, 128

static methods, 511-513

pointers to methods, 528

cannot find file error messages, 17

capabilities classes, 473

capacity( ) function, 695

capitalization, 782

cards (CRC)

anthropomorphic, 355-356

CRC sessions, 354-355

limitations of, 356-357

responsibilities, 355

transforming to UML, 357

caret (^), 774

carriage return escape character ( ), 58

case-sensitivity, 48

case values (switch statements), 199

casting down, 453-455, 487

Cat class

accessor functions, 159

Cat object, initializing, 156-157

data members, 145-146

declaring, 141, 164-165

implementing, 165

methods

accessor methods, 147-148

GetAge( ), 153

GetWeight( ), 164

implementing, 151-152

Meow( ), 148, 153

SetAge( ), 153

Cat object, initializing, 156-157

Cat.cpp, 165

Cat.hpp, 164

catch blocks, 719, 729-732

catching exceptions, 728-732

Celsius, converting to Fahrenheit, 106

cerr object, 598, 635

char arrays, 432-434

char variables, 43, 46

character encoding, 57

escape characters, 58-59

sizes, 56

character reference parameters (get( ) method), 606

characters, 56-57

ASCII character sets, 46

character strings, parsing, 423-425

encoding, 57

escape characters, 58-59

fill characters, 616-617

null, 432, 601

sizes, 56

cin object, 598-600

input

extraction operator, 603-604

multiple input, 601-603

strings, 600-601

methods

get( ), 604-608

getline( ), 608-610

ignore( ), 610-611

peek( ), 611-612

putback( ), 611-612

class keyword, 141, 149-151, 662

class, responsibility, and collaboration cards. See CRC cards

classes, 150. See also specific class names

abstract, 486

array classes, 444-445, 663

base classes, 372

compared to objects, 142

compared to structures, 171

contained classes, 537

accessing members of, 545

compared to delegation, 553-561

constructors, 546-549

costs, 546-549

Employee class, 542-544

filtering access to, 545

implementing, 552-553

passing by value, 549-552

String class, 538-542

data members, 140

accessing, 143-146

other classes as, 166-171

private, 144-145, 172, 376-377

protected, 376-377

public, 144-146

declaring, 141, 159-163, 374-376, 783

defined, 140

derived classes, 372-376, 473, 476-477

friend classes, 571-572

declaring, 580

sample program listing, 572-579

usage tips, 579

inheritance

casting down, 453-455, 487

limitations, 449-452

percolating shared functions, 452

invariants, 764-769

methods, 140

constants, 158-159

default values, 292-294

defining, 143-144

implementing, 151-154

inline, 163-166

overloading, 289-294

public accessor methods, 147-148

mixins, 473

naming conventions, 141-142

object-oriented design, 350

CRC cards, 354-357

data manipulation, 353

device protocols, 354

dynamic model, 363-366

preliminary classes, 351-352

relationships, 358-363

static model, 354

transformations, 352-353

views, 353

polymorphism, 11

resolving by name, 638-642

security, 148-149

shared base classes, 464-468

subclasses, 166-171

writing to files, 629-631

clearing bits, 774-775

clients, 159

clog object, 598, 635

code

code rot, 746

code space, 130

compiling, 15

reusing, 10-11

collaboration diagrams, 364

combining

arrays, 446

math operators with assignment operators, 73-74

references and pointers, 280

command-line processing, 631-634

comments, 32-33, 38

/* (C-style), 33

// (C++-style), 33

cautions, 34

example, 33-34

readability, 782-783

writing, 39

Compare( ) method, 881

compile time, 22

compile-time errors, 162

compilers, 6, 19, 752

assert( ) macro, 761-762

compiling with symbols, 747

errors, 20-21

intermediate files, saving, 752

troubleshooting, 20

compiling

errors, 20-21

Hello World program, 17-18

source code, 15

with symbols, 747

complement operator, 774

compound statements, 68-69

concatenating

strings, 759-760

values, 30

concatenation operator, 759-760

conditional operator, 94-95

conflict resolution, 637-642

const default, overriding, 642

const methods, 158-159, 249-251

const pointers, 248-251

declaring, 248-249

methods, 249-250

passing, 274-277

const statement, 60, 158, 172-173, 784

const this pointers, 251

constants, 59. See also variables

in arrays, 415

changing, 60

defining, 60

enumerated, 61-63

literals, 59

substitutions, 753

symbolic, 59-60, 64

constructors, 154

base constructors, passing arguments to, 381-385

contained classes, 546-549

copy constructors, 298-302

deep copies, 298, 301-302

member-wise copies, 298

parameters, 298

virtual, 400-403

defaults, 154-158, 295

inheritance, 378-381

initializing, 297

member variables, 297

multiple constructors, calling, 460-463

overloading, 294-296, 381, 384

specialized, 688

containment, 342-343, 537, 693

compared to delegation, 553-561

compared to private inheritance, 590

contained classes

accessing members of, 545

class design, 358-359

compared to delegation, 553-561

constructors, 546-549

costs, 546-549

Employee class, 542-544

filtering access to, 545

implementing, 552-553

passing by value, 549-552

String class, 538-542

costs, 546-549

implementing, 552-553

continue statements, 180-182

contravariance, 803-804

conversion operators

creating, 321-323

sample program, 323-324

conversion specifiers, 620-621

Convert( ) function, 106

converting

base 10 to base 6, 810

base 10 to base 7, 809-810

base 10 to binary, 810-811

data types, 320-324

decimals to binary, 813-814

Fahrenheit/Celsius, 106

copy constructors, 298-302

deep copies, 298, 301-302

member-wise copies, 298

parameters, 298

virtual, 400-403

copying strings, 435-436

Counter class

Counter object

converting int to, 321-322

converting to unsigned short, 324

declaring, 302-303

increment functions, 303-304

counting

numbers, 183-184

variables, 195

cout object, 28-30, 598

example, 28-29

fill characters, 616-617

flags, 617-620

methods

fill( ), 616-617

flush( ), 613

put( ), 613-614

setf( ), 617-620

width( ), 615-616

write( ), 614-615

output width, 615-616

passing values to, 29

.cp filename extension, 14

.cpp filename extension, 14, 162

CRC (class, responsibility, and collaboration) cards

anthropomorphic, 355-356

CRC sessions, 354-355

limitations of, 356-357

responsibilities, 355

transforming to UML, 357

customer roles (use cases), 337-339

D

%d conversion specifier, 620

dangling pointers, 245-248

data hiding, 10

data members

accessing, 143-146

classes, 166-171

free store

accessing, 239-241

pointers, 241-243

private, 144-145, 172, 376-377

protected, 376-377

public, 144-146

security, 148-149

static

accessing, 508-511

advantages, 533

defining, 507

example, 506-507

data slicing, 397-399

data types, 46

abstract, 473, 476-477

advantages, 488

declaring, 478

deriving from other ADTs, 482-486

example, 477-478

pure virtual functions, 477

bool, 79

converting, 320-324

creating, 139, 644

deallocating memory, 235-237

DEBUG mode, 769-771

debuggers, 746-747

debugging, 746-747. See also troubleshooting

assemblers, 747

assert( ) macro, 762-764

breakpoints, 747

examining memory, 747

inclusion guards, 755-756

printing interim values, 769-771

watch points, 747

dec flag, 618

decimal numbers, 808

converting to base 6, 810

converting to base 7, 809-810

converting to binary, 810-814

declaring

abstract data types, 478

arrays, 408, 414-415

object arrays, 416-417

on free store, 426

two-dimensional, 420

classes, 163, 783

Cat, 141, 164-165

Counter, 302-303

derived classes, 374-376

errors, 159-162

friend classes, 580

Point, 166-167

Rectangle, 168-170, 296

Rectangle class, 210-216

String, 437-443

constants

#define statement, 60

const statement, 60

constant substitutions, 753

data types, 644

functions, 101-103, 143-144

Add( ), 313-314

const, 158

example, 104-105

file locations, 162-163

friends, 585

inline, 122-124, 771-772

namespace functions, 645

macros, 756-757

method default values, 292-294

multiple inheritance, 459

namespaces, 643-644

objects, 142, 150

pointers, 224, 248-249, 231, 528

references, 256-257, 262

static data members, 507, 689-692

string substitutions, 752

structures, 171

templates, 661-664

variables, 42-43, 47-48

case-sensitivity, 48

Hungarian notation, 48-49

local variables, 106

multiple variables, 50

reserved words, 49

virtual inheritance, 472

decrement operator (- -), 74-76

deep copies, 298, 301-302, 318

default constructors, 154-158, 295

default destructors, 154-158

default parameters (functions), 116-118

default statement, 200

default values, 292-294

deferencing pointers to functions, 520

#define statement, 60, 753-754

defining. See declaring

delegation, 553-561

delete statement, 235-237, 429

delete( ) function, 694

deleting

arrays on free store, 429

pointers, 235-236

Demonstration-Function( ) function, 36

dereference operator (*), 226

dereferencing pointers, 232

derived classes, 372-376, 404, 473, 476-477

ADTs, 482-486

constructors, over-loading, 381-385

data members, accessing, 377-378

declaring, 374-376

design, 13-14, 329

classes, 350

CRC cards, 354-357

data manipulation, 353

device protocols, 354

dynamic model, 363-366

preliminary classes, 351-352

relationships, 358-363

static model, 354

transformations, 352-353

views, 353

models, 329-330

process, 331-333

controversies, 335

iterative development, 332

methods, 332

Rational Unified Process, 332

requirements documents, 335-336

application analysis, 347

artifacts, 349-350

project budgets and timelines, 348

systems analysis, 347-348

use-case analysis, 336-347

visualizations, 349

UML (Unified Modeling Language), 330-331

vision statements, 335

destructors

defaults, 154-158

inheritance, 378-381

virtual, 399-400, 488

development cycle, 16

development environments, 14

diagrams

collaboration, 364

interaction diagrams, 346-347

sequence, 363-364

state transition

end states, 364

start states, 364

super states, 365-366

dictionary arrays, 444

discriminators, 360-363

Display( ) function, 500

division of integers, 73

do...while loops

compared to while loops, 205

example, 186

syntax, 187

DoChangeDimensions( ) function, 217

documents (design)

requirements documents, 335-336

application analysis, 347

artifacts, 349-350

project budgets and timelines, 348

systems analysis, 347-348

use-case analysis, 336-347

visualizations, 349

vision statements, 335

Dog class

constructors, 378-381

declaring, 374-376

destructors, 378-381

domain models (use cases), 339-341

association, 343

containment, 342-343

generalization, 341

DOS commands, 598

dot operator (.), 150, 239

DoTaskOne( ) function, 204

double data type, 46

double quote (“), 59

Double( ) function, 123

Doubler( ) function, 115

doubly linked lists, 875

DrawShape( ) function, 290-291

dynamic binding, 395

dynamic_cast operator, 453

dynamic model (classes)

collaboration diagrams, 364

sequence diagrams, 363-364

state transition diagrams, 364-366

E

editors, text, 14

built-in editors, 22

compared to word processors, 21

elements of arrays, 408-409, 415

#else precompiler command, 754-755

else keyword, 84-85

Employee class, 542-544

empty for loops, 191-193

empty( ) function, 695

encapsulation, 10, 594

end( ) function, 702

endl object, 30

endless loops

exiting, 202

switch statement, 201-204

while (true), 183-184

enum keyword, 61

enumerated constants

example, 62-63

syntax, 61

values, 61-62

enumerations in arrays, 415

environments, 14

equal sign (=)

assignment operator (=), 50, 71, 317-320

equality operator (= =), 79-80

errors. See also bugs

cannot find file, 17

class declarations, 159-162

compile errors, 20-21, 162

fence post errors, 413

referencing nonexistent objects, 281-283

stray pointers, 247

warning messages, 22

escape characters, 58-59

eternal loops

exiting, 202

switch statement, 201-204

while (true), 183-184

evaluating

expressions, 70

logical operators, 92

examining memory, 229-231, 747

exceptions, 717-720

advantages, 748

assert( ) macro, 763

catching, 728-729

multiple exceptions, 729-732

try...catch blocks, 719-722

class hierarchies, 732-735

compiler support, 720

data

passing by reference, 739-742

reading, 735

disadvantages, 749

multiple, 729-732

programming tips, 745-746

sample program, 717-718

templates, 742-745

throwing, 722-728

virtual functions, 739-742

exclamation point (!), 92

exclusive OR bitwise operator, 774

executable files, 15

executing

functions, 105

Hello World program, 18

exiting loops

break statement, 180

endless loops, 202

expressions, 69. See also operators

branching, 200-201

evaluating, 70

nested parentheses, 78

external linkage, 641-642

extraction operator (>>), 599, 603-604

F

%f conversion specifier, 621

f escape code, 58

Factor( ) function

pointers, 268-269

references, 270-271

Fahrenheit, converting to Celsius, 106

false/true operations, 93-94

fence post errors, 413

fib( ) function, 197

Fibonacci series

recursion, 124-128

solving with iteration, 196-198

fields, bit, 775-778

FIFO (first in, first out), 703

files. See also specific filenames

appending, 626-628

binary files, 629-631

executable files, 15

filename extensions

.c, 14

.cp, 14

.cpp, 14, 162

.h, 163

.hp, 163

.hpp, 163

.obj, 15

function header files, 267-268

object files, 15

opening for input/output, 624-626

source files, 14

text files, 629-631

writing classes to, 629-630

fill characters, 616-617

fill( ) method, 616-617

filling arrays, 433-434

filtering access to contained classes, 545

Find( ) function, 500

finding memory addresses, 222-223

first in, first out (FIFO), 703

fixed flag, 618

flags, 618-620

flipping bits, 775

float data type, 46

floating-point variables, 46

flush( ) method, 613

flushing

buffers, 596

output, 613

for_each( ) algorithm, 709-710

for loops, 188-190

compared to while loops, 205

empty loops, 191-193

example, 188-189

initialization, 188

multiple initialization, 190

nesting, 193-195

null statements, 191-193

scope, 195-196

syntax, 189

forever loops

exiting, 202

switch statement, 201-204

while (true), 183-184

form feeds, 58

formatting output, 622-623

flags, 617-620

width, 615-616

free store, 252

advantages, 233-234

data members

accessing, 239-241

pointers, 241-243

declaring arrays on, 426

deleting arrays from, 429

memory

allocating, 234

restoring, 235-237

objects

creating, 238

deleting, 238-239

storing arrays on, 421-423

freeing memory, 235-237

friend keyword, 585

friends, 670

friend classes, 571-572

declaring, 580

sample program listing, 572-579

usage tips, 579

friend functions

declaring, 585

operator overloading, 580-585

friend keyword, 585

general template friends, 674-678

non-template friends, 670-674

front( ) function, 700

fstream classes, 597

FUNC.cpp file, 37-38

FunctionOne( ) function, 274

functions, 8, 36-37, 100. See also macros; methods

accessor functions, 147-148

Add( ), 38, 313-314

Area( ), 104

arguments, 36, 101

defaults, 116-118

passing by reference, 262-265, 271-274

passing by value, 109-110, 134, 263-264

at( ), 700

back( ), 700

begin( ), 702

body, 36

built-in, 100

capacity( ), 695

compared to macros, 771

Compare( ), 881

Convert( ), 106

declaring, 101-105, 143-144, 162-163

default values, 292-294

delete( ), 694

Demonstration-Function( ), 36

Display( ), 500

DoChange-Dimensions( ), 217

DoTaskOne( ), 204

Double( ), 123

Doubler( ), 115

DrawShape( ), 290-291

empty( ), 695

end( ), 702

executing, 105

Factor( ), 268-271

fib( ), 197

fill( ), 616-617

Find( ), 500

flush( ), 613

friend functions, 580-585

front( ), 700

FUNC.cpp example, 37-38

FunctionOne( ), 274

get( ), 434

character arrays, 607-608

character reference parameters, 606

with no parameters, 604-606

overloading, 610

GetAge( ), 153, 241

GetArea( ), 169

GetCount( ), 500

GetFirst( ), 500

getline( ), 608-610

GetString( ), 443, 544

GetUpperLeft( ), 169

GetWeight( ), 164

GetWord( ), 425

header files, 267-268

headers, 36

ignore( ), 610-611

increment functions, 303-304

inheritance

casting down, 453-455, 487

percolating shared functions, 452

inline functions, 122-124, 163-166, 771-772

Insert( ), 501, 700

IntFillFunction( ), 682

Intrude( ), 670

Invariants( ), 764-769

invoking, 35-36, 129, 133

Iterate( ), 501

main( ), 27, 100

max_size( ), 695

menu( ), 204

Meow( ), 148, 153

new( ), 694

overloading, 118-121, 387

example, 289-292

when to use, 294

overriding, 385-387

p( ), 653

parameters, 36, 101, 113

peek( ), 611-612

pointers

advantages, 517-520

arrays, 521-523

assigning, 517

declaring, 514

dereferencing, 520

example, 514-517

passing, 523-525

typedef statement, 525-528

polymorphism, 11, 118-121

pop_back( ), 700

pop_front( ), 702

printf( ), 620-622, 635-636

prototypes, 101-104, 267-268

push_back( ), 695

push_front( ), 702

put( ), 613-614

putback( ), 611-612, 635

recursion, 124-128

remove( ), 700

resolving by name, 638-642

return values, 36, 100-101, 114-115

returning multiple values

pointers, 268-270

references, 270-271

SetAge( ), 153, 241

setf( ), 617-620

SetFirstName( ), 544

SetLastName( ), 544

ShowMap, 707

ShowVector( ), 699

sizeof( ), 45

sizes, 112

statements, 112

static member functions, 511-513, 534

strcpy( ), 435

strncpy( ), 435-436

swap( ), 110

pointers, 264-265

references, 265-267

syntax, 27

template functions, 669-670, 683-688

virtual, 404, 487

destructors, 488

pure virtual functions, 477-482

width( ), 615-616

write( ), 614-615

G

general template friends, 674-678

generalization (domain models), 341

get( ) method, 434

character arrays, 607-608

character reference parameters, 606

overloading, 610

with no parameters, 604-606

GetAge( ) function, 153, 241

GetArea( ) function, 169

GetCount( ) function, 500

GetFirst( ) function, 500

getline( ) method, 608-610

GetString( ) function, 443, 544

GetUpperLeft( ) function, 169

GetWeight( ) function, 164

GetWord( ) function, 425

global variables

example, 110-112

limitations, 112, 134

goto statement, 176-177

greater than operator (>), 80

greater than or equal to operator (>=), 80

guidelines (use cases), 344-346

H

.h filename extension, 163

has-a relationships. See containment

headers

functions, 36, 267-268

namespaces, 645

heap. See free store

Hello World program

compiling, 17-18

creating, 19-20

running, 18

source code, 17, 25-26

testing, 19-20

Hello.cpp file, 17, 26

hex flag, 618

hexadecimal numbers, 813-816

converting to decimals, 813

escape characters, 59

hiding

compared to overriding, 389

methods, 387-389

history of C++, 5-7, 11

.hp filename extension, 163

.hpp filename extension, 163

Hungarian notation, 49

I

I/O objects, 597-598. See also streams

cerr, 598

cin, 598-600

extraction operator, 603-604

get( ) method, 604-608

getline( ) method, 608-610

ignore( ) method, 610-611

multiple input, 601-603

peek( ) method, 611-612

putback( ) method, 611-612

strings, 600-601

clog, 598

cout, 598

fill characters, 616-617

fill( ) method, 616-617

flags, 617-620

flush( ) method, 613

output width, 615-616

put( ) method, 613-614

setf( ) method, 617-620

width( ) method, 615-616

write( ) method, 614-615

identifiers

hiding, 639

naming, 781-782

If Horses Could Fly (code listing), 450-451

if statements, 80-82

branching, 81-82

else keyword, 84-85

indentation styles, 83-84

nesting

braces ({ }), 88-89

example, 86-87

semicolon notation, 83

syntax, 85

#ifndef command, 754

ignore( ) method, 610-611

imitating RTTI (Run Time Type Identification), 453

implementing

buffers, 597

classes, 165

containment, 552-553

methods, 151-154

const methods, 159

inline, 163-166, 326

pure virtual functions, 478-482

streams, 597

swap( ) function

pointers, 264-265

references, 265-267

include files, 784

include statement, 26, 38

inclusion guards, 755-756

increment functions, 303-304

increment operator (++), 74-76, 303-304

indenting code, 779

if statements, 83-84

switch statements, 780

indirection operator (*), 225-226, 280

inheritance, 10-11, 371-373

adding to two lists, 456

casting down, 453-455, 487

compared to templates, 712

constructors, 378-385

containment, 537

accessing members of, 545

compared to delegation, 553-561

constructors, 546-549

costs, 546-549

Employee class, 542-544

filtering access to, 545

implementing, 552-553

passing by value, 549-552

String class, 538-542

derivation, 372-376, 404

destructors, 378-381

limitations, 449-452

mixins, 473

multiple, 456-459

ambiguity resolution, 463-464

class design, 358-359

constructors, 460-463

declaring, 459

example, 457-459

limitations, 472

objects, 460

shared base classes, 464-468

virtual methods, 459

private, 562-563

compared to containment, 590

methods, 562

sample program listing, 563-570

usage tips, 571

shared functions, 452

virtual inheritance, 468-472

virtual methods, 391-397

copy constructors, 400-403

destructors, 399-400

invoking multiple, 393-395

memory costs, 403

slicing, 397-399

v-pointers, 396

v-tables, 396

initialization statement, 189

initializing

arrays, 413-414, 419

constructors, 297

for loops, 188-190

objects, 297

Cat, 156-157

constructor methods, 154

pointers, 224, 232

references, 257

static data members, 692

variables, 51

inline functions, 122-124, 163-166, 326, 771-772

inline statement, 122, 134, 163-164

input. See I/O (input/output)

Insert( ) function, 501, 700

insertion operator (<<), 28, 585-589

instantiating templates, 661

int data type, 46

integers

arrays, 409

division operations, 73

integer overflow, 72

long, 43, 53-54, 64

short, 43, 53-54

signed, 45, 55-56

sizes, 43-45

unsigned, 45, 54-55

interaction diagrams, 346-347

collaboration diagrams, 364

sequence diagrams, 363-364

state transition diagrams

end states, 364

start states, 364

super states, 365-366

interim values, printing, 769-771

intermediate files (compiler), 752

internal flag, 618

internal linkage, 641

internal nodes (linked lists), 885

International Standards Organization (ISO) Standard, 12

interpreters, 6

IntFillFunction( ) function, 682

Intrude( ) function, 670

invariants, 764-769

Invariants( ) method, 764-769

invoking methods, 35-36, 129, 133

base methods, 389-390

pointers to methods, 528

recursion, 124-125, 128

static, 511-513

ios class, 597

iostream class, 597

iostream library, 593

is-a relationships. See inheritance

ISO (International Standards Organization) Standard, 12

istream class, 597

Iterate( ) function, 501

iteration. See loops

J-K

Jacobson, Ivar, 332

jumps, 176

KB (kilobytes), 812

keywords, 49-50, 171, 817. See also statements

class, 141, 149-151, 662

const, 158, 172-173

delete, 235-237

else, 84-85

enum, 61

friend, 585

goto, 176-177

inline, 122, 134, 163-164

namespace, 31-32

new, 234

protected, 376

public, 152

return, 114-115

static, 642-643, 653

struct, 171

template, 662

typedef, 52-53, 525-528

using, 30-31

using declaration, 650-652

using directive, 648-650

kilobytes (KB), 812

L

%l conversion specifier, 621

%ld conversion specifier, 621

l-values, 71

labels, 176

last in, first out (LIFO), 703

leaks (memory), 235-237, 283-285

left flag, 618

less than operator (<), 80

less than or equal to operator (<=), 80

less than symbol (<), 28

less than operator, 80

less than or equal operator, 80

redirection symbol, 17

libraries, 594

defined, 15

iostream, 593

STL (Standard Template Library), 693

algorithms, 708-711

deque containers, 703

list containers, 701-702

map containers, 704-707

multimap containers, 708

multiset containers, 708

queues, 703

set containers, 708

stacks, 702-703

std namespace, 654-655

vector containers, 694-700

LIFO (last in, first out), 703

linkage

external, 641-642

internal, 641

linked lists, 444

advantages, 446

contravariance, 803-804

doubly linked, 875

example of, 876-884

nodes, 875, 885

sample program listing, 491-502

singly linked, 875

template-based, 791-803

trees, 875

virtual functions, 804-805

linkers, 6

lists, linked, 444

advantages, 446

contravariance, 803-804

doubly linked, 875

example of, 876-884

nodes, 875, 885

sample program listing, 491-502

singly linked, 875

template-based (code listing), 791-803

trees, 875

virtual functions, 804-805

literals, 59

local variables, 105-107

defining, 106

example, 106-107

persistence, 233

scope, 105-109

logic errors, 413

logical operators

AND (&&), 91

NOT (!), 92

OR (||), 91

order of evaluation, 92

precedence, 92-93

long data type, 53-54, 64

long integers, 43, 46, 64

loops, 175

do...while

compared to while loops, 205

example, 186

syntax, 187

endless

exiting, 202

switch statement, 201-204

while (true), 183-184

existing, 180-182

exiting, 180-182

Fibonacci series application, 196-198

for, 188-190

compared to while loops, 205

empty loops, 191-193

example, 188-189

initialization, 188

multiple initialization, 190

nesting, 193-195

null statements, 191-193

scope, 195-196

syntax, 189

goto keyword, 176-177

returning to top of, 180-182

while, 177

break statement, 180-183

compared to do...while loops, 205

compared to for loops, 205

complex loops, 179-180

continue statement, 180-182

exiting, 180-182

returning to top of, 180-182

simple example, 177-178

skipping body of, 184-185

starting conditions, 187-188

syntax, 178

while (true), 183-184

M

macros, 756-757

assert( ), 761-762, 784

debugging functions, 762

exceptions, 763

limitations, 763-764

source code, 761-762

compared to functions, 771

compared to templates, 771

defining, 757

disadvantages, 771

parentheses ( ), 757-759

predefined, 760

syntax, 757

when to use, 787

main( ) function, 27, 100

Managed Extensions to C++, 12

mathematical operators

combining with assignment operator, 73-74

modulus (%), 73

subtraction (-), 71-72

mathematical pointers, 423-426

max_size( ) function, 695

member functions. See methods

member variables. See data members

member-wise copies, 298, 318

memory, 130. See also pointers

addresses, 227-228

determining, 222-223

examining, 229-231

retrieving, 226

storing in pointers, 224-225

arrays, 421

code space, 130

examining, 747

free store

accessing, 239-241

advantages, 233-234

memory allocation, 234

objects, 238-239

pointers, 241-243

restoring, 235-237

leaks, 235-237, 283-285

RAM (random access memory), 42, 130-132

registers, 130

stack

clearing, 233

pulling data from, 132-133

pushing data onto, 130-133

virtual methods, 403

menu( ) function, 204

Meow( ) function, 148, 153

methodologists, 332

methods, 140. See also functions

base methods, 389-390

constructors, 154

calling multiple, 460-463

copy constructors, 298-302

defaults, 154-158, 295

initializing, 297

overloading, 294-296

declaring, 162-163

default values, 292-294

defining, 143-144

destructors, 154-158

friends, 580-585

get( ), 434

character arrays, 607-608

character reference parameters, 606

with no parameters, 604-606

overloading, 610

header files, 267-268

hiding, 387-389

implementing, 151-154

inline, 163-166, 326

overloading, 387

example, 289-292

when to use, 294

overriding, 385-387

pointers

arrays, 531-532

declaring, 528

example, 528-530

invoking, 528

public accessor methods, 147-148

static, 511-512

accessing, 513

advantages, 534

calling, 511-513

sample listing, 512

virtual, 391-397

calling multiple, 393-395

copy constructors, 400-403

destructors, 399-400

memory costs, 403

slicing, 397-399

v-pointers, 396

v-tables, 396

mimicking RTTI (Run Time Type Identification), 453

mixins, 473

models, 329-330. See also UML (Unified Modeling Language)

domain models, 339-341

association, 343

containment, 342-343

generalization, 341

dynamic models

collaboration diagrams, 364

sequence diagrams, 363-364

state transition diagrams, 364-366

static models, 354

modulus operator (%), 73

multidimensional arrays, 417-419

multiple base classes

ambiguity resolution, 463-464

constructors, 460-463

objects, 460

multiple exceptions, 729-732

multiple inheritance, 456-459

ambiguity resolution, 463-464

class design, 358-359

constructors, 460-463

declaring, 459

example, 457-459

limitations, 472

objects, 460

shared base classes, 464-468

virtual inheritance, 468-472

virtual methods, 459

multiple initialization, 190

multiple input (cin), 601-603

multiple values (functions), 268-271

multiple variables, defining, 50

N

escape code, 28-29, 58

name conflicts, 637-642

nameless temporary objects, 307-309

names

arrays, 427-428

capitalization, 782

classes, 141-142

counting variables, 195

filename extensions

.c, 14

.cpp, 14, 162

.h, 163

.hp, 163

.hpp, 163

.obj, 15

identifiers, 781-782

name conflicts, 637-642

pointers, 224

references, 256

spelling, 782

templates, 664

variables, 47-48

case-sensitivity, 48

Hungarian notation, 48-49

reserved words, 49-50, 817

namespace keyword, 31-32

namespaces, 637-638

adding members to, 645-646

aliases, 652

creating, 643-644

designating

namespace keyword, 31-32

std:: notation, 30

using keyword, 30-31

function definitions, 645

headers, 645

nesting, 646

sample program listing, 646-648

std, 654-655

type definitions, 644

unnamed, 652-653

unnamed namespaces, 656

NCITS (National Committee for Information Technology Standards), 12

negative numbers, 96

nesting

for loops, 193-195

if statements

braces ({ }), 88-89

example, 86-87

namespaces, 646

parentheses, 78

.Net platform, 785

new operator, 279

new statement, 234

new( ) function, 694

newline delimiter, 434

newline escape characters ( ), 28-29, 58

newsgroups, 785

nodes, 875, 885

nonexistent objects, referencing, 281, 283

nontemplate friends, 670-674

nonzero values, 96

not equal operator (!=), 80

NOT operator (!), 92

notation, Hungarian, 49

null character, 432, 601

null pointers, 224, 248, 262

null references, 262

null statement, 191-193

numbers

base 7, 809

base 8, 808-809

base 10, 808

converting to base 6, 810

converting to base 7, 809-810

binary, 811-812

counting, 183-184

Fibonacci series, 124-128, 196-198

hexadecimal, 813-816

negative numbers, 96

nonzero values, 96

nybbles, 812

O

object files, 15

object-oriented design

classes, 350

CRC cards, 354-357

data manipulation, 353

device protocols, 354

dynamic model, 363-366

preliminary classes, 351-352

relationships, 358-363

static model, 354

transformations, 352-353

views, 353

models, 329-330

process, 331-333

controversies, 335

iterative development, 332

methods, 332

Rational Unified Process, 332

requirements documents, 335-336

application analysis, 347

artifacts, 349-350

project budgets and timelines, 348

systems analysis, 347-348

use-case analysis, 336-347

visualizations, 349

UML (Unified Modeling Language), 330-331

vision statements, 335

object-oriented programming (OOP), 9, 137-138

data hiding, 10

encapsulation, 10

inheritance, 10-11

polymorphism, 11, 118-121

objects. See also specific object names

arrays, 416-417

compared to classes, 142

defining, 142, 150

derived, 377-378

free store objects, 238-239

initializing, 154, 297

passing, 397-399

passing references to, 277-279

referencing, 260-261

nonexistent objects, 281-283

objects on heap, 283-285

size of, 172

states, 617

template objects, 678-682

temporary

nameless, 307-309

returning, 306-307

values, assigning, 143

oct flag, 618

octal notation, 59

ofstream objects

arguments, 626

condition states, 624

default behavior, 626-628

opening files, 624-626

.ojb filename extension, 15

OOD. See object-oriented design

OOP. See object-oriented programming

opening files, 624-626

operators, 70-71

address of, 222-223, 257-258

assignment, 50, 71, 317-320

bitwise, 773-774

concatenation, 759-760

conditional, 94-95

conversion

creating, 321-323

sample program, 323-324

decrement, 74-76

dot, 150, 239

dynamic_cast, 453

extraction, 599, 603-604

increment, 74-76, 303-304

indirection, 226, 280

insertion, 585-589

logical, 91-92

mathematical

addition, 314-316

modulus, 73

self-assigned, 74

subtraction, 71-72

new, 279

ostream, 674

overloading, 302-303

addition, 314-316

friend functions, 580-585

guidelines, 317

limitations, 316-317

prefix operators, 304-306

temporary objects, 306-309

this pointer, 309-310

points-to, 240-241

postfix, 311-313

precedence, 77, 92-93, 819-820

redirection, 28, 598

reference, 256, 280-281

relational, 79-82

scope resolution, 640

true/false operations, 93-94

OR operators

bitwise, 774

logical, 91

ostream class, 597

ostream operator, 674-678

output. See also I/O (input/output)

flushing, 613

formatting, 622-623

fill characters, 616-617

flags, 617-620

width, 615-616

output devices, writing to, 613-614

output redirection operator (<<), 28

overloading

compared to overriding, 387

functions/methods, 118-121

constructors, 294-296, 381, 384

example, 289-292

when to use, 294

operators, 302-303

addition, 314-316

friend functions, 580-585

guidelines, 317

insertion, 585-589

limitations, 316-317

postfix, 311

prefix, 304-306

temporary objects, 306-309

this pointer, 309-310

overriding

compared to hiding, 389

compared to over-loading, 387

const default, 642

methods, 385-387

ownership of pointers, 285

P

p( ) function, 653

packages, 347

Pane class, 648

parameterized templates, 661

parameterized types. See templates

parameters, 36, 101, 113

command-line processing, 631-634

copy constructors, 298

defaults, 116-118

get( ) method, 606

macros, 757

passing

to base constructors, 381-385

by reference, 262-265, 271-274

by value, 109-110, 134, 263-264, 549-552

parentheses ( ), 96

macro syntax, 757-759

nesting, 78

parsing character strings, 423-425

partitioning RAM (random access memory), 130-132

PartsList class, 554-561

passing

exceptions, 739-742

objects, 397-399

parameters

by reference, 262-265, 271-274

by value, 109-110, 134, 263-264, 549-552

to base constructors, 381-385

pointers

const pointers, 274-277

pointers to functions, 523-525

references to objects, 277-279

template objects, 678-682

peek( ) method, 611-612

percolating shared functions, 452

period (.), 150, 239

persistence of variables, 233

pipe character (|), 91

piping, 598

plus sign (+)

addition operator, 314-316

increment operator, 74-76

prefix operator, 304-306, 311-313

Point class, 166-167

pointers, 221-224, 227-228

advantages, 232

allocating, 236

arrays, 421-423, 426-428

combining with references, 280

compared to references, 279-280

const, 248-251

declaring, 248-249

methods, 249-250

passing, 274-277

const this, 251

current values, printing, 769-771

data manipulation, 228-229

as data members on free store, 241-243

declaring, 224, 231

deleting, 235-236

dereferencing, 226, 232

function pointers

advantages, 517-520

arrays, 521-523

assigning, 517

declaring, 514

dereferencing, 520

example, 514-517

passing, 523-525

typedef statement, 525-528

indirection, 225

initializing, 224, 232

memory addresses

assigning, 224-225

examining, 229-231

retrieving, 226

memory leaks, 237

method pointers

arrays, 531-532

declaring, 528

example, 528-530

invoking, 528

naming, 224

null, 224, 248, 262

ownership, 285

passing by reference, 264-265

reassigning, 237

returning multiple values, 268-270

RTTI (Run Time Type Identification), 453

“stomping” on, 247

stray/dangling, 245-248

cautions, 247

compared to null pointers, 248

creating, 246-247

subtracting, 423-426

this, 243-245, 309-310

v-pointers (virtual function pointers), 396, 487

wild, 224

points-to operator (->), 240-241

polymorphism, 11, 118-121, 391, 449

pop_back( ) function, 700

pop_front( ) function, 702

postfix operator, 75-76, 311-313

pound symbol (#), 26

powertypes, 360-363

precedence of operators, 77, 92-93, 819-820

predefined macros, 760

prefix operators, 75-76

compared to postfix operator, 311-313

overloading, 304-306

preliminary classes, designing, 351-352

preprocessor, 26

class invariants, 764-769

commands

#define, 752-754

#else, 754-755

#ifndef, 754

inclusion guards, 755-756

inline functions, 771-772

interim values, printing, 769, 771

macros

assert( ), 761-764

compared to functions, 771

compared to templates, 771

defining, 756-757

parameters, 757

parentheses ( ), 757-759

predefined, 760

syntax, 757

string manipulation, 759-760

substitutions

constants, 753

strings, 752

tests, 753-754

printf( ) function, 636

compared to streams, 620-622

limitations, 620, 635

printing

characters, 57-58

interim values, 769-771

printf( ) function, 620-622

to screen, 28-30

private classes, 144-146

private data members, 376-377

accessing, 144, 147

advantages, 172

security, 148-149

private inheritance, 562-563

compared to containment, 590

methods, 562

sample program listing, 563-570

usage tips, 571

problem solving, 7-8

procedures, 8, 138. See also functions; methods

process of software design, 331-333

controversies, 335

iterative development, 332

methods, 332

Rational Unified Process, 332

program design, 329

classes, 350

CRC cards, 354-357

data manipulation, 353

device protocols, 354

dynamic model, 363-366

preliminary classes, 351-352

relationships, 358-363

static model, 354

transformations, 352-353

views, 353

models, 329-330

process, 331-333

controversies, 335

iterative development, 332

methods, 332

Rational Unified Process, 332

requirements documents, 335-336

application analysis, 347

artifacts, 349-350

project budgets and timelines, 348

systems analysis, 347-348

use-case analysis, 336-347

visualizations, 349

UML (Unified Modeling Language), 330-331

vision statements, 335

programming. See also program design

comments, 32-33, 38

/* (C-style), 33

// (C++-style), 33

cautions, 34

example, 33-34

writing, 39

development cycle, 16

development environments, 14

executable files, 15

levels of abstraction, 129

object files, 15

object-oriented, 9, 137-138

data hiding, 10

encapsulation, 10

inheritance, 10-11

polymorphism, 11, 118-121

problem solving, 7-8

program branching, 132-133

program design, 13-14

program structure, 25-28

# (pound) symbol, 26

include statements, 26, 38

main( ) function, 27

resources, 785

structured, 8-9

style guidelines

access labels, 783

assert( ) macro, 784

capitalization, 782

class definitions, 783

comments, 782-783

const statement, 784

identifier names, 781-782

include files, 784

readability of code, 780-781

spelling, 782

programs. See also program design; programming

branching, 132-133

comments, 32-33, 38

/* (C-style), 33

// (C++-style), 33

cautions, 34

example, 33-34

writing, 39

compilers, 6, 19, 752

assert( ) macro, 761-762

compiling with symbols, 747

errors, 20-21

intermediate files, saving, 752

troubleshooting, 20

debugging, 746-747

assemblers, 747

assert( ) macro, 762-764

breakpoints, 747

examining memory, 747

inclusion guards, 755-756

printing interim values, 769-771

watch points, 747

defined, 7

designing, 13-14

Hello World

compiling, 17-18

creating, 19-20

running, 18

source code, 17, 25-26

testing, 19-20

interpreters, 6

linkers, 6

structure of, 25-28

# (pound) symbol, 26

include statements, 26, 38

main( ) function, 27

protected data members, 376-377

protected keyword, 376

prototypes, 101-104

defined, 101

parameters, 267-268

return types, 103

public accessor methods, 147-148

public classes, 144-146

public keyword, 152

pulling data from stack, 133

pure virtual functions, 477-482

push_back( ) function, 695

push_front( ) function, 702

pushing data onto stack, 132-133

put( ) method, 613-614

putback( ) function, 635

putback( ) method, 611-612

Q-R

question mark (?), 59

quotation marks (“), 759

escape code, 58

r-values, 71

RAM (random access memory), 42, 130-132

Rational Unified Process, 332

readability of code, 780-781

reading data in exceptions, 735

reassigning

pointers, 237

references, 259

Rect.cpp, 168-169

Rectangle class

declaring, 168-170, 210-216, 296

DrawShape( ) method, 290-291

recursion, 124-128

Fibonacci series example, 125-128

stop conditions, 124-125

redirect input command (<), 598

redirect output command (>), 598

redirection (streams), 598

redirection operators, 17, 28, 598

reference operator (&), 256, 280-281

references, 255-257

combining with pointers, 280

compared to pointers, 279-280

const pointers, 274-277

creating, 256-257, 262

errors

nonexistent objects, 281-283

referencing objects on heap, 283-285

initializing, 257

naming, 256

null, 262

objects, 260-261

nonexistent objects, 281-283

objects on heap, 283-285

passing by reference, 262-265, 271-274

passing to objects, 277-279

reassigning, 259

returning multiple values, 270-271

swap( ) function, 265-267

target addresses

assigning, 259-260

returning, 257-258

relational operators, 79-80

branching, 81-82

precedence, 92-93

relationships (classes)

containment, 358-359

discriminators, 360-363

multiple inheritance, 358-359

powertypes, 360-363

remove( ) function, 700

requirements documents, 335-336

application analysis, 347

artifacts, 349-350

project budgets and timelines, 348

systems analysis, 347-348

use-case analysis, 336-337

actors, 337

customer roles, 337-339

domain models, 339-343

guidelines, 344-346

interaction diagrams, 346-347

packages, 347

scenarios, 343-344

visualizations, 349

reserved words, 49-50, 817

resizing arrays at runtime, 429-432

resolving name conflicts, 638-642

resources, 785

responsibilities (CRC sessions), 355

restoring memory to free space, 235-237

retrieving data in exceptions, 735

return statements, 36, 114-115

return values (functions), 36, 100-103, 114-115

returning

multiple values

pointers, 268-270

references, 270-271

temporary objects, 306-309

reusing source code, 10-11

right flag, 618

RTTI (Run Time Type Identification), 453

Rumbaugh, James, 332

Run Time Type Identification (RTTI), 453

run-time binding, 395

running

functions, 105

Hello World program, 18

runtime, resizing arrays at, 429-432

S

%s conversion specifier, 620

scenarios (use cases), 343-344

scientific flag, 618

scope

for loops, 195-196

variables, 105-109, 640-641

visibility, 640

scope resolution operator (::), 640

screens, printing to, 28-30

security, 148-149

self-assigned addition operator (+=), 74

semicolon (;), 68, 83

sequence diagrams, 363-364

sessions (CRC), 354-355

SetAge( ) method, 153, 241

setf( ) method, 617-618, 620

SetFirstName( ) function, 544

SetLastName( ) function, 544

sets, 444

setw manipulator, 618

shallow copies, 298, 318

Shape classes, 474-476

shared base classes, 464-468

short data type, 53-54, 64

short int data type, 46

short integers, 43, 46

showbase flag, 618

ShowMap( ) function, 707

showpoint flag, 618

showpos flag, 618

ShowVector( ) function, 699

signed integers, 45, 55-56

Simonyi, Charles, 49

single character input, 604

single quote (’), 58

singly linked lists, 875

sizeof( ) operator, 45

sizes

arrays, 415, 429-432

class objects, 172

functions, 112

variables, 43-46

slash (/), 33

slicing virtual methods, 397-399

software. See programs

solving problems, 7-8

solving the nth Fibonacci number (listing), 196

source code. See code

source files, 14

spaces, 96

specialized constructors, 688

specialized functions, 683-688

stack (memory), 130-132, 233

clearing, 233

pulling data from, 132-133

pushing data onto, 130-133

standard I/O objects, 597-598

cerr, 598

cin, 598-600

extraction operator, 603-604

get( ) method, 604-608

getline( ) method, 608-610

ignore( ) method, 610-611

multiple input, 601-603

peek( ) method, 611-612

putback( ) method, 611-612

strings, 600-601

clog, 598

cout, 598, 613-620

fill characters, 616-617

flags, 617-620

flush( ) method, 613

output width, 615-616

put( ) method, 613-614

write( ) method, 614-615

standard namespace, 654-655

namespace keyword, 31-32

std:: notation, 30

using keyword, 30-31

state flags, 615-617

state member data, 533

state transition diagrams

end states, 364

start states, 364

super states, 365-366

statements, 68. See also keywords

blocks, 68-69

catch, 719

try, 719-722

break, 180-183

catch, 719, 722, 729-732

class, 141, 149-151, 662

compound, 68-69

const, 60, 158, 172-173, 784

continue, 180-182

default, 200

#define, 60

constant substitutions, 753

string substitutions, 752

tests, 753-754

delete, 235-237, 429

do...while, 187

#else, 754-755

expressions, 69-70, 78

friend, 585

function prototypes, 104

goto, 176-177

if, 80-82

branching, 81-82

else keyword, 84-85

indentation styles, 83-84

nesting, 86-89

semicolon notation, 83

syntax, 85

include, 26, 38

initialization, 189

inline, 122, 134, 163-164

new, 234

null, 191-193

protected, 376

return, 36, 114-115

statements in functions, 112

struct, 171

switch

case values, 199

example, 199-200

forever loops, 201-204

guidelines, 204

syntax, 198-200

syntax, 68

template, 662

try, 719-722

typedef, 525-528

watch, 787

while

complex loops, 179-180

simple example, 177-178

syntax, 178

whitespace, 68

states (objects), 617

state transition diagrams, 364-366

static keyword, 642-643, 653

static member data, 506-508

accessing, 692

nonstatic methods, 510-511

without objects, 508-509

declaring in templates, 689-692

defining, 507

example, 506-507

initializing, 692

static member functions

accessing, 513

advantages, 534

calling, 511-513

sample listing, 512

static model, 354

std namespaces, 654-655

STL (Standard Template Library), 693

algorithms

function objects, 708-709

mutating sequence operations, 710-711

nonmutating sequence operations, 709-710

deque containers, 703

list containers, 701-702

map containers, 704-707

multimap containers, 708

multiset containers, 708

queues, 703

set containers, 708

stacks, 702-703

vector containers

adding elements to, 695

creating, 694

defined, 694

empty vectors, 695

sample program listing, 696-700

“stomping” on pointers, 247

stop conditions, 124-125

storing

arrays

on free store, 421-423

on stack, 421

memory addresses in pointers, 224-225

stray pointers, 245-248

cautions, 247

compared to null pointers, 248

creating, 246-247

strcpy( ) function, 435

streambuf class, 597

streams, 593-594

buffers, 594-596

flushing, 596

implementing, 597

compared to printf( ) function, 620-622

encapsulation, 594

ofstream class, 624

condition states, 624

default behavior, 626-628

opening files, 624-626

redirection, 598

standard I/O objects, 597-598

cerr, 598

cin, 598-612

clog, 598

cout, 598, 613-620

String classes, 436-441, 538-542, 545

constructors, 441

declaring, 437-443

destructor, 442

operators

implement, 442

offset, 442-443

overloaded operators, 441

strings

concatenating, 759-760

copying, 435-436

current values, printing, 769-771

defined, 28

null character, 601

parsing, 423, 425

placing in quotes, 759

String classes, 436-441, 538-542, 545

constructors, 441

declaring, 437-443

destructor, 442

operators, 441-443

stringizing, 759

substitutions, 752

testing, 753-754

strncpy( ) function, 435-436

strong typing, 159

Stroustrup, Bjarne, 11

struct keyword, 171

structured programming, 8-9

structures, 138, 171-173

style guidelines (code)

access labels, 783

assert( ) macro, 784

braces, 779

capitalization, 782

class definitions, 783

comments, 782-783

const statement, 784

identifier names, 781-782

include files, 784

indents, 779-780

long lines, 780

readability of code, 780-781

spelling, 782

subclasses, 166-171

subtracting pointers, 423-426

subtraction operator (-), 71-72

supersets, 372

swap( ) function, 110

pointers, 264-265

references, 265-267

switch statement

case values, 199

example, 199-200

forever loops, 201-204

guidelines, 204

indenting, 780

syntax, 198-200

symbolic constants, 59-60, 64

systems analysis, 347-348

T

escape code, 30, 58

tables, v-tables, 396

tabs, 30, 58, 96

tail nodes (linked lists), 885

target addresses

assigning, 259-260

returning, 257-258

temperatures, Fahrenheit/Celsius conversions, 106

template keyword, 662

templates, 659-661

compared to inheritance, 712

compared to macros, 771

compiler support, 665

defining, 661-664

exceptions, 742-745

friends

general, 674, 678

general template friends, 674-678

nontemplate, 670-674

functions, 669-670, 683-688

implementing, 665-669

instantiating, 661

naming, 664

parameterized, 661

passing template objects, 678-682

static data members, 689-692

STL (Standard Template Library), 693

algorithms, 708-711

deque containers, 703

list containers, 701-702

map containers, 704-707

multimap containers, 708

multiset containers, 708

queues, 703

set containers, 708

stacks, 702-703

vector containers, 694-700

template-based linked lists, 791-803

temporary objects

nameless, 307-309

returning, 306-307

ternary operator (?:), 94-95

testing

Hello World program, 19-20

strings, 753-754

text editors, 14

built-in editors, 22

compared to word processors, 21

text files, 629-631

text strings, 28

this pointer, 243-245, 251, 309-310

throwing exceptions, 722-728

tilde (~), 154, 774

timelines (design projects), 348

trailing zeros, displaying, 617

transformations, 352-353

transforming CRC cards to UML, 357

trees, 875

troubleshooting. See also debugging

bugs, 716

code rot, 746

compile-time errors, 162

compilers, 20

exceptions, 717-718

advantages, 748

catching, 728-732

class hierarchies, 732-735

disadvantages, 749

hierarchies, 733

multiple, 729-732

programming tips, 745-746

sample program, 717-718

templates, 742-745

throwing, 722-728

try...catch blocks, 719-722

logic errors, 159-162

true/false operations, 93-94

try blocks, 719-722

two-dimensional arrays, 418-420

type definition, 52-53

typedef statement, 52-53, 525-528

types. See data types

typing, strong, 159

U

UML (Unified Modeling Language), 330-331, 357

uninitialized array elements, 445

uninitialized buffers, 433-434

uninitialized character arrays, 433

unnamed namespaces, 652-653, 656

unsigned int data type, 46

unsigned integers, 45-46, 54-55

unsigned long int data type, 46

unsigned short int data type, 46

Uppercase flag, 618

use-case analysis, 336-337

actors, 337

customer roles, 337-339

domain models, 339-341

association, 343

containment, 342-343

generalization, 341

guidelines, 344-346

interaction diagrams, 346-347

packages, 347

scenarios, 343-344

Usenet newsgroups, 785

user-defined classes, 320-321

using keyword, 30-31

using declaration, 650-652

using directive, 648-650

V

v escape code, 58

v-pointers, 396

v-ptr (virtual function pointer), 396, 487

v-tables, 396

value, passing by, 109-110, 134, 549-552

values

assigning to variables, 50-52, 143

concatenating, 30

enumerated constants, 61

function return values, 36

multiple

returning with pointers, 268-270

returning with references, 270-271

passing

by reference, 262-265, 271-274

by value, 263-264

to cout, 29

variable values

assigning, 50-52

defined, 47

variables, 41-42. See also constants; pointers

assigning, 320-321

char, 43

character encoding, 57

escape characters, 58-59

sizes, 56

counting variables, 195

current values, printing, 769-771

data members, 140

data types, 46, 139

defining, 42-43, 47-50

example, 51-52

floating-point, 46

function pointers, 514

global

example, 110-112

limitations, 112, 134

initializing, 51

integers

long, 53-54

short, 53-54

signed, 45, 55-56

sizes, 43-45

unsigned, 45, 54-55

local, 105-107

example, 106-107

persistence, 233

scope, 107-109

names, 47-48

case-sensitivity, 48

Hungarian notation, 48-49

reserved words, 49-50, 817

scope, 105, 640-641

sizes, 43-46

type definition, 52-53

values

assigning, 50-52, 143

defined, 47

vertical bar (|), 91

vertical tab escape characters (v), 58

views, 353

virtual functions, 391-397, 404, 487

copy constructors, 400-403

destructors, 399-400, 488

exceptions, 739-742

linked lists, 804-805

memory costs, 403

multiple, calling, 393-395

pointers, 396, 487

pure, 477-482

slicing, 397-399

v-pointers, 396

v-tables, 396

virtual inheritance, 468-472

declaring, 472

example, 469-471

visibility, 640

vision statements, 335

visualizations, 349

void value, 114

W-Z

warning messages, 22

watch points, 747

watch statements, 787

while (true) loops, 183-184

while loops, 177

break statement, 180-183

compared to do...while loops, 205

compared to for loops, 205

complex loops, 179-180

continue statement, 180-182

do...while, 186-187

exiting, 180-182

returning to top of, 180-182

simple example, 177-178

skipping body of, 184-185

starting conditions, 187-188

syntax, 178

while (true), 183-184

whitespace, 68, 96

width( ) method, 615-616

wild pointers, 224

Window namespace, 646-648

word processors, 14, 21

wrapping

signed integers, 55-56

unsigned integers, 54-55

write( ) method, 614-615

writing

classes to files, 629-631

comments, 39

increment functions, 303-304

to output devices, 613-614

past the end of arrays, 410-413

xhhh escape characters, 59

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.158.36