C++ test 3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

.5 Q2: Which of the following is not a bitwise operator? a. ^ b. >> c. ~ d. *

d. *

.5 Q4: Evaluate ( 00001000 & 11000101 ) ^ ( 11110000 ). a. 00001101 b. 11000000 c. 00111101 d. 11110000

d. 11110000

.2 Q2: In order to perform file processing in C++, which header files must be included? a. <cstdio> , <iostream>; and <fstream>. b. <cstdio> and <iostream>. c. <cstdio> and <fstream>. d. <iostream> and <fstream>.

d. <iostream> and <fstream>

3 Q1: The Random library provides: a. pseudo-random number generators b. uniform distributions c. custom distributions d. all of the above

d. all of the above

5 Q1: Regular expressions are used in: a. text editors b. online forms c. IDEs d. all of the above

d. all of the above

.4 Q1: Which of the following will not change the file-position pointer to the same position as the others? Assume a 10-byte file size and a current position at byte # 1. a. fileObject.seekg( 2 ); b. fileObject.seekg( 1, ios::cur ); c. fileObject.seekg( 2, ios::beg ); d. fileObject.seekg( 8, ios::end );

d. fileObject.seekg( 8, ios::end );

.2 Q3: Which of the following is not true about files? a. C++ views each file as a sequential stream of bytes. b. Files are opened by creating objects of stream classes. c. Member functions of stream objects can be applied to file streams. d. istream, ostream and iostream are derived from ifstream, ofstream and fstream, respectively.

d. istream, ostream and iostream are derived from ifstream, ofstream and fstream, respectively.

.5 Q6: For any nonzero 8-bit x, which of the following does not result in zero? a. x & = ( ~x ) b. x ^= x c. x <<= 8 d. x |= x

d. x |= x

.7 Q3: To write fixed-length records, use file open mode: a. ios::app b. ios::ate c. ios::trunc d. ios::binary

: d. ios::binary

What is not a fundamental rule of recursion? 1. Must have a case where recursion is unnecessary (base/trivial/elementary case) 2. It must step through one function at a time 3. Problem must approach that case each pass, i.e. reduce in size

2. It must step through one function at a time

5.1 Q2: The regular expression matches zero or more digits. a. "\d*" b. "\D?" c. "\w{0,}" d. "\d+"

: a. "\d*"

.20 Q2: For which of the following operators does C++ not specify the order of evaluation of its operands? a. +. b. && c. ,. d. ?:.

: a. +.

.6 Q2: A random access file is organized most like a(n): a. Array. b. Object. c. Class. d. Pointer.

: a. Array.

.11 Q1: Select the false statement. a. C++ includes object serialization by default. b. C++ does not include object serialization by default. c. When an object is output to disk, only the values of its attributes are output. d. None of the above.

: a. C++ includes object serialization by default.

.7 Q2: Select the false statement. The reinterpret_cast operator: a. Changes the value of the object to which its operand points. b. Performs its operation at compile time. c. Is compiler-dependent and can cause programs to behave differently on different platforms. d. Is easy to use to perform dangerous manipulations that could lead to serious execution-time errors.

: a. Changes the value of the object to which its operand points.

9 Q1: Which of the following will not be included in C++0x? a. decimal types b. rvalue reference c. template aliases d. variable type deduction

: a. decimal types

6.2 Q2: Use the weak_ptr member function to create a shared_ptr to the resource observed by the weak_ptr. a. lock b. use_count c. reset d. getSharedPtr

: a. lock

.8 Q1: Which of the following functions would not be used to write data randomly to a random access file? a. tellg b. seekp c. write d. All of the above would be used.

: a. tellg

5 Q3: The character class \s represents any: a. whitespace character b. space character c. string character d. non-whitespace character

: a. whitespace character

.9 Q1: For an ifstream object A, a class type B and a local variable of type B called C, the proper way to read in one B object from A into C is: a. A.read( &C, sizeof( B ) ); b. A.read( reinterpret_cast< char * >( &C ), sizeof( B ) ); c. A.read( reinterpret_cast< char * >( &C ), B ); d. A.read( char * ( &C ), sizeof( B ) );

: b. A.read( reinterpret_cast < char * >( &C ), sizeof( B ) );

7 Q1: The unordered associative containers use a to determine where in the container to place the value. a. bucket b. delegator function c. float d. hash function

: d. hash function

4 Q1: Which of the following statements about the Boost Libraries is false? a. Class array allows you to use fixed-size arrays in STL applications rather than vectors (dynamically sized arrays) which are not as efficient when there's no need for dynamic resizing. b. Boost.Regex significantly enhances the regular expression support provided in the C++ base language. c. Smart pointers help you manage dynamically allocated resources (e.g., memory, files and database connections). d. Tuples are often used to return multiple values from a function.

: b. Boost.Regex significantly enhances the regular expression support provided in the C++ base language. [Prior to the new standard, C++ does not support regular expressions.]

.19 Q3: Recursion is memory-intensive because: a. Recursive functions tend to declare many local variables. b. Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack. c. Many copies of the function code are created. d. It requires large data values.

: b. Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack.

6.2 Q1: When the last shared_ptr to a resource is destroyed, all weak_ptrs to that resource . a. are destroyed b. are set to NULL c. are not affected d. can still access the resource

: b. are set to NULL

5.3 Q2: To replace only the first match to a regular expression, you must pass as an argument to regex_replace. a. -1 b. format_first_only c. replace_first_only d. 0

: b. format_first_only

.10 Q1: Select the proper object type. __________ file( "file.dat", ios::in | ios::out ); a. iostream b. fstream c. ofstream d. ifstream

: b. fstream

5 Q2: A program using Boost.Regex must include the header file. a. boost_regex.h b. regex.hpp c. regular_exp.hpp d. regex.h

: b. regex.hpp

6.1 Q1: To use shared_ptrs in your program you must include the header file. a. smart_ptr.hpp b. shared_ptr.hpp c. shared.hpp d. shared_ptr.h

: b. shared_ptr.hpp

9 Q2: A declaration allows you to test certain aspects of a program at compile time. a. compile_time_test b. static_assert c. test d. check

: b. static_assert

5.3 Q1: regex_replace returns a(n): a. bool b. string c. smatch d. void

: b. string

5.2 Q1: The "^" and "$" characters represent: a. back references b. the beginning and end of a string c. the beginning and end of a regular expression d. none of the above

: b. the beginning and end of a string

.20 Q1: Assuming the following pseudocode for the Fibonacci series, what is the value of the 5 th Fibonacci number (fibonacci ( 5 ))? fibonacci( 0 ) = 0 fibonacci( 1 ) = 1 fibonacci( n ) = fibonacci( n - 1 ) + fibonacci( n - 2 ) a. 1. b. 3. c. 5. d. 7.

: c. 5.

.19 Q1: A recursive function is a function that: a. Returns a double. b. Takes 3 arguments. c. Calls itself, directly or indirectly. d. Is inside of another function.

: c. Calls itself, directly or indirectly.

.21 Q1: Recursion is to the base case as iteration is to what: a. The counter. b. A repetition structure. c. Failure of the loop continuation test. d. A selection structure.

: c. Failure of the loop continuation test.

3 Q2: Which of the following statements is false? a. Boost is an online repository of free, peer-reviewed, open source C++ libraries. b. The Boost software license grants the rights to copy, modify, use and distribute the Boost source code and binaries for any commercial and non-commercial use. c. There are approximately 1000 libraries in Boost with more being added frequently. d. Boost has a formal acceptance process to ensure high-quality and portability.

: c. There are approximately 1000 libraries in Boost with more being added frequently. [There are approximately 100 libraries.]

.7 Q1: Select the false statement. The write function: a. Creates unformatted data. b. Expects data type const char * as its first argument. c. Writes to files in hexadecimal format. d. Takes an argument of type size_t.

: c. Writes to files in hexadecimal format.

5.1 Q3: The dot character (.) matches: a. any visible character b. any nonvisible character c. any character d. any character except a newline

: c. any character

5.1 Q1: The regular expression "A{5,}" matches: a. less than 5 A's b. exactly 5 A's c. at least 5 A's d. none of the above

: c. at least 5 A's

5.2 Q2: The regular expression "[^0-9]+:\s\d{2,}" matches: a. "123: Jones" b. "John 32145" c. "A7" d. "j: 16"

: d. "j: 16"

.19 Q2: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number <= 1 ) return 1; else return number * mystery( number - 1 ); } a. 0. b. 1. c. 4. d. 24.

: d. 24.

.6 Q1: Random access files are more effective than sequential files for: a. Instant access to data. b. Updating data easily. c. Inserting data into the file without destroying other data. d. All of the above.

: d. All of the above.

.21 Q2: All of the following are reasons to use recursion except: a. An iterative solution is not apparent. b. The resulting program is easier to debug. c. It more naturally mirrors the problem. d. It maximizes execution performance.

: d. It maximizes execution performance.

.5 Q1: Which of the following is not a disadvantage of trying to modify a sequential access file? a. Modifying data can potentially destroy other data. b. It may be necessary to rewrite every record in the file to make a slight change. c. Things that are stored in the same number of "raw data" bytes internally may not take up the same amount of space in a file. d. Overwriting a record with another record of the same size is very difficult.

: d. Overwriting a record with another record of the same size is very difficult.

8 Q1: C++0x will be a. easier to learn b. better for building libraries c. more compatible with C d. all of the above

: d. all of the above

6.1 Q2: Which of the following is not a member function or operation of shared_ptr. a. reset b. use_count c. -> d. delete

: d. delete

A thread a) is a separately-executable unit of work that shares memory with the owning process b) has its own virtual address space c) is not appropriate for long-running tasks d) will unravel if pulled

a) is a separately-executable unit of work that shares memory with the owning process

.6 Q3: __________ is not allowed. a. Accessing individual bits in a multi-bit bit field. b. Padding a bit field with bits that cannot be accessed. c. Having an unnamed bit field. d. Having a bit field with a zero width.

a. Accessing individual bits in a multi-bit bit field.

.5 Q1: The most basic unit of data on a computer is the: a. Bit. b. Byte. c. File. d. int.

a. Bit.

7 Q2: The library in TR1 is based on a Boost library. a. Regex b. Unordered Associative Containers c. Date d. all of the above

a. Regex

.6 Q1: A bit field must be declared as a: a. int or unsigned. b. char. c. float. d. long.

a. int or unsigned.

.3 Q2: Which file open mode would be used to write data only to the end of an existing file? a. ios::app b. ios::in c. ios::out d. ios::trunc

a. ios::app

Locks: a) Are a software security device to prevent unauthorized access to code at run-time b) Can be used to manage concurrent access to shared variables c) Are prohibitively difficult to implement

b) Can be used to manage concurrent access to shared variables

.6 Q2: The number of bits in a bit field is specified with: a. Parentheses as in bitfield( 4 ) b. A colon as in bitfield : 4 c. Brackets as in bitfield[ 4 ] d. A dot as in bitfield.4

b. A colon as in bitfield : 4

.3 Q1: Select the false statement. a. C++ imposes no structure on a file. b. C++ files include information about their structure. c. The programmer must impose a structure on a file. d. C++ files do not understand notions such as "records" and "fields."

b. C++ files include information about their structure.

.4 Q2: What is not true about this code segment? location = fileObject.tellg(); a. tellg is a member function of fileObject. b. location is a pointer. c. The value of location after the segment executes must be less than or equal to the number of bytes in the file attached to fileObject. d. fileObject is an istream object.

b. location is a pointer.

.2 Q1: Which of the following does not have a stream associated with it? a. cerr. b. cin. c. cout. d. All of the above have streams associated with them.

c. All of the above have streams associated with them.

.5 Q3: Let Bit1 = Bit2 = 1. Which of the following does not have the same result as the others? a. Bit1 & Bit2 b. Bit1 | Bit2 c. Bit1 ^ Bit2 d. ~( ~Bit2 )

c. Bit1 ^ Bit2

2: A merge sort operation runs in: a. O(log n) time. b. O(n) time. c. O(n log n) time. d. O(n 2 ) time.

c. O(n log n) time.

.5 Q5: Let x be an unsigned int on a machine with 4-byte unsigned ints. What effect does x>>=1; x<<=1; have? a. There is no effect. b. The leftmost bit of x is set to 0. c. The rightmost bit of x is set to 0. d. Both (b) and (c).

c. The rightmost bit of x is set to 0.

.3 Q3: When used with ofstream objects, operator! is not: a. Overloaded. b. Used to determine if the open operation succeeded. c. Used to close a file explicitly. d. Used to return a nonzero value if an error occurs.

c. Used to close a file explicitly.

1: The merge sort algorithm: a. Can be used only on vectors of even length. b. Works by reducing vectors down to the base case of a two-element vector. c. Works by merging two sorted vectors into one larger sorted vector. d. Cannot be implemented recursively.

c. Works by merging two sorted vectors into one larger sorted vector.


Ensembles d'études connexes

A&P3 - Week 6 - Blood Vessels Part. 1

View Set

Frankenstein Chapter 5 & 6 Questions

View Set

Texas Real Estate Finance: Chapter 9 - Lender Loan Processes

View Set