C++ How To Program Early Objects Version 9th Edition Deitel Solutions Manualpdf Download
C++ How To Program Early Objects Version 9th Edition Deitel Solutions Manualpdf Download
https://testbankdeal.com/product/c-how-to-program-early-objects-
version-9th-edition-deitel-solutions-manual/
https://testbankdeal.com/product/c-how-to-program-early-objects-
version-9th-edition-deitel-test-bank/
https://testbankdeal.com/product/c-how-to-program-late-objects-
version-7th-edition-deitel-test-bank/
https://testbankdeal.com/product/java-how-to-program-early-
objects-11th-edition-deitel-solutions-manual/
https://testbankdeal.com/product/using-
sage-50-accounting-2017-canadian-1st-edition-purbhoo-solutions-manual/
Blueprint Reading for Welders 9th Edition Bennett Test
Bank
https://testbankdeal.com/product/blueprint-reading-for-welders-9th-
edition-bennett-test-bank/
https://testbankdeal.com/product/macroeconomics-policy-and-
practice-1st-edition-mishkin-test-bank/
https://testbankdeal.com/product/international-cooking-a-culinary-
journey-3rd-edition-heyman-test-bank/
https://testbankdeal.com/product/fundamentals-of-corporate-
finance-2nd-edition-parrino-test-bank/
https://testbankdeal.com/product/corporate-financial-accounting-12th-
edition-warren-solutions-manual/
Social Problems 6th Edition Macionis Test Bank
https://testbankdeal.com/product/social-problems-6th-edition-macionis-
test-bank/
cpphtp9_07.fm Page 1 Thursday, June 6, 2013 12:12 PM
To go beyond is as
wrong as to fall short.
—Confucius
Objectives
In this chapter you’ll:
■ Use C++ Standard Library
class template array—a
fixed-size collection of
related data items.
■ Use arrays to store, sort
and search lists and tables of
values.
■ Declare arrays, initialize
arrays and refer to the
elements of arrays.
■ Use the range-based for
statement.
■ Pass arrays to functions.
■ Declare and manipulate
multidimensional arrays.
■ Use C++ Standard Library
class template vector—a
variable-size collection of
related data items.
cpphtp9_07.fm Page 2 Thursday, June 6, 2013 12:12 PM
Self-Review Exercises
7.1 (Fill in the Blanks) Answer each of the following:
a) Lists and tables of values can be stored in or .
ANS: arrays, vectors.
b) An array’s elements are related by the fact that they have the same and .
ANS: array name, type.
c) The number used to refer to a particular element of an array is called its .
ANS: subscript or index.
d) A(n) should be used to declare the size of an array, because it eliminates magic
numbers.
ANS: constant variable.
e) The process of placing the elements of an array in order is called the array.
ANS: sorting.
f) The process of determining if an array contains a particular key value is called
the array.
ANS: searching.
g) An array that uses two subscripts is referred to as a(n) array.
ANS: two-dimensional.
7.2 (True or False) State whether the following are true or false. If the answer is false, explain why.
a) A given array can store many different types of values.
ANS: False. An array can store only values of the same type.
b) An array subscript should normally be of data type float.
ANS: False. An array subscript should be an integer or an integer expression.
c) If there are fewer initializers in an initializer list than the number of elements in the ar-
ray, the remaining elements are initialized to the last value in the initializer list.
ANS: False. The remaining elements are initialized to zero.
d) It’s an error if an initializer list has more initializers than there are elements in the array.
ANS: True.
7.3 (Write C++ Statements) Write one or more statements that perform the following tasks for
an array called fractions:
a) Define a constant variable arraySize to represent the size of an array and initialize it to 10.
ANS: const size_t arraySize = 10;
b) Declare an array with arraySize elements of type double, and initialize the elements to 0.
ANS: array< double, arraySize > fractions = { 0.0 };
c) Name the fourth element of the array.
ANS: fractions[ 3 ]
d) Refer to array element 4.
ANS: fractions[ 4 ]
e) Assign the value 1.667 to array element 9.
ANS: fractions[ 9 ] = 1.667;
f) Assign the value 3.333 to the seventh element of the array.
ANS: fractions[ 6 ] = 3.333;
g) Display array elements 6 and 9 with two digits of precision to the right of the decimal
point, and show the output that is actually displayed on the screen.
ANS: cout << fixed << setprecision( 2 );
cout << fractions[ 6 ] << ' ' << fractions[ 9 ] << endl;
Output: 3.33 1.67
cpphtp9_07.fm Page 3 Thursday, June 6, 2013 12:12 PM
Self-Review Exercises 3
h) Display all the array elements using a counter-controlled for statement. Define the in-
teger variable i as a control variable for the loop. Show the output.
ANS: for ( size_t i = 0; i < fractions.size(); ++i )
cout << "fractions[" << i << "] = " << fractions[ i ] << endl;
Output:
fractions[ 0 ] = 0.0
fractions[ 1 ] = 0.0
fractions[ 2 ] = 0.0
fractions[ 3 ] = 0.0
fractions[ 4 ] = 0.0
fractions[ 5 ] = 0.0
fractions[ 6 ] = 3.333
fractions[ 7 ] = 0.0
fractions[ 8 ] = 0.0
fractions[ 9 ] = 1.667
i) Display all the array elements separated by spaces using a range-based for statement.
ANS: for ( double element : fractions )
cout << element << ' ';
7.4 (Two-Dimensional array Questions) Answer the following questions regarding an array
called table:
a) Declare the array to store int values and to have 3 rows and 3 columns. Assume that
the constant variable arraySize has been defined to be 3.
ANS: array< array< int, arraySize >, arraySize > table;
b) How many elements does the array contain?
ANS: Nine.
c) Use a counter-controlled for statement to initialize each element of the array to the
sum of its subscripts.
ANS: for ( size_t row = 0; row < table.size(); ++row )
for ( size_t column = 0; column < table[ row ].size(); ++column )
table[ row ][ column ] = row + column;
d) Write a nested for statement that displays the values of each element of array table in
tabular format with 3 rows and 3 columns. Each row and column should be labeled
with the row or column number. Assume that the array was initialized with an initial-
izer list containing the values from 1 through 9 in order. Show the output.
ANS: cout << " [0] [1] [2]" << endl;
7.5 (Find the Error) Find the error in each of the following program segments and correct the error:
a) #include <iostream>;
ANS: Error: Semicolon at end of #include preprocessing directive.
Correction: Eliminate semicolon.
b) arraySize = 10; // arraySize was declared const
ANS: Error: Assigning a value to a constant variable using an assignment statement.
Correction: Initialize the constant variable in a const size_t arraySize declaration.
c) Assume that array< int, 10 > b = {};
for ( size_t i = 0; i <= b.size(); ++i )
b[ i ] = 1;
ANS: Error: Referencing an array element outside the bounds of the array (b[10]).
Correction: Change the loop-continuation condition to use < rather than <=.
d) Assume that a is a two-dimensional array of int values with two rows and two columns:
a[ 1, 1 ] = 5;
ANS: Error: array subscripting done incorrectly.
Correction: Change the statement to a[ 1 ][ 1 ] = 5;
Exercises
NOTE: Solutions to the programming exercises are located in the ch07solutions folder.
7.6 (Fill in the Blanks) Fill in the blanks in each of the following:
a) The names of the four elements of array p are , , and
.
ANS: p[ 0 ], p[ 1 ], p[ 2 ], p[ 3 ]
b) Naming an array, stating its type and specifying the number of elements in the array
is called the array.
ANS: declaring.
c) When accessing an array element, by convention, the first subscript in a two-dimen-
sional array identifies an element’s and the second subscript identifies an el-
ement’s .
ANS: row, column.
d) An m-by-n array contains rows, columns and elements.
ANS: m, n, m × n.
e) The name of the element in row 3 and column 5 of array d is .
ANS: d[ 3 ][ 5 ].
7.7 (True or False) Determine whether each of the following is true or false. If false, explain why.
a) To refer to a particular location or element within an array, we specify the name of the
array and the value of the particular element.
ANS: False. The name of the array and the subscript of the array are specified.
b) An array definition reserves space for an array.
ANS: True.
c) To indicate reserve 100 locations for integer array p, you write
p[ 100 ];
ANS: False. A data type must be specified. An example of a correct definition would be:
array< int, 100 > p;
d) A for statement must be used to initialize the elements of a 15-element array to zero.
ANS: False. The array can be initialized in a declaration with a member initializer list.
cpphtp9_07.fm Page 5 Thursday, June 6, 2013 12:12 PM
Exercises 5
e) Nested for statements must be used to total the elements of a two-dimensional array.
ANS: False. The sum of the elements can be obtained without for statements, with one for
statement, three for statements, etc.
7.8 (Write C++ Statements) Write C++ statements to accomplish each of the following:
a) Display the value of element 6 of character array alphabet.
ANS: cout << alphabet[ 6 ] << '\n';
b) Input a value into element 4 of one-dimensional floating-point array grades.
ANS: cin >> grades[ 4 ];
c) Initialize each of the 5 elements of one-dimensional integer array values to 8.
ANS: int values[ 5 ] = { 8, 8, 8, 8, 8 };
or
int values[ 5 ];
for ( int j = 0; j < 5; ++j )
values[ j ] = 8;
or
int values[ 5 ];
for ( int &element : values )
element = 8;
d) Total and display the elements of floating-point array temperatures of 100 elements.
ANS: double total = 0.0;
for ( int k = 0; k < 100; ++k )
{
total += temperatures[ k ];
cout << temperatures[ k ] << '\n';
} // end for
or
double total = 0.0;
for ( int temp : temperatures )
{
total += temp;
cout << temp << '\n';
} // end for
e) Copy array a into the first portion of array b. Assume that both arrays contain doubles
and that arrays a and b have 11 and 34 elements, respectively.
ANS: for ( int i = 0; i < 11; ++i )
b[ i ] = a[ i ];
f) Determine and display the smallest and largest values contained in 99-element floating-
point array w.
ANS: double smallest = w[ 0 ];
double largest = w[ 0 ];
i) Write a nested counter-controlled for statement that initializes each element of t to zero.
ANS:
for ( int i = 0; i < 2; ++i )
{
for ( int j = 0; j < 3; ++j )
t[ i ][ j ] = 0;
} // end for
j) Write a nested range-based for statement that initializes each element of t to zero.
ANS:
for ( auto &row : t )
{
for ( auto &element : row )
element = 0;
} // end for
cpphtp9_07.fm Page 7 Thursday, June 6, 2013 12:12 PM
Exercises 7
k) Write a statement that inputs the values for the elements of t from the keyboard.
ANS:
for ( int i = 0; i < 2; ++i )
{
for ( int j = 0; j < 3; ++j )
cin >> t[ i ][ j ];
} // end for
l) Write a series of statements that determine and display the smallest value in array t.
ANS:
int smallest = t[ 0 ][ 0 ];
7.11 (One-Dimensional array Questions) Write single statements that perform the following
one-dimensional array operations:
a) Initialize the 10 elements of integer array counts to zero.
ANS: int counts[ 10 ] = {};
b) Add 1 to each of the 15 elements of integer array bonus.
ANS:
for ( int i = 0; i < 15; ++i )
++bonus[ i ];
or
c) Read 12 values for the array of doubles named monthlyTemperatures from the keyboard.
ANS:
for ( int p = 0; p < 12; ++p )
cin >> monthlyTemperatures[ p ];
or
or
7.12 (Find the Errors) Find the error(s) in each of the following statements:
a) Assume that a is an array of three ints.
cout << a[ 1 ] << " " << a[ 2 ] << " " << a[ 3 ] << endl;
ANS: a[ 3 ] is not a valid location in the array. a[ 2 ] is the last valid location.
b) array< double, 3 > f = { 1.1, 10.01, 100.001, 1000.0001 };
ANS: Too many initializers in the initializer list. Only 1, 2, or 3 values may be provided in
the initializer list.
c) Assume that d is an array of doubles with two rows and 10 columns.
d[ 1, 9 ] = 2.345;
Exercises 9
Result is 55
7.20 (What Does This Code Do?) What does the following program do?
ANS: This program prints array elements in reverse order. The output would be
CHOKING.
POISONS.
Little can be done in this, unless you have a pump, so as to
extract the poison from the stomach, then follow with physics.
WOUNDS.
The first thing is to clean the wound from all dirt and gravel. A
good fomentation with warm water will effect this. If the wound is
much lacerated, or punctured, we must bring them neatly together.
If any portions so torn as to prevent its from doing this completely,
they should be removed with a knife, or sharp scissors; then the
edges brought together by means of passing a needle and strong
waxed twine deeply through them, making two, three or more
stitches, half inch from each other. Then apply the tincture of myrrh
and aloes, and bandage tolerably firm, not so much so as to prevent
the circulation. If there should be proud flesh, the wound must be
cleansed with a strong solution of blue vitriol, and then dressed with
the tincture. All wounds should be first well cleansed, before
applying anything on them.
These are little warty tumors, growing on various parts of the skin,
and sometimes on the teats.
Remedy:—The easiest and shortest way to remove them, is to tie a
piece of waxed silk firmly around the base of each, and to tighten
them every day; by means of this, the tumor will drop off, and will
rarely grow again. To make it certain, the parts should be touched
with a hot iron or lunar caustic; the warts should be well scarred,
and they will never appear again.
The first thing is to examine the wound carefully, and see how far
it extends under the hoof or horn. The first step is to clean all the
foul or proud flesh, by means of a knife, then apply lunar caustic, or
muriatic acid, until the wound becomes healthy and dry. In extreme
cases where there is swelling, apply a poultice night and morning,
then apply the caustic, and keep dry and from all danger of getting
dirt and gravel in. When the wound begins to look healthy, apply the
tincture of Aloes and Myrrh, until perfectly relieved, and give a
gentle purgative.
The best time to dry cows is whilst feeding dry feed. A good dose
of physic and after it has operated, follow with an astringent drink,
will generally settle the business. Six drachms of alum dissolved in 1
pint water, is a dose. The cow should be milked clean when the
astringent is given; feed on dry food for a few days. Should the
udder get very hard in a few days, milk clean and give another
astringent drink, and the third may be given if necessary.
THE MANGE.
RABIES OR HYDROPHOBIA.
COW POWDERS.
Pulverize these articles fine and mix well, and it is ready for use.
Any of the above articles can be had at any Drug Store.
Directions for Use:—Dose for a full grown animal, one
tablespoonful once or twice a day, as the case may require.
This powder cannot be excelled, it is an excellent medicine for all
derangements of the system, it is perfectly harmless, and should be
fed sometime in all chronic and lingering diseases, or at least until
entirely relieved, and the system put in perfect health. No animal
can thrive unless in health. Therefore every farmer should adopt the
rule to feed all his stock, and especially those which he wishes to
fatten with some of these powders; by so doing you will save feed
and time. In fattening, feed on offal.
Directions:—For a full grown sheep, dose, 1 teaspoonful once or
twice a day, as the necessity of the case may require. Feed on offal.
INDEX TO DISEASES OF HORSES.
Chest Founder, 39
Chronic Cough, 45
Ears, 30
Enlargement of the Hock, 48
Epidemics, 44
Eyes, 29
Flatulent Colic, 9 10 11
Founder Acute, 52 53 54
Grease, 50 51
Inflammation, 40 41 42
—— Bladder, 15 16
—— Bowels, 22 23 24
—— Feet, 52 53 54
—— Kidneys, 17
—— Larynx, 43 44
—— Lungs, 18 19 20 21
Injury of the Eyes, 34
Lampass, 35
Physicing, 47
Poll Evil, 5 6 7 8
Process of Teething, 36 37 38
Rabies or Madness, 33
Restiveness or taming Horses, 55 56
Spasmodic Colic, 12 13 14
Sprain of Back Sinews, 48
—— of Coffin Joint, 49
Staggers, 31 32
Warts, 58
INDEX TO RECEIPTS BELONGING
TO THE HORSE.
Blistering, 69
—— Ointment, 71
Spirits of Pimento, 72
Alcohol, 94
Aloes, 95
Alum, 96
Antimony, 93
Aqua-Fortis, 94
Balls or Pills, 98
Cantharides, 97
Charcoal, 97
Chloride of Lime, 107
Clysters, 99
Common Salt, 106
Digitalis, 100
Drinks and Drenches, 104
Fomentations, 102
Gentian, 102
Ginger, 101
—— Root, 107
Liniments, 105
Linseed, 99
Mashes, 101
Muriatic Acid, 96
Mustard, 96
Opium, 103
Pitch, 100
Poultices, 103
Spasmodics, 93
Spirits of Camphor, 93
Sulphur, 105
Sulphuric Acid, 95
Tar, 104
Turpentine, 106
Thompson’s No. 6, 108
Vinegar, 94
Zinc or Calamine Powder, 108
INDEX TO DOMESTIC MEDICINES.
Dandeline, 121
Dr. Wickey’s Cholera Medicine, 148 149 150 151
Domestic Tonic, 201
Domestic Yeast, 204
Dr. Young’s Pills, 186
Domestic Cough Syrup, 189
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
testbankdeal.com