首页 SSD5单选题答案

SSD5单选题答案

举报
开通vip

SSD5单选题答案Ssd5单选题 Ssd5单选题 1.1.1 1. C++ is said to be an object-oriented language because of its support for (b) (a) C-style comments (b) classes, inheritance, and polymorphism (c) attendant algorithms (d) pointers 2. Which of the following statements about C++ is (are) ...

SSD5单选题答案
Ssd5单选题 Ssd5单选题 1.1.1 1. C++ is said to be an object-oriented language because of its support for (b) (a) C-style comments (b) classes, inheritance, and polymorphism (c) attendant algorithms (d) pointers 2. Which of the following statements about C++ is (are) true (c) It is strongly typed. It has been standardized by ISO. (a) None (b) I only (c) I and II (d) II only 1.1.2 1. All of the following characters are allowed to be part of a valid C++ identifier except (a) (a) - (hyphen) (b) _ (underscore) (c) X (d) 3 2. To produce an executable image, a C++ source file must be _____, then _____, and finally _____. (c) (a) linked, preprocessed, compiled (b) compiled, preprocessed, linked (c) preprocessed, compiled, linked (d) compiled, linked, preprocessed 3. At the end of the _____ stage for a C++ program, a(n) _____ can be produced. (c) (a) linking, source file (b) preprocessing, object file (c) linking, executable image (d) compiling, preprocessed file 4. In C++, the directive #include is processed by the (a) (a) preprocessor (b) Standard Template Library (c) linker (d) compiler 1.2.1 1. Lines at a store, file cabinets, and bookcases are real-world entities that most resemble _____ in computer science. (a) (a) data structures (b) functional programming languages (c) algorithms (d) object-oriented programming languages 2. In computer science, a structured representation of information is known as a(n) (b) (a) cache (b) data structure (c) algorithm (d) processor 3. An ordered set of directives that can be carried out mechanically is known as a(n) (b) (a) hash table (b) algorithm (c) associative array (d) tree 1.2.2 1. Decomposition of a problem involves which of the following? (d) (a) Simplifying the problem by eliminating low-priority requirements (b) Determining a programming language for implementing a solution to the problem (c) Reverse-engineering an algorithm that solves a different problem (d) Identifying entities and relationships that will aid in solving the problem 1.3.1 1. Which of the following expressions evaluates to true in C++ if and only if the index variable i is in bounds for an array of size 10? (c) (a) 0 < 10 (b) 0 <= i && i <= 10 (c) 0 <= i && i < 10 (d) 0 <= i < 10 2. Which of the following lists of C++ types are ordered increasingly by size, as computed by sizeof()? (d) (a) short, char, int, long (b) long, int, short, char (c) long, int, char, short (d) char, short, int, long 3. Each of the following is a basic C++ type except (c) (a) bool (b) char (c) byte (d) unsigned int 1.3.2 1. The purpose of the assignment operator is to (b) (a) be used internally in an object's copy constructor (b) provide for proper assignment between objects (c) initialize data members when an instance is first created (d) prevent memory leaks 2. If a user-defined class Complex has overloaded operator+=, then one would expect this operator to have which of the following declarations? (c) (a) void operator+=( const Complex& rhs ); (b) void operator+=( float real, float imag ); (c) Complex& operator+=( const Complex& rhs ); (d) Complex& operator+=( const Complex rhs ); 3. Assume that Thing is a user-defined class, and consider the following code fragment, where B is an instance of Thing. Thing A = B; Which of the following is a class member that is used in this code fragment? (c) (a) The assignment operator (b) The default constructor (c) The copy constructor (d) The destructor 4. Assume that Thing is a user-defined class, and consider the following function. Thing f(Thing& A) { Thing B; B.x = A.x; return B; } Where in this code will a copy constructor be used? (b) (a) In copying the data from A to B (b) In the return operation (c) In passing the parameter (d) In the creation of the local variable B 5. Which of the following is true about a class without a (user-defined) constructor? (a) (a) It may have a destructor, but might not. (b) It cannot have a destructor. (c) It must have a destructor. (d) It cannot have an assignment operator. 6. In a C++ class, access to data members and function members are typically (b) (a) both private (b) private and public, respectively (c) public and private, respectively (d) both public 7. To which of the following is object-based programming ideally suited? (b) (a) Implementing simple monolithic programs (b) Encapsulation (c) Attaining the highest possible efficiency (d) Providing elegant mechanisms for code reuse 1.3.3 1.Regarding C++ standard I/O, the _____ operator writes to a stream and the _____ operator reads from a stream. (d) (a) >, < (b) >>, << (c) <, > (d) <<, >> 2. Suppose inf is an available ifstream and c is an available character. Consider the following code fragment. do c = inf.get(); while (!inf.eof() && isspace(c)); Which of the following accurately describes the effect of executing this fragment? (c) (a) Characters are read until the end of the file is reached. (b) Characters are read until a white space is read. (c) Characters are read until a non-white-space character is read or until the end of the file is reached. (d) The number of non-white-space characters is counted. 3. In C++, the standard input stream is accessible using the object _____, and the standard output stream is accessible using the object _____. (a) (a) cin, cout (b) stdin, stdout (c) input, output (d) keyboard, screen 1.3.4 1. One reason for using an assert statement such as assert (0 <= i && i < 10); within code is to (d) (a) instruct the compiler to set i to any value in the indicated range (b) send a warning message but continue execution when the condition is violated (c) provide a comment for the user (d) terminate execution and send an error message whenever the condition is violated 2. In C++, preprocessor directives begin with which of the following symbols? (a) (a) # (b) % (c) - (d) ? 3. Which of the following is the C++ preprocessor directive for file inclusion? (c) (a) #ifndef (b) #pragma (c) #include (d) #define 4. One reason for using an assert statement such as assert( 0 <= i && i < 10 ); within code is to (a) (a) terminate execution and send an error message whenever the condition is violated (b) provide a comment for the user (c) instruct the compiler to set i to any value in the indicated range (d) send a warning message but continue execution when the condition is violated 5. In C++, the preprocessor is (d) (a) a virtual CPU that can be used to simulate machine-code execution (b) a debugging tool common to most visual programming environments (c) a set of APIs provided by several compiler vendors (d) a tool that manipulates source files before compilation 6. In C++, a preprocessor directive is a (c) (a) comment ignored by the preprocessor (b) comment that prevents the linking of object files into executable programs (c) single-line command introduced into a C++ source file (d) command-line argument supplied to the linker 1.1-1.3 1. Which of the following is not a predefined stream object in C++? (a) (a) cfile (b) cin (c) cout (d) cerr Feedback: See Appendix A.4, page A-9, in the course notes. 2. To read data from a file into a C++ program using class ifstream, it is necessary to include the _____ library header file. (a) (a) fstream (b) string (c) ctype (d) iomanip Feedback: See Appendix A.4, page A-13, in the course notes. 1.4.1 1. What is the effect of the following C++ code fragment? (d) int A[100]; for( int *p = A; p < A + 100; ++p ) { *p = 0; } (a) It sets 100 pointers in A to 0. (b) It produces an out-of-bounds error. (c) It zeroes out A[0]-many elements of array A. (d) It zeroes out the 100 elements of array A. 2. Consider the following C++ program segment: int j = 5; int *a = &j; *a = *a + 4; After execution of this program segment, what will be the value of the variable j? (b) (a) 0 (b) 9 (c) 5 (d) 4 3. Consider the following C++ program segment: int j[10]; for (int i = 0; i < 10; i++) { j[i] = i; } int *a = j; a++; After execution of this program segment, what will be the value of j[0]? (a) 11 (b) 2 (c) 0 (d) 1 1.4.2 1. Which of the following statements creates p as an alternative name for the variable i? (d) (a) int *p = &i; (b) int &p = *i; (c) int *p = i; (d) int &p = i; 2. Assume that Thing is a user-defined type. Which of the following print functions for Thing is the safest and most efficient? (a) void print( Thing* x ); (b) void print( Thing x ); (c) void print( Thing& x ); (d) void print( const Thing& x ); 1.4.3 4. Which of the following statements properly allocates an array of 100 integers? (a) (a) int *A = new int[100]; (b) int A = new int[100]; (c) int *A = new (int) 100; (d) int &A = new int[100]; 5. How does C++ handle memory allocation? (b) (a) C++ always uses a garbage collector. (b) Allocation and deallocation is the responsibility of the programmer. (c) Allocation and deallocation is completely shielded from the programmer. (d) C++ has a garbage collector that can be used or turned off. 6. Suppose a user-defined class Thing has a simple constructor that does not require any calls to new. Which of the following is true about the destructor? (c) (a) It will not contain calls to delete. (b) The appropriate destructor will be provided automatically by the compiler. (c) It might contain calls to delete, but might not. (d) In this case, no destructor is required for class Thing. Correct answer is 1.5.1 1. Which of the following is true of inheritance? (c) (a) It is an important idea in Object Oriented Programming, but currently it is not implemented in C++. (b) It causes one type to behave like several types. (c) It provides for the elegant construction of a new class from an existing class. (d) It protects data members from illegal access. 2. Inheritance is an important feature of C++ because (c) (a) it makes type-checking much easier (b) it can often replace templates (c) it is a powerful code reuse mechanism (d) it greatly increases efficiency 1.5.2 1. Which of the following is necessary in order to obtain polymorphic behavior in C++? (a) (a) Pointers or references are used with virtual functions. (b) Templates are avoided. (c) Only instances of the base class are used. (d) Only instances of the derived class are used. 4. Polymorphism is a mechanism that is used in order to (d) (a) protect data members from illegal access (b) determine methods of a class based on its data members (c) build new classes on top of existing ones (d) determine the type of an object dynamically at run time 5. Under what circumstances will a member function in C++ display polymorphic behavior? (c) (a) Always (b) If and only if the class is not a template class (c) If and only if the function is explicitly declared to be virtual (d) If and only if the class uses private inheritance 1.5.3 1. If templates were removed from C++, which of the following would be true? (b) Some algorithms could no longer be implemented. Any particular algorithm could still be implemented, but often less elegantly. Any particular algorithm could still be implemented, but the efficiency would often be catastrophically worse. (a) II only (b) None (c) II and III (d) I only 2. Which of the following is (are) true about template classes in C++? (d) Methods cannot be overloaded in templated class definitions. Private data of a templated class cannot be declared to have the type of the templated parameter. (a) I and II (b) II only (c) I only (d) None 3. Consider the following outline of a template array class. (b) template class Array { ... } Which of the following is true about using this outline to implement a general container class? (a) It is a poor choice since the type matching will slow down access at runtime. (b) It is a reasonable way to implement such a class. (c) It is a poor choice since templates slow down compilation. (d) It is impossible since the algorithm cannot know how to copy an instance of type T. 1.5.4 1. In C++ exception handling, a try block must be followed by _____ catch block(s). (b) (a) exactly one (b) one or more (c) exactly two (d) three or fewer 2. In the C++ standard exception hierarchy, which of the following classes is not derived from class runtime_error? (c) (a) overflow_error (b) range_error (c) domain_error (d) underflow_error 3. In C++ exception handling, intermediate exception handlers typically are used to: (a) (a) ensure allocated resources are properly released (b) catch exceptions polymorphically (c) override the guarantees of exception specifications (d) throw user-defined exception classes 2.1.1 1. The STL is heavily based on (b) (a) polymorphism (b) templates (c) object oriented programming (d) inheritance 2. Which of the following data structures is not a container implemented in the C++ Standard Template Library? (b) (a) Stack (b) Hash table (c) List (d) Vector 3. Which of the following statements regarding the design of the Standard Template Library (STL) in C++ is (are) true? (d) Each STL algorithm is usable with one specific container. The STL does not use templates and instead relies on polymorphism. (a) I only (b) I and II (c) II only (d) None 4. The main abstractions of the Standard Template Library include which of the following? (d) Iterators Exception handlers Algorithms (a) III only (b) I only (c) I and II only (d) I and III only 5. In the STL, common algorithms are instantiated for multiple types of container classes by using _____ to provide a uniform interface between the algorithms and containers. (b) (a) pointers (b) iterators (c) arrays (d) virtual functions 2.1.2 1. If A is an STL vector, then the effect of executing the statement A[i] = x; is to (b) (a) check array bounds, enlarge the vector if necessary, and then write x to position i (b) write x to position i of the vector, without bounds checking (c) check array bounds, and write x to position i if and only if i is in the proper range (d) create an iterator x pointing to position i in the array 2. Consider the following declaration that makes use of a user-defined class Thing. vector A(10); In order that it compile, the class Thing must have which of the following? (c) (a) a copy constructor (b) an assignment operator (c) a default constructor (d) a destructor 3. The capacity of an STL vector is defined to be the (d) (a) difference between the current number of elements and the maximum number of elements (b) number of elements currently stored in the vector (c) maximum number of elements the vector could possibly have on the given machine (d) maximum number of elements that can be stored in the vector without resizing 4. The size of an STL vector is defined to be the (a) (a) number of elements currently stored in the vector (b) total of the sizes of the data members in the vector class (c) maximum number of elements that can be stored in the vector without resizing (d) number of bytes the vector occupies in memory 5. Consider the following program segment. (d) vector A(10); A.resize(0); A.push_back(5000); At the end of an execution of this fragment, the size of vector A is (a) 0 (b) 10 (c) 5000 (d) 1 6. If A is an STL vector, then the effect of executing the statement A.push_back( x ); is to (a) (a) check whether the capacity of A is larger than the size of A, enlarges A if necessary, and append x to A (b) append x to A if there is room, and otherwise overwrites the currently last element of A (c) append x to A if and only if the size of A is less than capacity of A (d) append x to A, without checking the size and capacity of A 7. Consider the execution of the following. vector A(10,20); Which of the following accurately describes what is created? (a) (a) An array of 10 ints, each initialized to 20 (b) An array of 10 arrays of ints, each of size 20 (c) An array of ints, indexed from 10 to 20 (d) An array of 20 arrays of ints, each of size 10 2.1.3 1. Execution of which of the following statements sets an STL iterator it so that it points to the first element of a container A? (b) (a) A.reset( it ); (b) it = A.begin(); (c) A.begin( it ); (d) begin( A, it ); 2. For an STL iterator it, execution of the statement it--; does which of the following? (d) (a) Pre-decrements the item to which the iterator points. (b) Decreases by 1 the size of the container pointed to by it. (c) Post-decrements the item to which the iterator points. (d) Steps the iterator backwards to the previous item. 3. For an STL iterator it, execution of the statement ++it; does which of the following? (c) (a) Increase by 1 the size of the container pointed to by it. (b) Post-increments the item to which the iterator points. (c) Advances the iterator to the next item. (d) Pre-increments the item to which the iterator points. 4. Access to ranges of elements in an STL container is typically handled by (c) (a) suitable access member functions (b) pointers (c) iterators (d) references 2.1 1. Consider the following C++ program segment, assuming that string is a class. string str1("Hello, World"); str1[5] = 'Z'; The overloaded operator[] function invoked in the above program segment should have which of the following return types? (c) (a) const char & (b) char (c) char & (d) char * Feedback: See Chapter 2, pages 79–81, in the course textbook. 2. Which of the following statements is (are) true regarding C-style strings? (b) They are terminated by the null character. Storing a five-character string requires at least seven characters. (a) I and II (b) I only (c) II only (d) None Feedback: See section 2.1, subsection "C-style Strings," in the course notes. 3. A C-style string is stored as an array of characters that ends with _____ character. (d) (a) a '\n' (b) a '0' (c) any white-space (d) a '\0' Feedback: See Chapter 2, page 74, in the course textbook. 4. Which of the following statements is (are) true regarding strings in C++? Strings in C++ are supported by the standard class string. A constructor for the class string can accept a C-style string as an argument. (d) (a) I only (b) None (c) II only (d) I and II 5. Consider the following C++ program fragment, which is a partial declaration of the class string. class string { public: string(const char* cstring = ""); bool operator== (const string & rhs); ... }; Given this class and two string objects called s1 and s2, which of the following is not a legal statement? (a) (a) bool ans = ("hello" == s1); (b) bool ans = (s2 == "hello"); (c) string s3("Hello, World"); (d) bool ans = (s1 == s2); Feedback: See Chapter 2, pages 76–77, in the course textbook. 2.2.2 1. Consider the following C++ program fragment. vector A(10); A.push_back( 5000 ); At the end of an execution of this fragment, the size of vector A is (c) (a) 5000 (b) 10 (c) 11 (d) dependent on machine and compiler 2. One thing that the STL vector and the STL list have in common is that both are (c) (a) based on arrays of elements (b) random access containers (c) sequential containers (d) inherited from the superclass Container 2.2.3 1. A typical implementation of a deque in the C++ STL minimizes the need to copy elements upon the frontal insertion of new items by (c) (a) inserting the element at the next available position in the deque and maintaining a table of element positions (b) inserting the element at the end of the deque and maintaining a table of element positions (c) reserving memory at the front of the deque's stored elements (d) using a background thread to reallocate memory when necessary 2. Consider the following program fragment that calls the method count_if in the C++ Standard Template Library. (b) deque numbers; ... count_if(numbers.begin(), numbers.end(), is_odd); Which of the following declarations for the method is_odd is correct for the call to count_if? (a) int is_odd(int begin, int end); (b) bool is_odd(int i); (c) int is_odd(bool i); (d) bool is_odd(int begin, int end); 3. In the C++ Standard Template Library, vectors and deques differ in their interfaces for handling which of the following operations? (b) Insertion of an element at the front of the container Insertion of
本文档为【SSD5单选题答案】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_062796
暂无简介~
格式:doc
大小:258KB
软件:Word
页数:32
分类:计算机考试
上传时间:2011-10-27
浏览量:12