Answer the following statements true (T) or false (F)

1. If we want to find the median of 100 scores, we need 100 separate variables to hold
the data..
2. An array behaves like a list of variables each of which is of the same type and for
which there is a uniform, convenient naming convention that can be declared in a
single line of code. In the explanation, give an example of declaration and access.
3. With arrays, indices start at any number the programmer chooses to indicate in the
definition.
4. The programmer should always use a defined constant in an array declaration.
5. When using an array, it is perfectly legal to access indexed variables with index
values less than 0 or greater than or equal to the declared size of the array.

1. False
We can (much more easily) use an array of 100 of the type of the scores
to find the median.
2. True.
For example, an array of 400 double values is declared
double array[400];
Access for read or write is array[index], where 0<=index<400.
3. False
Index values start at 0, not any other number, and run to one less than
the declared size.
4. True
The reason is flexibility. A program with an array with declared size of
5 only works with a maximum of 5 of whatever the array holds. If things change so
that we need to process 17 of these things, we are faced with the difficult and error
prone task of finding all places in the program that 5 is used as an array size,
including situations where someone has done arithmetic with the 5 and some other
number. Better to use a defined constant from the start.
5. False
These index values are out of range, or simply illegal. The compiler
cannot catch this. Unless you access protected memory doing this, the C++ runtime
system will not catch this mistake either. The programmer has the obligation of
detecting illegal index values or assuring there will be none.

Computer Science & Information Technology

You might also like to view...

Double is a subclass of ____, which is a subclass of Object.

A. Math B. Number C. StrictMath D. System

Computer Science & Information Technology

Which of the following NIST publications focuses on cybersecurity practices and guidelines?

A) Special Publication 1800 series B) FIPS C) ITL bulletins D) NIST Internal or Interagency reports

Computer Science & Information Technology