CSCI 1943 - BRCC

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is the output after the following code executes? int numerator = 5; int denominator = 25; int temp = 0; temp = numerator; numerator = denominator; denominator = temp; cout << numerator << "/" << denominator << " = " << (numerator/denominator) << endl;

25/5 = 5

What will the following C++ 11 code display? vector<int> numbers {3, 5 }; for (int val : numbers) cout << val << endl; <br/> - represents a newline

3<br/>5<br/>

The escape sequence that represents the null terminator is

\0

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list.

all but the first dimension

An array can easily be stepped through by using a

for loop

Which of the following is the data type that can be used to create files, read data from them, and write data to them?

fstream

Which of the following is the member function that reads a single character from a file?

get

Passing a structure as a constant reference parameter to a function

guarantees not to result in changes to the structure's members

After the code shown executes, what is true about the following statements?int numbers[] = {0, 1, 2, 3, 4};int *ptr = numbers;ptr++;

ptr will hold the address of numbers [1]

After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1, 2, 3, 4};int *ptr = numbers;ptr++;

ptr will hold the address of numbers[1]

Which of the following is the member function that writes a single character to a file?

put

The following is the pseudocode for which type of algorithm For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 To size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with arrays[start] End For

selection sort

The advantage of a linear search is its

simplicity

To help prevent memory leaks from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used.

smart pointer

A function may return a pointer but the programmer must ensure that the pointer

still points to a valid object after the function ends

The following statement ________.cin >> *num3;

stores the keyboard input into the variable pointed to by num3

The function that accepts a pointer to a C-string as an argument and returns the length of the C-string, not including the null terminator is

strlen

In C++11, you can use a new type of enum known as a(n) ________ (also known as an enum class) to have multiple enumerators with the same name, within the same scope.

strongly typed enum

To access an array element, use the array name and the element's ________.

subscript

To dereference a structure pointer, the appropriate operator is

the -> operator

If a variable uses more than one byte of memory, for pointer purposes its address is

the address of the first byte of storage

If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with

the interger 0 or the value NULL

What will the following statement output?cout << &num1;

the memory address of the variable named num1

The arguments of the strcpy function are

two addresses

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int? unique_ptr<int> int( new uniq ); unique_ptr<uniq> int( new int ); unique_ptr<uniq> uniq( new int ); None of these unique_ptr<int> uniq( new int );

unique_ptr<int> uniq( new int);

Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement: array1 = array2;

False

C++ limits the number of array dimensions to two.

False

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

False

True/False: A linear search can only be implemented with integer values.

False

True/False: A union can only have one member.

False

True/False: Before you can perform a bubble sort, the data must be stored in descending order.

False

True/False: Before you can perform a selection sort, the data must be stored in ascending order.

False

True/False: By default, files are opened in binary mode.

False

True/False: If you attempt to store data past an array's boundaries, it is guaranteed that the compiler will issue an error.

False

True/False: In C++ 11, the range-based for loop is best used in situations where you need the element subscript for some purpose.

False

True/False: It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable.

False

True/False: The C++ compiler performs strict array bounds checking when it encounters an array of characters.

False

True/False: The ampersand (&) is used to dereference a pointer variable in C++.

False

True/False: The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.

False

True/False: The setprecision manipulator cannot be used to format data written to a file.

False

True/False: When used by itself, the ios::app flag causes the file's existing contents to be deleted if the file already exists.

False

True/False: You cannot directly assign an enumerator to an int variable.

False

What does the following statement do? vector<int> v(10);

It creates a vector object with a starting size of 10

If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr;

It declares a structure pointer called pcirc initialized with a null pointer.

In C++11 the range-based for loop is best used in situations where you need the element subscript for some purpose.

True

The amount of memory used by an array depends on the array's data type and the number of elements in the array.

True

True/False: An individual array element can be processed like any other type of C++ variable.

True

True/False: By being able to pass arrays as arguments, you can write your own functions for processing C-strings.

True

True/False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.

True

True/False: If a function is legally prototyped to return an integer value, it can return a structure member that is an integer data type.

True

True/False: If an uppercase character is passed as an argument to toupper, the result will be an uppercase character.

True

True/False: In C++ 11, you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.

True

True/False: In C++ 11, you cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference.

True

True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member.

True

True/False: The ios::hardfail bit is set when an unrecoverable error occurs.

True

True/False: The number of comparisons made by a binary search is expressed in powers of two.

True

True/False: The string class's front and back member functions were introduced in C++ 11.

True

True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.

True

True/False: When passing a file stream object to a function, you should always pass it by reference.

True

An array initialization must be all on one line.

False

Which of the following is the directive you must use to access files from a C++ program?

#include <fstream>

To use the strlen function in a program you must include

#include<cstring>

Regardless of the algorithm being used, a search through an array is always performed A. from highest to lowest B. from lowest to highest C. beginning with the middle element D. using a binary search E. none of the above

E.

When you pass a pointer as an argument to a function, you must -not dereference the pointer in the function's body - dereference the pointer value in the function prototype - None of these -declare the pointer value again in the function call -use the #include<func.ptr.h> statement

None of those

The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function? void swap(int num1, int num2) { int temp = num2; num2 = num1; num1 = temp; }

The swap function must use a reference parameters.

Which of the following is TRUE about this statement? sum += *array++;

This statement assigns the dereferenced pointer's value, then increments the pointer's address.

Which of the following is TRUE about this statement? sum += *array++;

This statement assigns the dereferenced pointer's value, then increments the pointer's address.

The following statement ________.int *ptr = new int;

assigns an address to the variable ptr

When a file is opened, the file stream object's "read position" is

at the beginning of the file

The function that accepts a C-string containing a number as its argument and returns the integer equivalent is

atoi

Subscript numbering in C++________.

begins with zero

Use the delete operator only on pointers that were

created with the new operator

The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in the array Set found to false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array [middle] equals the desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position

binary search

The expression being tested by the statement shown below will evaluate to true if var1 is ________.if (!isdigit(var1))

both an alphabetic character and a symbol such as $ or &

The following is the pseudocode for which type of algorithm? For maxElement = each subscript in the array, from the last to the first For index = 0 To maxElement - 1 If array[index] > array[index + 1] swap array[index] with array[index +1] End If End For End For

bubble sort

An array's size declarator must be a ________ with a value greater than ________.

constant integer expression, zero

ofstream, ifstream, and fstream are

data types

Before a structure can be used it must be

declared

What does the following statement do?double *num2;

declares a pointer variable named num2

Which of the following statements deletes memory that has been dynamically allocated for an array? delete [] array; int delete [ ]; new array = delete; int array = delete memory;

delete [] array;

This vector function returns true if the vector has no elements.

empty

All stream objects have ________ which indicate the position of the stream.

error state bits

With pointer variables you can ________ manipulate data stored in other variables.

indirectly

A(n) ________ can be used to specify the starting values of an array.

initialization list

Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables?

int temp = num2; num2 = num1; num1 = temp;

With an enumerated data type, the enumerators are stored in memory as

integers

Which of the following is the state bit that can be tested to see if the end of an input stream is encountered?

ios:eofbit

To determine whether a character entered is whitespace, use the ________ function.

isspace

If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do?cout << *a.p;

output the dereferenced value pointed to by p

The following is the pseudocode for which type of algorithm? Set found to false Set position to -1 Set index to 0 While found is false and index < number of elements If list[index] is equal to search value found = true position = index End If Add 1 to index End While Return Position

linear search

The name of an array stores the _____ of the first array element.

memory address

The name of a structure is referred to as its paramater tag argument data type none of these

none of these

In C++11, the ________ keyword was introduced to represent address 0.

nullptr

A two-dimensional array can have elements of ________ data type(s).

one

To set up a file to perform I/O you must declare

one or more file stream objects

An element of a two-dimensional array is referred to by ________ followed by ________.

the row subscript of the element, the column subscript of the element

An array can store a group of values, but the values must be

the same data type

A good reason to pass a structure as a constant reference is

to prevent changes to the structure's members

Which statement correctly defines a vector object for holding integers?

vector<int>v;

Which of the following is the member function that can be used to store binary data to a file?

write


Set pelajaran terkait

Pathophysiology FINAL questions (CH. 54)

View Set

Exemplar 10.C - Inflammatory Bowel Disease

View Set

Chapter 22_Transoceanic Encounters and Global Connections

View Set

Managerial Accounting Week 2 Notes

View Set

Physiological and behavioral responses of the neonate

View Set

Chapter 3, Chapter 1, Chapter 2, Econ Chapter 3,4,6,7 Review 1, Econ Chapter 3, Econ Chapter 4, Managerial Economics Exam

View Set

AP Macroeconomics Unit 2 Vocabulary

View Set