COP3363 - Ch. 9, 10 and (section 5.11), 11, 13 Quizzes

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared.

20,000

What does the following statement do? double *num2; a. Declares and initializes a pointer variable named num2 b. Declares a double variable named num2 c. Declares a pointer variable named num2 d. Initializes a pointer variable named num2 e. None of these

Declares a pointer variable named num2

Which code segment is more efficient? Segment 1 int num =0; cout<< "Enter in a number..."; cin>> num; Segment 2 int num =0; cout<< "Enter in a number..."; cin>> num; num *= 1;

Segment 1

Which code segment is more efficient? Segment 1 int num =0; cout<< "Enter in a number..."; cin>> num; cout<<"num divide by 2 is = "<<num/2; Segment 2 int num =0; cout<< "Enter in a number..."; cin>> num; num /= 2; cout<<"num divide by 2 is = "<<num;

Segment 1

Which code segment is more efficient? Segment 1 int grade; cout<< "Enter in your grade..."; cin>> grade; while ( grade < 0) { while !( grade >= 0) { cout<< "Enter in your grade..."; cin>> grade; } } Segment 2 int grade; cout<< "Enter in your grade..."; cin>> grade; while ( grade < 0) { cout<< "Enter in your grade..."; cin>> grade; }

Segment 2

Which code segment is more efficient? Segment 1 bool bIs Senior = True; int grade; cout<< "Enter in your grade..."; cin>> grade; if (( grade >= 90) || bIsSenior) cout << "Congrats"; Segment 2 bool bIs Senior = True; int grade; cout<< "Enter in your grade..."; cin>> grade; if (bIsSenior || ( grade >= 90)) cout << "Congrats";

Segment 2

Which code segment is more efficient? Segment 1 int grade; cout<< "Enter in your grade..."; cin>> grade; if ( grade >= 90) cout << "A"; else if ((grade >= 70)&&(grade < 80) cout << "C"; else if ((grade >= 80)&&(grade < 90) cout << "B "; Segment 2 int grade; cout<< "Enter in your grade..."; cin>> grade; if ( grade >= 90) cout << "A"; else if (grade >= 80) cout << "B"; else if (grade >= 70) cout << "C";

Segment 2

Given the following structure declaration, idNum is struct Employee { string name; int idNum; };

a member

A pointer variable is designed to store

a memory address

Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr; a. The statement defines a Rectangle pointer variable named *BoxPtr. b. The statement assigns the value of *BoxPtr to the object Rectangle. c. The statement is illegal in C++. d. The statement declares an object of the class Rectangle.

a. The statement defines a Rectangle pointer variable named *BoxPtr.

When the less than operator (<) is used between two pointer values, the expression is testing whether a. the address of the first variable comes before the address of the second variable in the computer's memory b. the value pointed to by the first is greater than the value pointed to by the second c. the value pointed to by the first is less than the value pointed to by the second d. the first variable was declared before the second variable e. None of these

a. the address of the first variable comes before the address of the second variable in the computer's memory

What will the following statement output? cout << &num1; a. the memory address of the variable named num1 b. the value stored in the variable named num1 c. the string &num1 d. the number 1 e. None of these

a. the memory address of the variable named num1

For the following code, which statement is NOT true? class Point { private: double y; double z; public: double x; }; a. z is not available to code that is written outside the class. b. The name of the class is Point. c. x is available to code that is written outside the class. d. x, y, and z are called members of the class.

a. z is not available to code that is written outside the class.

The function that converts a C-string to an integer and returns the integer value is

atoi

The function that accepts a C-string as an argument and converts the string to a long integer is

atol

The following statement ________.int *ptr = new int; a. results in a compiler error b. assigns an address to the variable ptr c. creates a new pointer named int d. assigns an integer less than 32767 to the variable ptr e. None of these

b. assigns an address to the variable ptr

Which of the following statements outputs the value of the gpa member of element [1] of the student array? a. cout << student1.gpa; b. cout << student[1].gpa; c. cout << student1->gpa; d. cout << firstStudent.gpa; e. None of these

b. cout << student[1].gpa;

Which of the following is used to protect important data? a. the public access specifier b. the private access specifier c. the class protection operator

b. the private access specifier

A good reason to pass a structure as a constant reference is: a. to slow down the function's execution which helps prevent errors b. to prevent changes to the structure's members c. to ensure changes to the structure's members d. to speed up the function's modification of the structure's members

b. to prevent changes to the structure's members

The arguments of the strcpy function are: a. three pointers b. two addresses c. one array and one pointer d. two C-strings e. None of these

b. two addresses

A ________ search is more efficient than a ________ search

binary; linear

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile? a. number >> outFile; b. write(outFile, number); c. outFile << number; d. outFile >> number;

c. outFile << number;

A function may return a pointer but the programmer must ensure that the pointer: a. has not previously been returned by another function b. was received as a parameter by the function c. still points to a valid object after the function ends d. has not been assigned an address

c. still points to a valid object after the function ends

A structure pointer contains: a. the name and address of the structure tag b. the address of a structure tag c. the address of a structure variable d. the dereferenced address of a structure tag

c. the address of a structure variable

If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with a. a nonzero value b. the null terminator '\0' c. the integer 0 or the value NULL d. Any of these e. None of these

c. the integer 0 or the value NULL

What is the result after the following statement executes? char var1 = tolower('A'); a. the character a is output to the monitor b. the character A is output to the monitor c. var1 stores the ASCII value for lowercase 'a' d. var1 stores the character value 'A' e. None of these

c. var1 stores the ASCII value for lowercase 'a'

Dynamic memory allocation occurs a. when a pointer is assigned an incorrect address b. when a pointer fails to dereference the right variable c. when a new variable is created at runtime d. when a new variable is created by the compiler e. None of these

c. when a new variable is created at runtime

The following statement ________. bookList[2].publisher[3] = 't'; a. is illegal in C++ b. will change the name of the second book in bookList to 't' c. will store the character 't' in the fourth element of the publisher member of bookList[2] d. will result in a runtime error

c. will store the character 't' in the fourth element of the publisher member of bookList[2]

A pointer variable may be initialized with: a. an address less than zero b. any nonzero integer value c. any nonzero number d. a valid address in the computer's memory e. None of these

d. a valid address in the computer's memory

Data types that are created by the programmer are known as: a. parameters b. functions c. variables d. abstract data types (ADTs)

d. abstract data types (ADTs)

Which of the following is an example of a C++ primitive data type? a. unsigned char b. unsigned short int c. long double d. All of these

d. all of these

To test whether a character is a numeric digit character, use the ________ function. a. isnumber b. isnumeric c. notAlpha d. isdigit e. None of these

d. isdigit

When a constructor function accepts no arguments, or does NOT have to accept arguments because of default arguments, it is called a(n)

default constructor

Which of the following is automatically called when an object is destroyed?

destructor function

Which of the following statements is NOT valid C++ code? a. int ptr = &num1; b. float num1 = &ptr2; c. int ptr = int *num1; d. All of these are valid e. All of these are invalid

e. All of these are invalid

A declaration for an enumerated type begins with the ________ key word.

enum

Given the following declaration: enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE

false

t/f: In-place member initialization no longer is available in C++11.

false

t/f: You must use the private access specification for all data members of a class.

false

t/f: While a class's member functions may be overloaded, the constructor cannot be overloaded.

false

To write read data from a file, you define an object of the ________ data type

ifstream

To determine whether a character entered is whitespace, use the ________ function. a. iswhitespace b. iswhite c. isspace d. isblank

isspace

In C++ a C-string is a sequence of characters stored in consecutive memory, terminated by a

null character

The ________ sort usually performs fewer exchanges than the ________ sort

selection; bubble

Which of the following is required after the closing brace of the structure definition?

semicolon

To test whether a character is a printable character, use the ________ function.

sprint

You can use the technique known as a member initialization list to initialize members of a class.

true

t/f: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

true


संबंधित स्टडी सेट्स

Conversación Avanzada. Unidad: España.

View Set

Transportation security exam 2 (AVIATION)

View Set