Jul 17, 2011

网上收集的C++笔试题目(9)

【Q1 】Which of the following options correctly describe the relationship between a derived class and its base class in C++?
    A.    Isamemberof relationship

    B.    Is­a relationship

    C.    Has­a­kind­of relationship

    D.    Has­a relationship

    E.    Becomes­a relationship

【Q2】 Which of the following statements correctly describe C++ references?

    A.    A refrence may refer to a different object by assignment.

    B.    A reference must be initialized when it is declared.

    C.    The operator ­> must be used to access the referenced object.

    D.    A reference creates an alias to another object.

    E.    A reference remains valid irrespective of the scope or lifetime of the referenced object.

【Q3】Which of the follow describe appropriate scenarios for the using the C++ volatile type­modifer?

    A.    When a variable cannot be changed

    B.    When a variable can be changed asynchronously by hardware

    C.    When a variable can only be changed by the program normally

    D.    When a variable can be changed asynchronously by another thread

    E.    When a variable can be changed only once

【Q4】 A C++ class named SomeClass has a public static int member named data. An object of SomeClass named objSome is declared. Which of the following statements
  can access to data?


    A. SomeClass::objSome.data

    B.  objSome.data

    C. SomeClass::data

    D. objSome::data

    E.  SomeClass<static int>.data

【Q5】Which of the following C++ code snippets can a developer use to open a file SomeFile.txt with an instance outfile of class ofstream?
    A. std::ofstream outfile;
    outfile.read("SomeFile.txt");
    B.  std::ofstream outfile("SomeFile.txt");

    C. std::ofstream outfile;
    outfile.open("SomeFile.txt");
    D. std::ofstream outfile;
    outfile.open("SomeFile.txt", std::ios::out);
    E.  std::ofstream outfile;
    outfile.read("SomeFile.txt", std::ios::out);

【Q6】Which of the following operators have a unary form in C++?

    A. !

    B.  %

    C. ++

    D. -

    E.  []

【Q7】  Which of the following identify a valid function prototype for a C++ function named Display, which receives a STL vector object as an argument?
    A. template <class T> void Display(std::vector& obj);

    B. template <class T> void Display<T>(std::vector<T>& obj);

    C. template <class T> void Display(std::vector<T>& obj);

    D. template <class T> void Display<T>(std::vector& obj);

    E. template <class T, class Q> void Display<T>(std::vector<Q>& obj);

【Q8】 Which of the following statements describe the result when standard new CANNOT allocate the requested storage in C++?  (Note: older compilers may not implement
 ior).


    A.    It throws an insufficient_memory exception.

    B.    It throws a bad_alloc exception.

    C.    It returns silently with no effect on the expression.

    D.    It returns null.

    E.    It logs an error message to the mem_err.log file.

【Q9】Which of the following are possible results of building the C++ code below?
 Class
SomeClass
 {
     protected:
         int data;
         friend class AnotherClass;
 };

 void SomeFunc(SomeClass sc)
 {
     sc.data = 5;
 }

 class AnotherClass
 {
     public:
         void Another(SomeClass sc)
         {
             sc.data = 25;
         }
         friend void SomeFunc(SomeClass sc);
 };

 int main(void)
 {
     SomeClass sc;
     SomeFunc(sc);
     cout << sc.data;
 }

    A.    Compiling generates an error because main() is not allowed to access the protected member data of SomeClass.

    B.    The build will be successful, and the program will display an output of "5" when it is executed.

    C.    Compiling generates an error because Another() of AnotherClass is not allowed to access the protected member data of SomeClass.

    D.    Compiling generates an error because SomeFunc() is not allowed to access the protected member data of SomeClass.

    E.    Compiling generates an error because AnotherClass is not allowed to declare SomeFunc() as a friend as it is already a friend of SomeClass.

【Q10】Which of the following are valid Container types (i.e. Container concepts) in the Standard Template Library?
    A.    ?

    B.    Associative

    C.    Random

    D.    Sequence

    E.    Linked
【Q11】Which of the following are valid outputs of executing the code below in C++?

 cout << setw(11) << 'A';

    A.    10 blank spaces followed by A

    B.    A with 5 blank spaces on either side

    C.    11A

    D.    11 As

    E.    A followed by 11 blank spaces



No comments:

Post a Comment