...
Function Basics
3.1 PREDEFINED FUNCTIONS 92
Predefined Functions That Return a Value 92
Predefined
void
Functions 97
A Random Number Generator 99
3.2 PROGRAMMER-DEFINED FUNCTIONS 103
Defining ... no intuitive
meaning, but C++ converts the
int values to bool and then evaluates the && and !
operations. Thus, C++ will evaluate this mess. Recall that in C++, any nonze...
...
in a
cout
statement
spaces in
output
newline
character
01_CH01.fm Page 29 Wednesday, August 20, 2003 2:21 PM
30 C++ Basics
Tip
Although "\n" and endl mean the same thing, they are ... such cases C++ performs an automatic type cast, converting the 5 to 5.0 and placing
5.0 in the variable d. You cannot store the 5 as the value of d without a type cast, but
sometimes C++ do...
... wanted
floating-point division, which does not discard the part after the decimal point.
c.
f = (9. 0/5) * c + 32.0;
or
f = 1.8 * c + 32.0;
9.
cout << "The answer to the question of\n"
... allow you to use the standard
C++ libraries.
■
LIBRARIES AND
include
DIRECTIVES
C++ includes a number of standard libraries. In fact, it is almost impossible to write a
C++ pr...
... see numeric intervals given as
2 < x < 3
In C++ this interval does not have the meaning you may expect. Explain and give the
correct C++ Boolean expression that specifies that
x lies between ... the two alternatives in an if-else statement to do nothing at
all. In C++ this can be accomplished by omitting the
else part. These sorts of statements
Branching Mechanisms 57
Self-Test...
... of beer on the shelf.\n";
number ;
}
S
AMPLE
D
IALOGUE
100 bottles of beer on the shelf.
99 bottles of beer on the shelf.
.
.
.
0 bottles of beer on the shelf.
80 Flow of Control
34. For ... loop.
You will find it instructive to compare the details of the programs in Displays 2.8 and
2 .9. Pay particular attention to the change in the controlling Boolean expression.
continue
statement...
... array.
For example, the following will set the value of
score[3]
equal to
99
:
int n = 2;
score[n + 1] = 99 ;
Although they may look different,
score[n + 1]
and
score[3]
are ... return 0;
25 }
S
AMPLE
D
IALOGUE
Enter 5 scores:
5 9 2 10 6
The highest score is 10
The scores and their
differences from the highest are:
5 off by 5
9 off by 1
2 off by 8
10 off by 0...
... Member
(part 1 of 2)
1 //Program to demonstrate the CDAccount structure type.
2 #include <iostream>
3 using namespace std;
4 struct Date
5 {
6 int month;
7 int day;
8 int year;
9 };
10 ... term;//months until maturity
16 Date maturity; //date when CD matures
17 double balanceAtMaturity;
18 };
19 void getCDData(CDAccount& theAccount);
20 //Postcondition: theAccount.initialBalan...
... beyond the Vector Size 293
Tip: Vector Assignment Is Well Behaved 294
Efficiency Issues 294
CHAPTER SUMMARY 296
ANSWERS TO SELF-TEST EXERCISES 296
PROGRAMMING PROJECTS 298
07_CH07.fm Page 257 ... Use of
const
2 79
Inline Functions 284
Static Members 286
Nested and Local Class Definitions 2 89
7.3 VECTORS—A PREVIEW OF THE STANDARD
TEMPLATE LIBRARY 290
Vector Basics 290
Pitfall...