Study Guide III Questions

studied byStudied by 5 people
5.0(1)
Get a hint
Hint

An array is an example of a structured data type.

True

False

1 / 59

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

60 Terms

1

An array is an example of a structured data type.

True

False

True

New cards
2

All components of an array are of the same type.

True

False

True

New cards
3

If array index goes out of bounds, the program always terminates in an error.

True

False

False

New cards
4

Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.

True

False

False

New cards
5

The word const is used before the array declaration in a function heading to prevent the function from modifying the array.

True

False

True

New cards
6

The base address of an array is the memory location of the first array component.

True

False

True

New cards
7

A function cannot return a value of the type array.

True

False

True

New cards
8

Two arrays are parallel if they hold the same type of data.

True

False

False

New cards
9

When a two-dimensional array is declared as a parameter, the C++ compiler ignores the sizes of both dimensions.

True

False

False

New cards
10

Which of the following statements declares alpha to be an array of 25 components of the type int?

int alpha[25];

int array alpha[25];

int alpha[2][5];

int array alpha[25][25];

int alpha[25];

New cards
11

Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList?

0 through 99

0 through 100

1 through 100

1 through 101

0 through 99

New cards
12

Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list? \n

\n for (int j = 1; j < 10; j++) \n      cout << list[j] << " "; \n cout << endl;

\n for (int j = 0; j <= 9; j++) \n      cout << list[j] << " "; \n cout << endl;

for (int j = 1; j < 11; j++)

cout << list[j] << " "; \n cout << endl;

\n

for (int j = 1; j <= 10; j++) \n     cout << list[j] << " "; \n cout << endl;

for (int j = 0; j <= 9; j++) \n      cout << list[j] << " "; \n cout << endl;

New cards
13

What is the output of the following C++ code? \n   \n int list[5] = {0, 5, 10, 15, 20}; \n int j; \n   \n for (j = 0; j < 5; j++) \n      cout << list[j] << " "; \n cout << endl; \n

0 1 2 3 4

0 5 10 15

0 5 10 15 20

5 10 15 20

0 5 10 15 20

New cards
14

What is the output of the following C++ code? \n   \n int alpha[5] = {2, 4, 6, 8, 10}; \n int j; \n   \n for (j = 4; j >= 0; j--) \n     cout << alpha[j] << " "; \n cout << endl; \n

2 4 6 8 10

4 3 2 1 0

8 6 4 2 0

10 8 6 4 2

10 8 6 4 2

New cards
15

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?

\n  for (j = 0; j <= 49; j++) \n     cout << gamma[j] << " ";

\n for (j = 1; j < 50; j++) \n     cout << gamma[j] << " ";

\n for (j = 0; j <= 50; j++) \n     cout << gamma[j] << " ";

\n

for (j = 0; j <= 48; j++) \n     cout << gamma[j] << " ";

for (j = 0; j <= 50; j++) \n     cout << gamma[j] << " ";

New cards
16

Consider the following declaration int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement?

int alpha[] =  {3, 5, 7, 9, 11};

int alpha[] =  {3 5 7 9 11};

int alpha[5] = [3, 5, 7, 9, 11];

int alpha[] =  (3, 5, 7, 9, 11);

int alpha[] =  {3, 5, 7, 9, 11};

New cards
17

Consider the following declaration int alpha[3];. Which of the following input statements correctly inputs values into alpha?

\n cin >> alpha \n     >> alpha \n     >> alpha;

\n cin >> alpha[0] \n     >> alpha[1] \n     >> alpha[2];

\n cin >> alpha[1] \n     >> alpha[2] \n     >> alpha[3];

\n cin >> alpha;

cin >> alpha[0] \n     >> alpha[1] \n     >> alpha[2];

New cards
18

Consider the following statement: double alpha[10][5];. The number of components of alpha is ____.

15

50

100

150

50

New cards
19

Consider the statement int list[10][8];. Which of the following about list is true?

list has 10 rows and 8 columns.

list has 8 rows and 10 columns.

list has a total of 18 components.

list has a total of 108 components.

list has 10 rows and 8 columns.

New cards
20

After the following statements execute, what are the contents of matrix? \n   \n int matrix[3][2]; \n int j, k; \n   \n for (j = 0; j < 3; j++) \n     for (k = 0; k < 2; k++) \n         matrix[j][k] = j + k; \n

\n   \n 0 0 \n 1 1 \n 2 2

\n   \n 0 1 \n 2 3 \n 4 5

\n   \n 0 1 \n 1 2 \n 2 3

\n   \n 1 1 \n 2 2 \n 3 3

0 1 \n 1 2 \n 2 3

New cards
21

Given the following declaration: \n   \n int j; \n int sum; \n double sale[10][7]; \n   \n which of the following correctly finds the sum of the elements of the fifth row of sale?

\n sum = 0; \n for(j = 0; j < 7; j++) \n     sum = sum + sale[5][j];

\n sum = 0; \n for(j = 0; j < 7; j++) \n     sum = sum + sale[4][j];

\n sum = 0; \n for(j = 0; j < 10; j++) \n     sum = sum + sale[5][j];

\n sum = 0; \n for(j = 0; j < 10; j++) \n     sum = sum + sale[4][j];

sum = 0; \n for(j = 0; j < 7; j++) \n     sum = sum + sale[4][j];

New cards
22

Given the following declaration: \n   \n int j; \n int sum; \n double sale[10][7]; \n   \n which of the following correctly finds the sum of the elements of the fourth column of sale?

\n sum = 0; \n for(j = 0; j < 7; j++) \n     sum = sum + sale[j][3];

\n sum = 0; \n for(j = 0; j < 7; j++) \n     sum = sum + sale[j][4];

\n sum = 0; \n for(j = 0; j < 10; j++) \n     sum = sum + sale[j][4];

\n sum = 0; \n for(j = 0; j < 10; j++) \n     sum = sum + sale[j][3];

sum = 0; \n for(j = 0; j < 10; j++) \n     sum = sum + sale[j][3];

New cards
23

A struct is a homogeneous data structure with all components of the same type.

True

False

False

New cards
24

Both arrays and structs are examples of structured data types.

True

False

True

New cards
25

Memory is allocated when you define a struct.

True

False

False

New cards
26

A struct can be passed as a parameter to a function by value or by reference.

True

False

True

New cards
27

The contents of a struct variable must be written one member at a time.

True

False

True

New cards
28

A function can return a value of the type struct.

True

False

True

New cards
29

The component type of an array cannot be a struct.

True

False

False

New cards
30

A member of a struct can be another struct.

True

False

True

New cards
31

A struct is typically a ____ data structure.

simple

dynamic

heterogeneous

linked

heterogeneous

New cards
32

The components of a struct are called the ____ of the struct.

variables

identifiers

elements

members

members

New cards
33

Which of the following struct definitions is correct in C++?

\n struct studentType \n { \n     int ID; \n };

\n struct studentType \n { \n     string name; \n     int ID; \n     double gpa; \n }

\n int struct studentType \n { \n     ID; \n }

\n struct studentType \n { \n     int ID = 1; \n };

struct studentType \n { \n     int ID; \n };

New cards
34

Consider the following struct definition \n   \n struct rectangleData \n { \n     double length; \n     double width; \n     double area; \n     double perimeter; \n }; \n   \n Which of the following variable declarations is correct?

rectangle rectangleData;

struct rectangleData();

rectangleData myRectangle;

rectangleData rectangle = new rectangleData();

rectangleData myRectangle;

New cards
35

Typically, in a program, a struct is defined ____ in the program.

in the main function

before the definitions of all the functions

after the definitions of all the functions

in any function

before the definitions of all the functions

New cards
36

The syntax for accessing a struct member is structVariableName____.

.memberName

*memberName

[memberName]

$memberName

.memberName

New cards
37

Consider the following statements. \n   \n struct rectangleData \n { \n     double length; \n     double width; \n     double area; \n     double perimeter; \n }; \n   \n rectangleData bigRect; \n   \n Which of the following statements correctly initializes the component length of bigRect?

bigRect = {10};

bigRect.length = 10;

length[0]= 10;

bigRect[0]= 10

bigRect.length = 10;

New cards
38

In C++, the ____ symbol is an operator, called the member access operator.

:(colon)

.(dot)

,(comma)

$ (dollar sign)

.(dot)

New cards
39

Consider the following statements. \n   \n struct rectangleData \n { \n     double length; \n     double width; \n     double area; \n     double perimeter; \n }; \n   \n rectangleData bigRect; \n   \n Which of the following statements is valid in C++?

cin >> bigRect;

cin >> bigRect.length;

perimeter = 2 * (length + width);

area = length * width;

cin >> bigRect.length;

New cards
40

A struct variable can be passed as a parameter ____.

only by const

only by reference

only by value

either by value or by reference

either by value or by reference

New cards
41

A class is an example of a structured data type.

True

False

True

New cards
42

A public member function of a class can access only other public members of the class.

True

False

False

New cards
43

By default, all members of a class are public.

True

False

False

New cards
44

If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables.

True

False

False

New cards
45

Given the declaration \n   \n class myClass \n { \n public: \n     void print();  //Output the value of x; \n     MyClass(); \n   \n private: \n     int x; \n }; \n   \n myClass myObject; \n   \n The following statement is legal. \n   \n myObject.x = 10;

True

False

False

New cards
46

An accessor function of a class first accesses the values of a member variable of the class and then changes the values of the member variable.

True

False

False

New cards
47

A mutator function of a class changes the values of the member variable(s) of the class.

True

False

True

New cards
48

The public members of a class must be declared before the private members.

True

False

False

New cards
49

A constructor has no type and is therefore a void function.

True

False

False

New cards
50

The constructor with no parameters is called the default constructor.

True

False

True

New cards
51

A constructor with one or more default parameters is called the default constructor.

True

False

False

New cards
52

The destructor automatically executes when the class object goes out of scope.

True

False

True

New cards
53

The components of a class are called the ____ of the class.

elements

members

objects

properties

members

New cards
54

If a member of a class is ____, you cannot access it outside the class.

public

automatic

private

static

private

New cards
55

In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the parameter declaration.

automatic

private

static

const

const

New cards
56

In C++, the scope resolution operator is ____.

:

::

$

.

::

New cards
57

A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function.

accessor

mutator

constructor

destructor

accessor

New cards
58

To guarantee that the member variables of a class are initialized, you use ____.

accessors

mutators

constructors

destructor

constructors

New cards
59

How many destructors can a class have?

no explicit destructors

one

two

any number

one

New cards
60

A destructor has the character ____, followed by the name of the class.

.

::

#

~

~

New cards

Explore top notes

note Note
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 118 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 86 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 23 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 12 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 33 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 20 people
Updated ... ago
4.5 Stars(2)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard146 terms
studied byStudied by 14 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard85 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard50 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard106 terms
studied byStudied by 15 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard118 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard52 terms
studied byStudied by 172 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard40 terms
studied byStudied by 13 people
Updated ... ago
4.0 Stars(5)
flashcards Flashcard164 terms
studied byStudied by 42 people
Updated ... ago
5.0 Stars(1)