C++ Programming From Problem Analysis to Program Design 6th Edition Malik Test Bank - Download All Chapters Immediately In PDF Format
C++ Programming From Problem Analysis to Program Design 6th Edition Malik Test Bank - Download All Chapters Immediately In PDF Format
https://testbankdeal.com/product/c-programming-from-problem-
analysis-to-program-design-6th-edition-malik-test-bank/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-6th-edition-malik-solutions-manual/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-7th-edition-malik-test-bank/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-8th-edition-malik-test-bank/
https://testbankdeal.com/product/pearsons-federal-
taxation-2018-comprehensive-31st-edition-rupert-solutions-manual/
Basic Immunology Functions and Disorders of the Immune
System 4th Edition Abbas Test Bank
https://testbankdeal.com/product/basic-immunology-functions-and-
disorders-of-the-immune-system-4th-edition-abbas-test-bank/
https://testbankdeal.com/product/nonlinear-systems-3rd-edition-khalil-
solutions-manual/
https://testbankdeal.com/product/busn-5-5th-edition-kelly-test-bank/
https://testbankdeal.com/product/guide-to-sql-9th-edition-pratt-
solutions-manual/
https://testbankdeal.com/product/mf-4th-edition-knox-test-bank/
Psychology 1st Edition Marin Test Bank
https://testbankdeal.com/product/psychology-1st-edition-marin-test-
bank/
Chapter 8: Arrays and Strings
TRUE/FALSE
2. The array index can be any integer less than the array size.
3. The statement int list[25]; declares list to be an array of 26 components, since the array
index starts at 0.
4. Given the declaration int list[20]; the statement list[12] = list[5] + list[7];
updates the content of the twelfth component of the array list.
5. Suppose list is a one dimensional array of size 25, wherein each component is of type int. Further,
suppose that sum is an int variable. The following for loop correctly finds the sum of the elements
of list.
sum = 0;
6. If an array index goes out of bounds, the program always terminates in an error.
7. Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.
8. When you pass an array as a parameter, the base address of the actual array is passed to the formal
parameter.
9. The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.
MULTIPLE CHOICE
1. Which of the following statements declares alpha to be an array of 25 components of the type int?
a. int alpha[25]; c. int alpha[2][5];
b. int array alpha[25]; d. int array alpha[25][25];
ANS: A PTS: 1 REF: 507-508
2. Assume you have the following declaration char nameList[100];. Which of the following
ranges is valid for the index of the array nameList?
a. 0 through 99 c. 1 through 100
b. 0 through 100 d. 1 through 101
ANS: A PTS: 1 REF: 509
3. Assume you have the following declaration int beta[50];. Which of the following is a valid
element of beta?
a. beta['2'] c. beta[0]
b. beta['50'] d. beta[50]
ANS: C PTS: 1 REF: 509
4. Assume you have the following declaration double salesData[1000];. Which of the following
ranges is valid for the index of the array salesData?
a. 0 through 999 c. 1 through 1001
b. 0 through 1000 d. 1 through 1000
ANS: A PTS: 1 REF: 509
5. Suppose that sales is an array of 50 components of type double. Which of the following correctly
initializes the array sales?
a. for (int 1 = 1; j <= 49; j++)
sales[j] = 0;
b. for (int j = 1; j <= 50; j++)
sales[j] = 0;
c. for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
d. for (int j = 0; j <= 50; j++)
sales[j] = 0.0;
ANS: C PTS: 1 REF: 512
6. Suppose that list is an array of 10 components of type int. Which of the following codes correctly
outputs all the elements of list?
a. 0 1 2 3 4 c. 0 5 10 15 20
b. 0 5 10 15 d. 5 10 15 20
ANS: C PTS: 1 REF: 512
int alpha[5];
int j;
a. 1 c. 5
b. 4 d. 6
ANS: C PTS: 1 REF: 512
a. 2 4 6 8 10 c. 8 6 4 2 0
b. 4 3 2 1 0 d. 10 8 6 4 2
ANS: D PTS: 1 REF: 512
a. 0 5 10 15 20 c. 5 10 15 20 20
b. 5 10 15 20 0 d. Code results in index out-of-bounds
ANS: D PTS: 1 REF: 515-516
11. Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the
following for loops sets the index of gamma out of bounds?
a. for (j = 0; j <= 49; j++)
cout << gamma[j] << " ";
b. for (j = 1; j < 50; j++)
cout << gamma[j] << " ";
c. for (j = 0; j <= 50; j++)
cout << gamma[j] << " ";
d. for (j = 0; j <= 48; j++)
cout << gamma[j] << " ";
ANS: C PTS: 1 REF: 515-516
12. Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the
following is equivalent to this statement?
a. int alpha[] = {3, 5, 7, 9, 11};
b. int alpha[] = {3 5 7 9 11};
c. int alpha[5] = [3, 5, 7, 9, 11];
d. int alpha[] = (3, 5, 7, 9, 11);
ANS: A PTS: 1 REF: 516
14. Which of the following correctly declares name to be a character array and stores "William" in it?
a. char name[6] = "William";
b. char name[7] = "William";
c. char name[8] = "William";
d. char name[8] = 'William';
ANS: C PTS: 1 REF: 536
15. Consider the following declaration: char str[15];. Which of the following statements stores
"Blue Sky" into str?
a. str = "Blue Sky";
b. str[15] = "Blue Sky";
c. strcpy(str, "Blue Sky");
d. strcpy("Blue Sky");
ANS: C PTS: 1 REF: 537
16. Consider the following declaration:
char charArray[51];
char discard;
cin.get(charArray, 51);
cin.get(discard);
17. Consider the following statement: double alpha[10][5];. The number of components of
alpha is ____.
a. 15 c. 100
b. 50 d. 150
ANS: B PTS: 1 REF: 544
18. Consider the statement int list[10][8];. Which of the following about list is true?
a. list has 10 rows and 8 columns.
b. list has 8 rows and 10 columns.
c. list has a total of 18 components.
d. list has a total of 108 components.
ANS: A PTS: 1 REF: 544
19. Consider the following statement: int alpha[25][10];. Which of the following statements about
alpha is true?
a. Rows of alpha are numbered 0...24 and columns are numbered 0...9.
b. Rows of alpha are numbered 0...24 and columns are numbered 1...10.
c. Rows of alpha are numbered 1...24 and columns are numbered 0...9.
d. Rows of alpha are numbered 1...25 and columns are numbered 1...10.
ANS: A PTS: 1 REF: 544
20. Which of the following correctly declares and initializes alpha to be an array of four rows and three
columns with the component type int?
a. int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}};
b. int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5};
c. int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5};
d. int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};
ANS: D PTS: 1 REF: 546
21. After the following statements execute, what are the contents of matrix?
int matrix[3][2];
int j, k;
a. 0 0 c. 0 1
1 1 1 2
2 2 2 3
b. 0 1 d. 1 1
2 3 2 2
4 5 3 3
ANS: C PTS: 1 REF: 548-550
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fifth row of sale?
a. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[5][j];
b. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];
c. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[5][j];
d. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[4][j];
ANS: B PTS: 1 REF: 550
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fourth column of sale?
a. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[j][3];
b. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[j][4];
c. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][4];
d. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];
ANS: D PTS: 1 REF: 551
25. A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is
called a(n) ____.
a. matrix c. n-dimensional array
b. vector d. parallel array
ANS: C PTS: 1 REF: 557
COMPLETION
1. A data type is called ____________________ if variables of that type can store only one value at a
time.
ANS: simple
2. In a(n) ____________________ data type, each data item is a collection of other data items.
ANS: structured
double sales[10];
int index;
ANS: sales[index]
4. The word ____________________ is used before the array declaration in a function heading to
prevent the function from modifying the array.
ANS: const
5. The ____________________ of an array is the address (that is, the memory location) of the first array
component.
ANS: base address
6. The ____________________ sort algorithm finds the location of the smallest element in the unsorted
portion of the list and moves it to the top of the unsorted portion of the list.
ANS: selection
7. For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key
comparisons and 3(n-1) item assignments.
ANS: selection
ANS:
12
twelve
9. The function ____________________ returns the length of the string s, excluding the null character.
ANS: strlen(s)
ANS: 15
11. The following statements store the value ____________________ into len.
int len;
len = strlen("Sunny California");
ANS: 16
12. The header file string contains the function ____________________,which converts a value of type
string to a null-terminated character array.
ANS: c_str
PTS: 1 REF: 541
13. Two (or more) arrays are called ____________________ if their corresponding components hold
related information.
ANS: parallel
int alpha[10][25];
ANS:
10
ten
15. In the following declaration, the array gamma has ____________________ components.
int gamma[5][6][10];
ANS:
300
three hundred
The evidence which has been presented in the preceding chapter as to the benefits
resulting from the feeding of school children would have evoked, fifty, or even
twenty years ago, a simple and decisive retort. Granted, it would have been argued,
that the health and educational capacity of the children is deteriorated by lack of
nourishment, that irreparable and preventible damage is inflicted, and that the
provision of meals by a public authority averts this evil for many and mitigates it for
all; yet no plea of immediate expediency can stand against the ultimate loss involved
in any public assumption of the cost of providing maintenance for children. If a local
authority supplies part, even a small part, of their food, parental responsibility is, pro
tanto, diminished, with results disastrous not only to the character of the parents but
to the prospects of the children themselves. For if parents receive assistance in one
direction from a public authority, they will soon clamour to receive assistance in
other directions as well. In order to qualify for it, they will neglect their children, who
will thus benefit in one way only to be victimized in others. The children themselves,
having been fed from public funds, will be trained in habits of dependence, and,
when they grow up, will insist on still further provision being made for their children
in their turn. Thus one tiny breach in the walls of the family will insensibly be
widened till it admits a flood in which domestic affections and the integrity of the
home, "relations dear, and all the charities of father, son, and brother" are
submerged.
If such anticipations seem exaggerated, they have nevertheless played an important
part in determining the policy pursued in England towards more than one question,
and lie behind many of the criticisms which are passed on certain recent forms of
social intervention. The idea that relief given to the child must be regarded as relief
given to the parent, and that, if given at all, it must be accompanied by severe
restrictions, was enunciated emphatically in the Poor Law Report of 1834—indeed
that famous document scarcely mentions children except in so far as the treatment
of adults is influenced by these appendages—and has since become a settled part of
Poor Law policy. The fear that parental responsibility might be weakened was a
criticism brought against the Education Act of 1870, against the abolition of school
fees in 1894, and against the provision of medical treatment for school children
under the Education (Administrative Provisions) Act of 1907. Naturally, therefore, the
public provision of meals for school children has not escaped the criticism that it
would weaken the bond between parent and child and ultimately result in "the
breaking up of the home." "To remove the spur to exertion and self-restraint,"
reported a special committee of the Charity Organisation Society in 1887, "which the
spectacle of his children's hunger must be to any man in whom the feelings of
natural kindness are not altogether dead, is to assume a very grave responsibility,
and perhaps to take away the last chance of re-establishing the character and
fortunes of the breadwinner, and, with him, the fortunes of the whole household. It
is true, no doubt, that there are parents who are past redemption by influences of
this kind, but the majority of the committee are of opinion that it is better in the
interests of the community to allow, in such cases, the sins of the parents to be
visited on the children than to impair the principle of the solidarity of the family and
run the risk of permanently demoralising large numbers of the population by the
offer of free meals to their children."[528]
Now it is obvious that an economic policy which was determined primarily by a
consideration for the "solidarity of the family" would lead to far-reaching measures
of industrial reorganisation. If the ideal is a society in which "the bread-winner" is by
his "exertion and self-restraint" to guarantee "the fortunes of his whole household,"
the immediate object of attack must be those industrial evils which effectually
prevent him from doing so at present, and of which the principal are low wages,
casual labour, recurrent periods of unemployment and bad housing. That a crusade
conducted in the interests of the family against these regular features of modern
industry is entirely desirable need not be questioned. But in its absence it is obvious
that, so far from allowing "the sins of the parents to be visited on the children,"
what we are really doing is to allow the sins of the employer to be visited on the
employed or the sins of the community to be visited upon future generations of
unborn children, and it seems almost frivolous to ascribe the results of this constant
and vicarious sacrifice to the measures which, like the provision of school meals, are
directed merely to the partial mitigation of some of its worst effects. The truth is, to
put the matter bluntly, that what breaks up the family is not the presence of food
but its absence, and that, if the public conscience is unperturbed by the spectacle of
numerous homes in which economic circumstances have deprived the parents of the
means of providing meals for their children themselves, its sudden sensitiveness at
the thought of meals being provided by some external authority would be ludicrous
if it did not lead to such tragic consequences. The reader who reflects on the
thousands of dock-labourers in London, Liverpool and Glasgow who, through no fault
of their own, can obtain only three days' work a week, or on the 25 to 30 per cent.
of the working-class population of Reading who have been shown by Professor
Bowley to be receiving a total family income below the low standard fixed by Mr.
Rowntree,[529] and to be receiving it, in 49 per cent. of the cases, because they are
"in regular work but at low wages,"[530] will scarcely argue that the mere provision of
meals, however injudicious he may regard it, is likely to contribute seriously to the
weakening of family relationships which have been already strained or broken by
industrial anarchy or industrial tyranny. Sublata causa tollitur effectus. But does any
one seriously believe that a cessation of school meals would restore the desired
"solidarity of the family" to the casual or sweated labourer?
If the suggestion that the provision of meals is a principal cause undermining
parental responsibility is fantastic, is the suggestion that it must necessarily exercise
some influence in that direction better founded? We shall deal later with such facts
as can be used to throw light on this question. But we may point out here that the
idea underlying it usually derives part of its cogency in the minds of many of its
supporters less from any concrete evidence than from an implicit assumption that
there is a "natural" division of duties between public authorities and the individual
citizen, and that any redistribution of them between these two parties, which
removes one function from the latter to the former, must necessarily result in the
undermining of character, the weakening of the incentive to self-maintenance, the
decay of parental responsibility, in short, in all the phenomena of the process known
as "pauperisation." Now we need scarcely point out that, stated in this crude form,
the theory that every assumption of fresh responsibilities by public authorities results
in the undermining of character has no foundation in the experience of mankind. It
is, of course, quite true that any sudden removal from an individual of duties which
he has hitherto been accustomed to discharge may result in weakening the springs
of effort. It is also quite true that any sudden addition to his responsibilities may
result in crushing them, and that, as far as the more poorly paid ranks of labour are
concerned, energies are far more often worn out in a hopeless struggle than sapped
by an insidious ease. But by themselves these facts prove nothing as to the manner
in which burdens, duties, responsibilities, should be distributed between the
community and its individual members. What experience shows is that there is no
"natural" allocation of functions, but that there has been throughout history at once
a constant addition to, and a constant re-arrangement of them, and that the former
process is quite compatible with the latter. Nor is there any ground for the idea that
the extension of the activities of public bodies must necessarily result in accelerating
the approach of the state of economic and moral inertia described by those who
anticipate it as "Pauperism." If that were the case, all civilised communities would,
indeed, have been hastening to destruction from a time "whereof the memory of
man runneth not to the contrary." For our fathers had no elementary education, our
grandfathers no municipal water, and few lamp-posts; while our great-grandfathers
enjoyed the independence derived from the possession of relatively few roads, and
those of a character sufficiently bad to offer the most powerful incentives to the
energy and self-reliance of the pedestrian. On this theory the citizen of Manchester
would be more pauperised than the citizen of London; both would be seriously
pauperised compared with the peasant of Connemara; while the wretched
inhabitants of German municipalities would be wallowing in a perfect quagmire of
perpetual pauperism. Why indeed should one stop here? There have been periods in
history in which not only these functions, but the organisation of justice and the
equipment of military forces have been left to the bracing activities of private
individuals; and an enquiry into the decline and fall of individual independence
would, if logically pursued, lead us into dim regions of history far anterior to the
Norman Conquest. The origins of modern pauperism, like the origins of modern
liberty, are to be sought among "the primeval forests of Germany!"
While, however, there is no foundation for the doctrine that every extension of public
provision results in a slackening of energy on the part of the individual, it is, none
the less, possible that this may be the result of the particular kind of provision which
consists in the supplying of meals to school children. In the event of that being
proved to be the case, it is by no means easy to say what policy should be pursued.
Public authorities, it may be argued, should cease to provide school meals. To this
answer, which is at first sight plausible, there are two objections which are together
almost insuperable. The first is that Education Authorities are under a legal
obligation to provide education for the children in their charge and to carry out
medical inspection with a view to discovering their ailments; while they may, if they
think fit, provide medical treatment for them. They owe it to their constituents to
spend their money in the most effective and economical manner. Education given to
children who are suffering from want of nourishment not only is ineffective, but may
be positively deleterious. When the extent of malnutrition is known, is it reasonable
to expect the Authorities deliberately to shut their eyes to the fact that so far from
benefiting the children who suffer from it they may be positively aggravating their
misfortunes? If it be replied, ruat coelum fiat justitia, let the children suffer in order
to improve the moral character of their parents, an Education Committee may not
unfairly retort that it is elected primarily to attend to the welfare of the children, and
that the wisdom of elevating parents, who ex hypothesi are demoralised, at the cost
of the rising generation is, at any rate, too problematical to justify it in neglecting its
own special duties. Moreover, even assuming that public bodies were willing to apply
to the education of children the principles recommended in 1834 for the treatment
of "improvidence and vice," there is no reason to suppose that they would succeed
in averting the "pauperisation" which is dreaded. No fact is more clearly established
by the history of all kinds of relief administration since 1834 than that the effect of
refusing to make public provision for persons in distress is merely to lead to the
provision of assistance in a rather more haphazard, uncoordinated and indiscriminate
manner by private agencies. A purely negative policy is systematically "blacklegged"
by private philanthropists. Rightly or wrongly the plain man finds his stomach turned
by the full gospel of deterrence; with the result that, while the English Poor Law is
nominally deterrent, enormous sums are spent every year in private charity in
London alone; that in 1886 the Local Government Board recommended local
authorities to provide relief for certain classes of workers apart from the Poor Law,
on the ground that the Poor Law, for whose administration the Local Government
Board is responsible, is necessarily degrading; and that, finally, a special Act had to
be passed in 1905 creating authorities to administer assistance for unemployed
workmen whom public opinion would no longer allow to be left to the tender mercies
of a deterrent policy of Poor Relief. That the same result would follow with even
greater certainty were public bodies to decline to provide for necessitous school
children is obvious, inasmuch as to the foolish sentimentality of the ordinary person
the sufferings of childhood make a special appeal. Indeed it has followed already. In
the days when Education Authorities had no power to spend public money on the
provision of meals for school children, what happened was that the provision of
meals was begun by private persons, and in the towns which have not put the Act of
1906 into force such private provision obtains at the present day. Such extra-legal
intervention has all the disadvantages ascribed to the public provision of meals, for
one can scarcely accept the extravagant contention that while soup supplied by an
Education Authority pauperises, soup tickets supplied by a philanthropic society do
not. And it has few of its advantages. For private philanthropy tends to be more
irregular and arbitrary in its administration than most public authorities. Since it
cannot cover the whole area of distress, its selection of children to be fed is more
capricious; since its funds are raised by appeals ad misericordiam they often fail
when they are needed most; and when, as often happens, more than one agency
enters the field, the result is overlapping and duplication. Nor will it seem a minor
evil to those who care for the civic spirit that even the best-intentioned charity can
never escape from the taint of patronage, can never be anything but a sop with
which the rich relieve their consciences by ministering to the poor.
The statement that the feeding of school children weakens parental responsibility
presumably means that the provision of meals at school induces parents to neglect
to provide meals themselves. When one turns from these general considerations to
examine how far this result has actually occurred, one is faced with the task of
sifting a few grains of fact from a multitude of impressions. The first and most
essential preliminary to the formation of any reasonable judgment is to determine
the circumstances of those families one or more of whose members are receiving
meals at school; and in order to throw some light on this point we give, in the
following table, such particulars from six areas as are available:—[531]
testbankdeal.com