... integer part resulting from division. In other words, integer
division discards the part after the decimal point. So,
10 /3 is 3 (not 3. 333 3…), 5/2 is 2
(not 2.5), and 11 /3 is 3 (not 3. 6666…). ... preceding each item to be output with
1 .3
cout
01_CH01.fm Page 28 Wednesday, August 20, 20 03 2:21 PM
26 C++ Basics
Notice the expression 2*(n++). When C++ evaluates this exp...
...
remainder, so the value of
1 /3 is 0, not 0 .33 33 . This makes the value of the entire
expression
0 * 3, which of course is 0.
01_CH01.fm Page 39 Wednesday, August 20, 20 03 2:21 PM
... << "\n";
return 0;
}
4. 3* x
3* x + y
(x + y)/7
Note that x + y/7 is not correct.
(3* x + y)/(z + 2)
5. bcbc
6.
(1 /3) * 3 is equal to 0
Since 1 and 3 are of type int, the / o...
... 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 2 and 3.
3. Consider a quadratic ... that are
simultaneously greater than the smaller root (1) and less than the larger root (3) . Write a
C++ Boolean expression that is true when the value of this quadratic is neg...
... shelf.
80 Flow of Control
34 . For each of the following situations, tell which type of loop (while, do-while, or for)
would work best.
a. Summing a series, such as
1/2 + 1 /3 + 1/4 + 1/5 + . . . ... of days of sick leave taken by employees in a department.
d. Testing a function to see how it performs for different values of its arguments.
35 . What is the output produced by the followin...
... numbers.\n";
23 return 0;
24 }
S
AMPLE
D
IALOGUE
Enter 4 negative numbers:
-1 -2 3 -4
ERROR: positive number or zero was entered as the
3rd number! Input ends with the 3rd number.
3rd number was ...
3
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 FUNC...
... commas. For
example:
int children [3] = {2, 12, 1};
1022
10 23
1024
1025
1026
1027
1028
1029
1 030
1 031
1 032
1 033
1 034
a[0]
Some variable
named stuff
a[1]
a[2]
a [3]
a[5]
a[4]
Some variable
named ... code?
char symbol [3] = {’a’, ’b’, ’c’};
for (int index = 0; index < 3; index++)
cout << symbol[index];
5. What is the output of the following code?
double a [3] = {1.1, 2.2,...
... {
130 return rate;
131 }
132 void BankAccount::setBalance(double balance)
133 {
134 accountDollars = dollarsPart(balance);
135 accountCents = centsPart(balance);
136 }
137 //Uses cstdlib:
138 ... as $32 3.52 is
not a dollar sign in front of a floating-point value. The $32 3.52 cannot have any more or fewer
than two digits after the decimal point. You cannot have a balance of $32 3....