Void product( void )

{

int a;

int b;

int c;

int result;

cout << "Enter three integers: ";

cin >> a >> b >> c;

result = a * b * c;

cout << "Result is " << result;

}

Question: Why would a function prototype contain a parameter type declaration such as

double &?

This creates a reference parameter of type "reference to double" that enables the function

To modify the original variable in the calling function

Question: All arguments to function calls in C++ are passed by value

False

Question: Lists and tables of values can be stored in __________ or __________.

Arrays, vectors

Question: The elements of an array are related by the fact that they have the same

________ and ___________.

Name, type

Question: The number used to refer to a particular element of an array is called its

________.

Subscript (or index)

Question: A(n) __________ should be used to declare the size of an array, because it

makes the program more scalable

Constant variable

Question: The process of placing the elements of an array in order is called ________

the array

Sorting

The process of determining if an array contains a particular key value is called

_________ the array

Searching

Question: An array that uses two subscripts is referred to as a(n) _________ array

Two-dimensional

Question: An array can store many different types of values

False

Question: An array subscript should normally be of data type float

False

Question: If there are fewer initializers in an initializer list than the number of elements

in the array, the remaining elements are initialized to the last value in the initializer list

False

Question: It is an error if an initializer list contains more initializers than there are

elements in the array

True

Question: An individual array element that is passed to a function and modified in that

function will contain the modified value when the called function completes execution

False

Question: Write one or more statements that perform the following task for and array

called “fractions”. Define a constant variable arraySize initialized to 10.

const int arraySize = 10;

Question: Write one or more statements that perform the following task for and array

called “fractions”. Declare an array with arraySize elements of type double, and initialize

the elements to 0.

double fractions[ arraySize ] = { 0.0};

Question: Write one or more statements that perform the following task for and array

called “fractions”. Name the fourth element of the array

fractions[ 3 ]

Question: Write one or more statements that perform the following task for and array

called “fractions”. Refer to array element 4

fractions[ 4 ]

Question: Write one or more statements that perform the following task for and array

called “fractions”. Assign the value 1.667 to array element 9

fractions[ 9 ] = 1.667;

Question: Write one or more statements that perform the following task for and array

called “fractions”. Assign the value 3.333 to the seventh element of the array

fractions[ 6 ] = 3.333;

Question: Write one or more statements that perform the following task for and array

called “fractions”. Print array elements 6 and 9 with two digits of precision to the right of

the decimal point.

cout << fixed << setprecision (2); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;

Question: Write one or more statements that perform the following task for and array

called “fractions”. Print all the array elements using a for statement. Define the integer

variable i as a control variable for the loop.

for (int i = 0; < arraySize; i++) cout << "fractions[" < i << "] = " << fractions[ i ] <<

endl;

Question: Declare the array to be an integer array and to have 3 rows and 3 columns.

Assume that the constant variable arraySize has been defined to be 3:

int table[ arraySize ][ arraySize];

Question: Write a program segment to print the values of each element of array table in

tabular format with 3 rows and 3 columns. Assume that the array was initialized with the

declaration

int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } };

and the integer variables i and j are declared as control variables.

cout << " [0] [1] [2]" << endl;

for (int i = 0; i < arraySize; i++) { cout << '[' << i << "] ";

for (int j = 0; j < arraySize; j++)

cout << setw(3) << table[ i ][ j ] << " ";

cout << endl;

Question: Find the error in the following program segment and correct the error:

#include <iostream>;

#include <iostream>

Question: Find the error in the following program segment and correct the error:

arraySize = 10; // arraySize was declared const

const int arraySize=10;

Question: Find the error in the following program segment and correct the error:

Assume that int b[ 10 ] = { 0 };

for (int i = 0; <= 10; i++)

b[ i ] = 1;

for (int i = 0; <= 9; i++)

b[ i ] = 1;

Question: the error in the following program segment and correct the error:

Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };

a[ 1, 1 ] = 5;

a[ 1, 1 ] = 5;

Question: A pointer is a variable that contains as its value the____________ of another

variable


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: