Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
Your paragraph text
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
A First Book of C++, 3rd Edition 05344-92819 Chapter 2 Solutions Exercises 2.1 1.
2.
3.
4. 5.
a. float or double b. integer c. float or double d. integer e. float or double 634,000 195.162 83.95 .00295 .0004623 1.26e2 6.5623e2 3.42695e3 4.8932e3 3.21e-1 1.23e-2 6.789e-3 This exercise is system-dependent, so answers will vary. a. 8 bytes for KINGSLEY; 9 BYTES FOR KINGSLEY\0 b. Students will create a figure similar to Figure 2-3 that includes the following: 8 bytes of storage
01001011 01001001 01001110 01000111 01010011 01001100 01000101 01011001 -------- ------- -------- -------- -------- -------- -------- -------KINGSLEY
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
6.
a. b.
8 bytes for kingsley; 9 bytes for kingsley\0 Students will create a figure similar to Figure 2-3 that includes the following: 8 bytes of storage
01101011 01101001 01101110 01100111 01110011 01101100 01100101 01111001 -------- -------- -------- -------- -------- -------- -------- -------KINGSLEY
7.
This exercise is name-dependent, so answers will vary.
8.
A computer will use variables and declaration statements to let the computer know what types of values it will be using. For example, if the program requires integer types, it will declare variables of the int data type.
9.
a. 128 * 1048576 = 134217728 b. 256 * 1048576 = 268435456 c. 512 * 1048576 = 536870912 e. 256 * 1048576 * 2 = 536870912 f. 2566 * 1048576 * 4 = 10762584064 g. 1.44 * 1048576 = 1509949.44
Exercises 2.2 1.
2.
a. b. c. d. e.
(2 * 3) + (4 * 5) (6 + 18)/2 4.5/(12.2-3.1) 4.6*(3.0+14.9) (12.1 + 18.9) * (15.3 - 3.8)
a.
n/p+3=5
b. c. d. e. f. g. h. i. j.
m / p + n - 10 * amount = 10 m - 3 * n + 4 * amount = 24 amount / 5 = 0 18 / p = 3 18 % p = 3 -p * n = -50 -m / 20 = -2 -m % 20 = -10 (m + n) / (p + amount ) = 12
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
k. m + n / p + amount = 53 Note: these results assume that the above variables are integer data type 3. a. n / p + 3 = 5.0 b. m / p + n - 10 * amount = 10.0 c. m - 3 * n + 4 * amount = 24.0 d. amount / 5 = 0.2 e. 18 / p = 3.6 f. 18 % p = (modulus works only with integers) g. -p * n = -50.0 h. -m / 20 = -2.0 i. -m % 20 = (modulus works only with integers) j. (m + n) / (p + amount ) = 12.0 k. m + n / p + amount = 53.0 Note: these results assume that the above variables are float data type 4. a. 27 b. 8 c. 1 d. 220 e. 23 f. 20 g. 6 h. 2 5. a. 27.0 b. 8.0 c. 1.0 d. 220.0 e. 23.0 f. 20.0 g. 6.0 h. 2.0 6. a. 21.8 b. 15.3 c. 21.8 d. 8 e. compiler error f. 8 g. 23 h. 16
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
j.
i.
16 compiler error
Exercises 2.3 1. answer1 is the integer 2 answer2 is the integer 5 2. The remainder of 9 divided by 4 is1 The remainder of 17 divided by 3 is 2 3. See Solution file pgm2-3ex3.cpp. Output: 15 56.73 0.104918 4. See Solution file pgm2-3ex4.cpp. Output: 3 3 -9 5. a. missing closing semi-colon b. quotation marks unnecessary c. quotation marks unnecessary d. cout must precede "Hello World!"; and insertion operator must be used instead of extraction operator e. the setw() manipulator must precede the output f. set(10) must be setw(10), and setprecision(2) must precede the literal output 6. a. |5| b. | 5| c. |56829| d. | 5.26| e. | 5.27| f. |53.26| 9. |534.26| h. |534.00| 7. a. The number is 26.27
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
The number is 682.30 The number is 1.97 b. 26.27 1.97
682.30 --------710.54
c. 26.27 -------
682.30 1.97 710.54
d. 36.16 10.00 ---8. 16, e, 10, 12
Exercises 2.4 1.
2.
prod_a newbal 9ab6 c1234 while sum.of abcd $total average _c3 new bal grade1 12345 a1b2c3d4 finGrad
valid valid invalid valid invalid invalid valid invalid valid invalid invalid valid invalid valid valid
salestax harry maximum 3sum a234 sue
valid valid valid invalid valid valid
begins with a number C++ keyword decimal point not allowable begins with special character begins with special character contains a space begins with a number
not meaningful begins with a number not meaningful not meaningful
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
okay valid for invalid r2d2 valid not meaningful c3p0 valid not meaningful a valid not meaningful tot.al invalid contains decimal point firstNum valid average valid awesome valid not meaningful c$five invalid contains special character ccal valid not meaningful sum valid goforit valid not meaningful netpay valid 3. a. int count; b. float grade; c. double yield; d. char initial; 4. a. int num1, num2, num3; b. float grade 1, grade2, grade3, grade4; c. double tempa, tempb, tempc; d. char ch, let1, let2, let3, let4; 5. a. int firstnum, secnum; b. float price, yield, coupon; c. double maturity; 6. a. int month; int day = 30; int year; b. double hours; double rate; double otime = 15.62; c. float price; float amount; float taxes; d. char in _key; char ch; char choice = 'f'; 7. a. #include <iostream> // preprocessor directive using namespace std; // additional preprocessor directive int main() // header line for function main()
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
{ // opening brace for function main() int num1, num2, total; // integer variable declarations num1 = 25; // assign the value 25 to the variable num1 num2 = 35; // assign the value 35 to the variable num2 total = num1 + num2; // assign the sum of num1 and num2 to total cout << "The total of" << num1 << " and " << num2 << " is " << total << endl; // output statement return 0; // return 0 to calling program } // closing brace for function main() b. The total of25 and 35 is 60. (Note: no space between of and 25) 8. See Solution file pgm2-4ex8.cpp 9 See Solution file pgm2-4ex9.cpp 10. See Solution file pgm2-4ex10.cpp 11. The average is 16.5, but the program stores 16 in the variable average. To ensure that the correct answer is displayed, the variable average must be declared as a float or double value. 12. See Solution file pgm2-4ex12.cpp. 13. A name and a memory address 14. a. All definitions are declarations but not all declarations are definitions. b. Definition statements reserve storage areas in memory for the variables. In this sense variables are created (come into existence) by definition statements. Before a variable is used it must exist. Thus definition statements must precede any statement that uses the variables. They need not, however, always precede all other statements. For example, in the following code the variable b is defined within the body of the function. Although it is preferable to define and/or declare all variables at the top of the function immediately after the opening brace, there are times that it is useful to temporarily create a variable within a function for debugging purposes. int main() { int a; a = 5; cout << " a = " << a << endl; int b; b = a; cout << " b = " << b << endl;
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
return 0; } 15.
a. Address: 159 160 161 162 163 164 165 166 -------------------------------------------------------|||||w|o|w|!| --------------------------------------------------------rate ch1 ch2 ch3 ch4 Address: 167 168 169 170 171 172 173 174 --------------------------------------------------||||||||| --------------------------------------------------taxes Address: 175 176 177 178 179 180 181 182 ------------------------------------------------------|||0|||||| ------------------------------------------------------num count b. ch1 = 01110111 ch2 = 01101111 ch3 = 01110111 ch4 = 00100001
16.
a. Address: 159 160 161 162 163 164 165 166 ---------------------------------------------------|a||b|u|n|c|h|\| ---------------------------------------------------cn1 cn2 cn3 cn4 cn5 cn6 cn7 key Address: 167 168 169 170 171 172 173 174 --------------------------------------------------|'|o|f|||||| --------------------------------------------------sch inc inc1 b. cn1=01100001 cn2=00100000 cn3=01100010 cn4=01110101
Solutions Manual for A First Book of C++ From Here to There 3rd Edition by Bronson
cn5=01101110 cn6=01100011 cn7=01101000 key=01011100 sch=00100111 inc=01101111 inc1=01100110
Address: 159 160 161 162 163 164 165 166 17.
|||||||||
--------------------------------------------------------
--------------------------------------------------------miles count num Address: 167 168 169 170 171 172 173 174 --------------------------------------------------||||||||| --------------------------------------------------dist Address: 175 176 177 178 179 180 181 182 ------------------------------------------------------||||||||| ------------------------------------------------------temp