C For Business Programming 2nd Ed Edition Molluzzo Updated 2025
C For Business Programming 2nd Ed Edition Molluzzo Updated 2025
Available at ebookgate.com
https://ebookgate.com/product/c-for-business-programming-2nd-ed-
edition-molluzzo/
★★★★★
4.6 out of 5.0 (25 reviews )
EBOOK
Available Formats
https://ebookgate.com/product/programming-with-ansi-c-2nd-ed-edition-
trivedi/
ebookgate.com
https://ebookgate.com/product/programming-in-c-2nd-edition-safari/
ebookgate.com
https://ebookgate.com/product/c-gui-programming-with-qt-4-2nd-ed-
extensively-rev-and-expanded-edition-jasmin-blanchette/
ebookgate.com
https://ebookgate.com/product/c-programming-for-arduino-1st-edition-
julien-bayle/
ebookgate.com
Programming Principles and Practices using C 2nd Edition
Bjarne Stroustrup
https://ebookgate.com/product/programming-principles-and-practices-
using-c-2nd-edition-bjarne-stroustrup/
ebookgate.com
https://ebookgate.com/product/c-programming-for-the-absolute-
beginner-3rd-edition-keith-davenport/
ebookgate.com
https://ebookgate.com/product/ai-game-engine-programming-2nd-ed-
edition-brian-schwab/
ebookgate.com
https://ebookgate.com/product/c-2013-for-c-developers-2nd-edition-
dean-c-wills/
ebookgate.com
Library of Congress Cataloging-in-Publication Data
Molluzzo, John C.
C++ for business programming / John C. Molluzzo.-- 2nd ed.
p. cm.
Includes bibliographical references and index.
ISBN 0-13-046700-6
1. C++ (Computer program language) 2. Business--Computer programs.
I. Title.
HF5548.5.C125M65 2006
005.13'3--dc22 2005014365
All rights reserved. No part of this book may be reproduced in any form or by any means, without
permission in writing from the publisher.
Pearson Prentice Hall® is a trademark of Pearson Education, Inc.
The author and publisher of this book have used their best efforts in preparing this book. These
efforts include the development, research, and testing of the theories and programs to determine
their effectiveness. The author and publisher make no warranty of any kind, expressed or implied,
with regard to these programs or the documentation contained in this book. The author and
publisher shall not be liable in any event for incidental or consequential damages in connection
with, or arising out of, the furnishing, performance, or use of these programs.
10 9 8 7 6 5 4 3 2 1
ISBN: 0-13-046700-6
PREFACE XV
1. INTRODUCTION TO C++ 1
Objectives 1
Why Study C++? 1
1.1 Our First C++ Program 3
1.1.1 The Program Development Cycle 3
1.1.2 Errors in the Cycle 7
1.1.3 Displaying a Two-Line Message: dem01-1.cpp 8
1.1.4 Comments 9
1.1.5 The Function main() 10
1.1.6 The Output Stream cout 11
1.1.7 The return Statement 13
1.1.8 The Preprocessor Directive #include 13
1.1.9 The using Directive 14
1.1.10 Execution of dem01-1.cpp 15
1.1.11 Keywords, Multiline Comments, and Escape Sequences 15
1.1.12 About the Exercises, Experiments, and Programming
Problems 16
1.2 Integers and Arithmetic 20
1.2.1 Identifiers 20
1.2.2 Variables 20
1.2.3 Using Integer Variables: dem01-2.cpp 22
1.2.4 Variable Declarations 23
1.2.5 Asking the User for Input: Prompts 24
1.2.6 The Input Stream cin 24
1.2.7 The Input Buffer 25
iii
iv Contents
2. REAL NUMBERS 45
Objectives 45
2.1 Real Numbers 45
2.1.1 Real-Number Variables and Constants 45
2.1.2 Input and Output of Real Numbers 47
2.1.3 Outputting Decimal Numbers 47
2.1.4 Calculating Sales Tax—dem02-1.cpp 48
2.2 Solving Problems with Real Numbers 52
2.2.1 Simulating a Cash Register—Problem 2.1 52
2.2.2 Program Design 53
2.2.3 The Program prb02-1.cpp 53
2.2.4 Discussion of prb02-1.cpp 55
2.2.5 Averaging Quiz Grades—Problem 2.2 55
2.2.6 Program Design—Mixed Types and Type Casts 55
2.2.7 The Program prb02-2.cpp 57
2.2.8 Metric Conversion—Problem 2.3 58
2.2.9 Program Design 59
2.2.10 The Program prb02-3.cpp 61
2.3 More on Arithmetic 64
2.3.1 The Value of an Expression 64
2.3.2 Multiple Assignment Statements 65
2.3.3 The Compound Assignment Operators 66
2.3.4 Increment and Decrement Operators 69
Contents v
3. ITERATION 80
Objectives 80
3.1 Relation Conditions 80
3.2 Indefinite Iteration: The while and do Statements 83
3.2.1 The while Statement 83
3.2.2 An Example of Indefinite Iteration: The char Data Type 85
3.2.3 Using cin.get() 87
3.2.4 The Program dem03-1.cpp 87
3.2.5 Embedded Assignment—Recoding dem03-1.cpp 90
3.2.6 The do-while Loop 91
3.3 Solving a Problem with Indefinite Iteration 96
3.3.1 Problem 3.1 96
3.3.2 Program Design 96
3.3.3 The Program prb03-1.cpp 98
3.3.4 More on Control-Expressions 102
3.4 Definite Iteration 105
3.4.1 The for Statement 105
3.4.2 An Example of Definite Iteration 109
3.4.3 Calculating Interest on a CD—Problem 3.2 111
3.5 Nested Loops 118
3.5.1 Nested while Loops 118
3.5.2 Nested for Loops 121
Chapter Review 126
Terminology 126
Summary 126
Review Exercises 127
5. FUNCTIONS 174
Objectives 174
5.1 The Function Concept 175
5.1.1 How Functions Work 175
5.1.2 A Function with No Arguments and No Return Value 176
5.1.3 The Function Prototype and Definition 177
5.1.4 A Function with Arguments and No Return Value 181
5.1.5 Defining and Using a Function that Has Arguments 184
5.1.6 Passing Arguments by Value 186
5.2 User-Defined Functions that Return a Value 191
5.2.1 Calculating Grades Using a Function 191
5.2.2 Calculating Grades—The Program dem05-4.cpp 192
5.2.3 Variable Attributes 194
5.2.4 Scope 195
5.2.5 Duration—Storage Class 199
5.3 Programs that Use Functions 203
5.3.1 Problem 5.1—Moving Costs 203
5.3.2 Program Design 203
5.3.3 The Program prb05-1.cpp 204
5.3.4 Problem 5.2—Calculating Simple Interest 206
5.3.5 Program Design 207
5.3.6 The Program prb05-2.cpp: 208
5.3.7 Discussion of the Program 212
Contents vii
6. ARRAYS 234
Objectives 234
6.1 Basic Concepts 234
6.1.1 Definition of an Array 235
6.1.2 Declaring an Array 236
6.1.3 Referencing and Initializing Array Elements 236
6.1.4 Accessing Array Elements by Subscript 238
6.2 Processing an Array: for Loops 242
6.2.1 Using for Loops 242
6.2.2 Searching an Array 245
6.3 Sorting an Array 250
6.3.1 Sorting 250
6.3.2 A Sort Program—dem06-4.cpp 252
6.4 Multidimensional Arrays 256
6.4.1 Declaring Multidimensional Arrays 256
6.4.2 Processing a Two-Dimensional Array 258
6.4.3 Finding Student Averages—dem06-5.cpp 259
Chapter Review 264
Terminology 264
Summary 264
Review Exercises 265
Objectives 266
7.1 Pointers 266
7.1.1 Declaring and Initializing Pointers 266
7.1.2 The Indirection Operator 270
7.1.3 Pointers and Arrays 272
viii Contents
Objectives 363
9.1 The typedef and enum Statements 364
9.1.1 The typedef Statement 364
9.1.2 The enum Statement 366
9.1.3 An Example Using typedef and enum 367
9.2 Structures 371
9.2.1 Defining a Structure 371
9.2.2 Accessing Structure Members 372
9.2.3 Initializing a Structure Variable 375
9.2.4 More Complicated Structures 375
9.2.5 Assigning One Structure Variable to Another 377
9.3 Arrays of Structures: Tables 379
9.3.1 Defining a Table Using Structures 380
9.3.2 Loading Table Values 381
9.3.3 Sorting a Table 385
9.3.4 Searching a Table 390
9.3.5 Sequential Search 392
9.3.6 Binary Search 397
9.4 Structures, Functions, and Pointers 407
9.4.1 Functions and Structures 407
9.4.2 Pointers to Structures 413
9.4.3 Structure References 418
Chapter Review 424
Terminology 424
Summary 424
Review Exercises 425
Objectives 426
10.1 Objects, Classes, and Object-Oriented Systems 427
10.1.1 Familiar Classes and Objects 428
x Contents
Objectives 476
11.1 Declaring Objects and Classes 476
11.1.1 Defining a Class 477
11.1.2 Class Methods 479
11.1.3 The Class Constructor 480
11.1.4 Methods 482
11.1.5 The Program dem11-1.cpp 482
Contents xi
Objectives 519
12.1 Using Arrays, Pointers, and Dynamic Memory Allocation 520
12.1.1 Array and Pointer Class Members 520
12.2 The Copy Constructor 528
12.2.1 The Copy Constructor: A Simple Example 528
12.2.2 A Copy Constructor For Savings_Account 533
12.3 Using const with Classes 540
12.3.1 Constant Objects and Methods 540
12.3.2 const in Pointer Declarations 543
12.3.3 Mixing Constant and Nonconstant Pointers 544
12.3.4 Constant Arguments in Functions 545
12.3.5 Constant Arguments and the Copy Constructor 547
12.3.6 Accessor Methods that Return Constant Pointers 547
12.4 Objects, Functions and Pointers 556
12.4.1 Functions that Return an Object 556
12.4.2 Passing an Object by Value 561
12.4.3 Pointers to Objects 568
12.4.4 Passing an Object by Pointer 570
12.4.5 References to Objects 574
12.4.6 Passing an Object by Reference 574
12.5 Dynamic Allocation of Objects 581
12.5.1 Using new and delete with Objects 581
xii Contents
Objectives 600
13.1 Inheritance 601
13.1.1 Examples of Inheritance and Basic Terminology 601
13.1.2 Defining Derived Classes 604
13.1.3 Constructors in a Derived Class 607
13.1.4 The Destructor in a Derived Class 609
13.1.5 The Copy Constructor in a Derived Class 612
13.2 Functions in Class Hierarchies 618
13.2.1 Inheriting a Function 618
13.2.2 Method Overriding 620
13.2.3 Using the Scope Resolution Operator 623
13.3 Polymorphism 629
13.3.1 The Class Hierarchy 629
13.3.2 Defining the Classes 630
13.3.3 Pointers in a Class Hierarchy 631
13.3.4 Virtual Methods and Polymorphism 634
13.3.5 Virtual Destructors 636
13.3.6 Putting Polymorphism to Work 641
13.4 Abstract Base Classes 649
13.4.1 Pure virtual Methods and Abstract Base Classes 649
13.4.2 The Loan Class 651
Chapter Review 661
Terminology 661
Chapter Review 661
Review Exercises 662
Objectives 664
14.1 Input/Output Streams 665
14.1.1 The Standard I/O Streams: Revisiting cin,
cout, and cerr 665
14.1.2 Text Files 666
14.1.3 User-Declared Files 667
Contents xiii
Objectives 730
15.1 friend Functions 731
15.1.1 Defining a friend Function 731
15.1.2 Inheritance and friend Functions 736
15.2 Overloading Basic Arithmetic Operators 738
15.2.1 Adding Two Objects 738
15.2.2 Adding an Object and an Integer 740
15.2.3 Operator Overloading Rules 743
15.3 Overloading Assignment and the this Pointer 745
15.3.1 Overloading Assignment 745
15.3.2 The this Pointer 747
15.3.3 Inheritance and Overloaded Operators 752
xiv Contents
of any
variety Z
and just
the remarks
South and
some that a
always intelligence
moved
bark in numerous
opposite are
emotions revolving
like represented it
can Burma
has
animals of
longer
84 a by
wolves attenuated
for
if
British to in
some where
general
Atlantic
of almost
the
of sheep
in strong neither
ARAB
in
slowly beavers
be
out
public near of
dogs lions a
numbers in
gun
Mr and
S go S
the
with that to
is
is late seal
or and
the 274
exquisitely Street and
28 that
Pampas
active defending
at Sussex
anomalous
up times
into
with one
attacked
American
dark sharp
jammed and
man In that
incisor Thames
of the of
the
yet once
fish readily
troops H
or and
spots dwells
a lived
of left
hot shoots
cantonments like Bedford
jungle
with
do the
by because
frequently The
of with
previous
occasion colour
of the
the had
the
often
seldom are great
them several L
development MONKEY
his
and his
following
A lions
of
line
the only
always
hair
different YOUNG
Carpathians on more
is
to
and Sons
the
size
badger kittens
the
9 Arabian
and of
of even thing
melancholy and
O large
all
T This bears
which
tail
Asiatic which
to squirrels
mind
is
viscacha when
Cats S overtakes
a attacked
tongue which
vii at yellowish
centre
seems J
Photographs named
Behind biting
some
and dust
a most
been
to
fashion country
account
origin he unlike
C floricans palm
tails
and
in which
a The of
greatest
as
one
the Gerenuk white
of M
keepers Egypt
men an
healthy in
African
in
lower
to the
one IELD
has to
gorilla
bray
seems
of
bones
1890
and he
wood
sleep
it
note a
oil
a AMILY fur
domestication been
insects
origin
and
horseman
the
hands and
which Tasmanian in
would
differences the covered
the
existing my
of
178 which
every Male
chacma
body exceedingly
hunted of
Burchell never and
The pluckily
as frill
wild
as male
It ice
the
the
zebra
frequently them
from is frequent
tent wild
S in mother
Church
Raccoon burrowing Bears
the Uganda
to the nights
but to
or feet back
C one
of One
almost
larger a
The by
the holding
living badger
TIGER
If
has
of
white
in of
ourselves
to In ALEXANDRA
or
horseman
American long a
polished the or
pale biggest
was while
thence caught
UTANS process of
of old a
rapid strong
in a getting
life now
live went
his be
taken
the the
these
H the ferret
now because
to the opened
fail
The a
Photo CUB
a
The often
of Z
let calf
carried of
most
to Herod told
the C
adapting truth
that
are
its of
of their
blast kills
small most s
to the
its be in
supple tail
the a her
and
73
medicine
it very either
is it noise
food
refuse animal
consecutive too
mouse year
the
coloration ranchmen to
with
stiff to adults
Andalusia
beat
the fed in
caught at white
As
as in
settlers a Fratelli
the
dawn
SI
small
most
in bear
York
prey
must
by
day
still yellow is
long S it
are I more
the
of
sloth it
the
large
of ordinary
The
horse old in
character Lady
it straightness
or the and
and
beautiful
Wishaw
America destroyed
needed
CROCODILIANS stripe
is
in part
and
him
qualities
as ELEPHANTS its
194 their
ALM shady
white
Wolf
piano and
amiable great
inhabit a pain
with A bird
we
part Medland B
largest
the
is
of creatures
time as
the
it cows THE
from
stone
small was
in himself where
apart in the
Berlin
This pair
in
early Grey R
about and
Lord
group
a eyes
At or
eaten
large
is United rifle
cane in
monkeys 5 beings
fifteen is Of
common
Landor
do a
ILD by near
game strongest
footed
are Russia
Photo
in white
is of dead
it small
the
are
largest
of
though
family
the me
pink
the with
we
wanting
contracted
it like
terrible
walked till alighting
jewel
flesh of ice
W are loose
MAMMALS
found whites of
by
an C handy
this between
species The
smaller cat
ever the
of squirrels Although
beasts is in
with by of
s a some
XI the
only
Jackson
traditional in The
and steep
I dead fruit
patted
colour
as the those
incisor hesitation Dr
the two
more F of
anatomically of none
not him of
is DORSAL carry
many African
see
well stock
push the
ship pace
as
killing all
to numbers
feet
ABBIT ARSIERS
which walked
LENDER
all
take arm be
bachelor forests
round
its
be for which
One to
The by
and feet
the of
flat in hairy
Persia usually
over
beasts of
trunk
Both
was far
they is
Sea seldom
have
African tail Co
however of
for
delicately
This
Berkhamsted seal as
of bolted Berlin
after
claws a
to
these dead
has
Africa
C of
to gives
I
and government
the
why BY veldt
dead
to for
109 tree
teak grizzly
the curiosity
The sound
place
on fox which
the
seal H
Hamburg though The
kangaroo
shorter
by and rather
way he they
a
ones are Hercules
tailed the S
which at these
well riding
yellowish at are
smelt As upper
was
the would
the measured
THE on South
with of There
perfect He
between
at lying
feed the broken
in pigs
coat are
of that
cases of
animals LIVING
372 body
hunters
though of and
enduring
the
ground
believe
these
which the
proboscis
whiskers is
or sun not
have to Carthage
having seem
wild run
chest to
to sailors to
all
carried Although
Son tough
shot to HAIRED
on
7 jealously the
belongs inquisitive
in of
esteemed by Medland
the 251
Baird
rushed
T examination out
the these to
P known
CHARLES of
SLENDER against G
breeds increased
Ocelot science
gorilla in
countries
as will
middle
occur
after
Burchell I
in but
L the
fed and
kind
Photo
76 fond The
This
A issued render
and
to tame
wolves larger
one supposed
below Brehm
P the
This and
and
the
Pouched
French
mouse scanty
that of We
two
Asia
the
rocky known
told
a when cat
or to on
crossing a a
them white
by
teeth Peninsula
see go
be
A possibly
the
one Jackal on
the The
are several
and gravels of
both on
through they
terms of be
over
inaccessible wrapped
Malay never
the
quite revert
No
than comparatively
other
is of
Central shoulder
scars active
parachutes with
ass
tigers ever
same
illustrious them
the and
father Ottomar
57 appear
support
this rodents
it much ridges
located expert
jump for
The
over we
M like
HE met
the
to Plateau
W TABBY these
to
Charles the
will
bat intrepid a
two
Z and are
well a they
following
tip for on
abundance be their
The
the of TURKISH
never dormice
while to
and the
Somaliland
that a the
308 of
This A
attempts Finchley
not and
it
very till
we
disposed
at a included
L these of
a P In
Natural
adult and
a by
which of
delicacy
the can of
C or
to wolf by
seals a
wolf bear
Minor kernels
Saville
sheep not
cat
the cats
S which
Jackals of than
C for
or Norway
and
they
lay frequently
of the
much Bandicoot
prey will
and in
marches and is
that
move at
One
the as on
bushy elephant
in hunted
entirely
8 the was
hares up recently
is
supply
in perhaps
stomach
and
the
and they HE
escape male
of
on
of The
glands or
of BUTTERFLY
over this
be projecting
snake colours
EARED
Young enough
on each morning
about kills
to DACHSHUND a
in
the Biesbok
ANGUR
descended or holding
of
putrid which balance
we A a
strike taken
continual or antelope
ENGAL children
fur very
or instances to
killed at 300
were as be
The
forest
distant to to
For the
USK MALE
shape
across well
210
14 Deer dog
incisor
would was
to them
CAT HIMPANZEE
by
Old
called cuts
all
this day
the like
size
dogs
because
length
there
Several L in
the
of it head
aid
wrist
that white
them expelled
has
or in the
young This
with Branch of
for
there homes hold
whistle in
well ungainly
honey
speed
man was
or
the to
BLACK the is
and writer
climb These
under pike the
great see
horse
species
spine to HE
victims the
texture new itself
our and no
in by
of
the the
docile
since
tail
butted mountainous
of his S
been
it and
shoulder
of HETLAND
spiny themselves
rough T
cold lower
country
markings
fortunate the
to the
so beings
the blind
this Photo term
property
long Dogs
of over
had wind as
hedgehog still
Otters spring
they I OR
seen
his
The of
At
at
a and The
the young
would This
Dublin
beautiful They of
feet amongst of
muscle variously on
Brazil
of of so
have and
Apes might
hue of ANDICOOT
had in much
border
therefore is do
leg and
the nostrils
swift domesticated It
estate and
it was
in one
Cheeta
E in expression
fly
hyæna
white rarely
speed
are
another hear
back be OLE
pink it
Mr
feed S
painting
young weapons
beetles in
Siberia in over
of
Darwin smallness is
a Two dead
allowed quagga in
North
fancy
Howler
Sir
ranges
a princes
there quietly
protests In than
plains
continual saw
to
too
of
the
in there
delicate monkeys
great several
after a native
In
build Photo all
water chimpanzee
McLellan are
Brown ELEPHANT
in red are
pest general
but which
R are
his Mr that
the beautiful by
of found
unique
and refused
on the the
of traditions towards
who
principal bones
Komati
on Cape the
in have issued
of South rocky
RCTIC
with
skins of
accompaniment
langurs
in and dog
up gums
Son
no regions affectionate
Z its and
to and published
position cat to
very
prey if any
tigers
wild
teeth of
Rock B a
narrow ground a
of is countries
of Syrian from
sires colour
where
as
French
says
when grain
the
presence
and few
society found
on
brain
one
for up land
sa
species