CS 150 chapter 6,8,9,10

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Rows of alpha are numbered 0...24 and columns are numbered 0...9.

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.

list has 10 rows and 8 columns.

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 a total of 18 components. c. list has a total of 108 components. d. list has 8 rows and 10 columns.

selection

For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n-1) item assignments.

void

Functions that do not have a return type are called ____ functions.

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

Given the following declaration: 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?

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

Given the following declaration: 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?

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

.(dot)

The syntax for accessing a struct member is structVariableName____.

.memberName

n-dimensional array

A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is called a(n) ____.

stub

A function ____________________ is a function that is not fully coded.

a declaration, but not a definition

A function prototype is ____.

automatic

A variable for which memory is allocated at block entry and deallocated at block exit is called a(n) ____________________ variable.

static

A variable for which memory remains allocated as long as the program executes is called a(n) ____________________ variable.

formal

A variable listed in a header is known as a(n) ____ parameter.

actual parameter

A variable or expression listed in a call to a function is called the ____.

reference

A(n) ____________________ parameter is a formal parameter that receives the location (memory address) of the corresponding actual parameter.

value

A(n) ____________________ parameter s a formal parameter that receives a copy of the content of the corresponding actual parameter.

0 1 1 2 2 3

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

True

Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0) return x; else return x + 1;

98

Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____.

0 through 99

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 999

Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid for the index of the array salesData?

beta[0]

Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta? a. beta['2'] b. beta['50'] c. beta[0] d. beta[50]

discard = '\n'

Consider the following declaration: char charArray[51]; char discard; Assume that the input is: Hello There! How are you? What is the value of discard after the following statements execute? cin.get(charArray, 51); cin.get(discard); a. discard = ' ' (Space) b. discard = '\n' c. discard = '\0' d. discard = '!'

strcpy(str, "Blue Sky");

Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str?

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

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

50

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

Consider the following statements. struct personalInfo { string name; int age; double height; double weight; }; struct commonInfo { string name; int age; }; personalInfo person1, person2; commonInfo person3, person4; Which of the following statements is valid in C++? a. person1 = person3; b. person2 = person1; c. person2 = person3; d. person2 = person4;

b. person2 = person1;

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

before the definitions of all the functions

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? a. rectangleType.print(); b. rectangleType::print(); c. bigRect.print(); d. bigRect::print();

c. bigRect.print();

In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration. a. private b. static c. const d. automatic

c. const

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Consider the accompanying class definition. Which of the following variable declarations is correct? a. rectangle rectangleType; b. rectangle rectangleType.area; c. rectangleType rectangle; d. class rectangleType rectangle;

c. rectangleType rectangle;

class secretType { public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY(); private: int x; static int y; }; secretType::secretType() { x = 1; } secretType::secretType(int a) { x = a; } void secretType::print() { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY() { y++; } Consider the accompanying class and member functions definitions. How many constructors are present in the class definition? a. none b. one c. two d. three

c. two

You can assign the value of one struct variable to another struct variable of ____ type.

c. the same

A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member. a. $ b. + c. - d. #

d. #

A ____ sign in front of a member name on a UML diagram indicates that this member is a public member. a. # b. - c. $ d. +

d. +

What does ADT stand for? a. asynchronous data transfer b. abstract definition type c. alternative definition type d. abstract data type

d. abstract data type

A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function. a. destructor b. mutator c. constructor d. accessor

d. accessor

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? a. none b. zero c. two d. three

d. three

A struct is typically a ____ data structure

heterogeneous

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

members

Consider the following struct definition struct rectangleData { double length; double width; double area; double perimeter; }; Which of the following variable declarations is correct? a. rectangleData rectangle = new rectangleData(); b. rectangle rectangleData; c. struct rectangleData(); d. rectangleData myRectangle;

rectangleData myRectangle;

An array name and index are separated using ____.

square brackets

b. cout << tryMe(2.0, 3.0);

Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared. a. cin >> tryMe(x); b. cout << tryMe(2.0, 3.0); c. cout << tryMe(tryMe(double, double), double); d. cout << tryMe(tryMe(float, float), float);

b. cout << myFunc(myFunc(7, 8), 15);

Given the following function prototype: int myFunc(int, int);, which of the following statements is valid? Assume that all variables are properly declared. a. cin >> myFunc(y); b. cout << myFunc(myFunc(7, 8), 15); c. cin >> myFunc('2', '3'); d. cout << myFunc(myFunc(7), 15);

c. int u = test(5.0, '*');

Given the following function prototype: int test(float, char);, which of the following statements is valid? a. cout << test(12, &); b. cout << test("12.0", '&'); c. int u = test(5.0, '*'); d. cout << test('12', '&');

7

Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement? cout << next(next(5)) << endl;

-1

Given the following function: int strange(int x, int y) { if (x > y) return x + y; else return x - y; } what is the output of the following statement? cout << strange(4, 5) << endl;

d. cout << test(7, 14, 23);

Given the function prototype: float test(int, int, int); which of the following statements is legal? a. cout << test(7, test(14, 23)); b. cout << test(test(7, 14), 23); c. cout << test(14, 23); d. cout << test(7, 14, 23);

a. cout << testAlpha(5, 'A', 2);

Given the function prototype: double testAlpha(int u, char v, double t); which of the following statements is legal? a. cout << testAlpha(5, 'A', 2); b. cout << testAlpha( int 5, char 'A', int 2); c. cout << testAlpha('5.0', 'A', '2.0'); d. cout << testAlpha(5.0, "65", 2.0);

variable

If a formal parameter is a nonconstant reference parameter, during a function call, its corresponding actual parameter must be a(n) ____________________.

void

If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ____________________ function and use the appropriate reference parameters to return the values.

False

If the formal parameter list of a function is empty, the parentheses after the function name are not needed.

scope resolution operator

In C++, :: is called the ____________________.

True

In C++, a function prototype is the function heading without the body of the function.

'\0'

In C++, the null character is represented as ____.

structured

In a(n) ____________________ data type, each data item is a collection of other data items.

first row is stored first

In row order form, the ____. a. first row is stored last b. first row is stored first c. first column is stored first d. first column is stored last

True

Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.

reference

Stream variables (for example, ifstream and ofstream) should be passed by ____________________ to a function.

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

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 <= 50; j++) cout << gamma[j] << " "; b. for (j = 1; j < 50; j++) cout << gamma[j] << " "; c. for (j = 0; j <= 48; j++) cout << gamma[j] << " "; d. for (j = 0; j <= 49; j++) cout << gamma[j] << " ";

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

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

for (int j = 0; j <= 49; j++) sales[j] = 0.0;

Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the array sales?

True

T/F? All components of an array are of the same data type.

False

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

False

T/F? 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.

False

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

True

T/F? In a two-dimensional array, the elements are arranged in a table form.

False

T/F? 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; for (int i = 0; i < 25; i++) sum = sum + list;

False

T/F? The array index can be any integer less than the array size.

True

T/F? The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.

False

T/F? The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0.

True

T/F? When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter.

signature

The ____________________ of a function consists of the function name and its formal parameter list.

base address

The ____________________ of an array is the address (that is, the memory location) of the first array component.

scope

The ____________________ of an identifier refers to where in the program an identifier is accessible (visible).

True

The data type of a variable in a return statement must match the function type.

False

The execution of a return statement in a user-defined function terminates the program.

True

The following function heading in a C++ program is valid: int funcExp(int u, char v, float g)

False

The following return statement returns the value 10. return 10, 16;

range-based

The form of the for loop shown below is called a(n) ____________________ for loop. for (dataType identifier : arrayName) statements

False

The function main is always compiled first, regardless of where in the program the function main is placed.

function header

The heading of the function is also called the ____.

8.0

The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____.

'$'

The output of the statement: cout << tolower('$') << endl; is ____.

14.0

The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.

driver

The program that tests a function is called a(n) ____________________ program.

<cmath>

The standard header file for the abs(x)function is ____.

6

The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.

6

The statement: return 37, y, 2 * 3; returns the value ____.

10

The statement: return 8, 10; returns the value ____.

const

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

<cctype>

To use the predefined function tolower, the program must include the header file ____.

True

Using functions greatly enhances a program's readability because it reduces the complexity of the function main.

10 8 6 4 2

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

0 5 10 15 20

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

Code results in index out-of-bounds

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

5

What is the value of alpha[2] after the following code executes? int alpha[5]; int j; for (j = 0; j < 5; j++) alpha[j] = 2 * j + 1;

6

What value is returned by the following return statement? int x = 5; return x + 1;

reference

When you attach & after the dataType in the formal parameter list of a function, the variable following that dataType becomes a(n) ____________________ parameter.

int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};

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}};

char name[8] = "William";

Which of the following correctly declares name to be a character array and stores "William" in it?

a. int funcExp(int x, float v);

Which of the following function prototypes is valid? a. int funcExp(int x, float v); b. funcExp(int x, float v){}; c. funcExp(void); d. int funcExp(x);

d. int funcTest(int, int, float);

Which of the following function prototypes is valid? a. int funcTest(int x, int y, float z){} b. funcTest(int x, int y, float){}; c. int funcTest(int, int y, float z) d. int funcTest(int, int, float);

int alpha[25];

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

b. Prototypes end with a semicolon, but headers do not.

Which statement below about prototypes and headers is true? a. Parameter names must be listed in the prototype, but not necessarily in the header. b. Prototypes end with a semicolon, but headers do not. c. Headers should come before prototypes. d. Headers end with a semicolon, but prototypes do not.

Local

____________________ identifiers are not accessible outside of the function (block).

Reference or reference

____________________ parameters are useful in three situations: • When the value of the actual parameter needs to be changed • When you want to return more than one value from a function • When passing the address would save memory space and time relative to copying a large amount of data

In C++, the ____ is called the member access operator. a. . b. , c. :: d. #

a. .

Consider the following statements. struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++? a. cin >> bigRect.length >> width; b. cout << bigRect.length; c. cout << bigRect; d. cout << length;

b. cout << bigRect.length;

Which of the following is true about classes and structs? a. By default, all members of a struct are public and all members of a class are private. b. A struct variable is passed by value only, and a class variable is passed by reference only. c. An assignment operator is allowed on class variables, but not on struct variables. d. You cannot use the member access specifier private in a struct.

a. By default, all members of a struct are public and all members of a class are private.a. By default, all members of a struct are public and all members of a class are private.

A class and its members can be described graphically using a notation known as the ____ notation. a. UML b. OOD c. OOP d. OON

a. UML

To guarantee that the member variables of a class are initialized, you use ____. a. constructors b. destructor c. accessors d. mutators

a. constructors

If a function of a class is static, it is declared in the class definition using the keyword static in its ____. a. heading b. parameters c. main function d. return type

a. heading

The components of a class are called the ____ of the class. a. members b. objects c. elements d. properties

a. members

A class object can be ____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates. a. static b. automatic c. local d. public

a. static

A destructor has the character ____, followed by the name of the class. a. ~ b. . c. :: d. #

a. ~

If a member of a class is ____, you cannot access it outside the class. a. automatic b. private c. static d. public

b. private

In C++, the scope resolution operator is ____. a. $ b. :: c. . d. :

b. ::

A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block. a. public b. automatic c. local d. static

b. automatic

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class? a. clock b. clockType c. Type d. +clockType

b. clockType

How many destructors can a class have? a. no explicit destructors b. one c. two d. any number

b. one


Kaugnay na mga set ng pag-aaral

ITEC 3325 Final, MIS 3000 exam 3

View Set

APUSH Chapters 10-27, 31, 32, 33

View Set

health promotion and maintenance

View Set

Foundations Exam 1 Chapter 20 PrepU

View Set

Types of Life Insurance Policies

View Set