C Plus Plus Final Review Quiz

28 Questions | Total Attempts: 64

SettingsSettingsSettings
Please wait...
C Plus Plus Quizzes & Trivia

Questions and Answers
  • 1. 
    Suppose you are realizing the ADT Queue as a C++ class template as follows:template < typename T >class TQueue{  public:    ...    void     Push    (const T& t);    T        Pop     ();    T&       Front   ();    ...  private:    class Link    {      Link (const T& t) : element_(t), nextLink_(0){}      T   element_;      Link * nextLink_;      friend class TQueue;    };     Link * firstLink_;    Link * lastLink_;    ...};Which of the following is a correct implementation of Push(t)? 
    • A. 

      { Link * newLink = new Link (t); if (firstLink_ == 0) firstLink_ = lastLink_ = newLink; else { firstLink_ -> nextLink_ = newLink; firstLink_ = newLink; } }

    • B. 

      { Link * newLink = new Link (t); if (firstLink_ == 0) firstLink_ = lastLink_ = newLink; else { lastLink_ -> nextLink_ = newLink; lastLink_ = lastLink_ -> nextLink_; } }

    • C. 

      { Link * newLink = new Link (t); if (lastLink_ == 0) lastLink_ = firstLink_ = newLink; else { lastLink_ -> nextLink_ = newLink; lastLink_ = newLink; } }

    • D. 

      { Link * newLink = new Link (t); if (lastLink_ == 0) lastLink_ = firstLink_ = newLink; else { lastLink_ = newLink; lastLink_ -> nextLink_ = newLink; } }

  • 2. 
    An abstract data type [ADT] requires three things. Which of the following is not one of these?
    • A. 

      A set of elements of type T

    • B. 

      Memory allocated for storage

    • C. 

      Operations on the set

    • D. 

      Rules of behavior constraining the operations

  • 3. 
    Consider the classes and client program defined below: class A{  public:    void F() { std::cout << "A::F()\n"; }    void G() { std::cout << "A::G()\n"; }    virtual void H() { std::cout << "A::H()\n"; }    virtual ~A(){};}; class B : public A{  public:    void G() { std::cout << "B::G()\n"; }    void H() { std::cout << "B::H()\n"; }}; #include<iostream> int main(){  A a;  B b;  A * p = new B;  a.F();  a.G();  a.H();  b.F();  b.G();  b.H();  p->F();  p->G();  p->H();} What is the screen output of this program?
    • A. 

      A::F() A::G() A::H() A::F() B::G() B::H() A::F() B::G() B::H()

    • B. 

      A::F() A::G() A::H() A::F() B::G() B::H() A::F() A::G() A::H()

    • C. 

      A::F() A::G() A::H() B::F() B::G() B::H() A::F() A::G() B::H()

    • D. 

      A::F() A::G() A::H() A::F() B::G() B::H() A::F() A::G() B::H()

  • 4. 
    Which statements are true about the Stack ADT? 
    • A. 

      It models a first in first out system.

    • B. 

      It models a last in first out system.

    • C. 

      It is often used by CPUs to evaluate expressions.

    • D. 

      It is often used to manage communication between computers.

    • E. 

      It is used by the C++ runtime system to manage function calls.

    • F. 

      It can be efficiently implemented using an array.

    • G. 

      It can be efficiently implemented using dynamic links.

    • H. 

      It is usually realized as a container class template.

  • 5. 
    Suppose you have this code snippet: unsigned int n = 3;n = (n << 2);std::cout << n; What value is output to screen?
  • 6. 
    Every object of the same class
    • A. 

      Gets a copy of each static member variable

    • B. 

      Can call each public member function using the dot notation

    • C. 

      Gets a reference to each non-static member function

    • D. 

      Gets a copy of each static member function

    • E. 

      Can access each public non-static class variable using the dot notation

    • F. 

      Can access public static class variables using the dot notation

    • G. 

      Gets a copy of each non-static member function

    • H. 

      Gets a copy of each non-static member variable

  • 7. 
    Operator delete
    • A. 

      Can delete an entire array of objects declared using new

    • B. 

      Must be told which destructor to call when destroying an object

    • C. 

      Should be called explicitly for each object that has been created with operator new

    • D. 

      Calls the class destructor

  • 8. 
    Suppose you are realizing the ADT Stack as a class template as follows:   template < typename T , size_t N >  class TStack  {    public:      ...      void     Push     (const T& t);      T        Pop      ();      T&       Top      ();      ...    private:      const size_t capacity_;      T            data_[N];      size_t       size_;      ...  }; Which of the following is a correct implementation for Pop?
    • A. 

      { if (size_ == 0) exit (EXIT_FAILURE); --size_; return data_[size_]; }

    • B. 

      { if (size_ == 0) exit (EXIT_FAILURE); T rval = data_[size_ - 1]; --size_; return rval; }

    • C. 

      { if (size_ == 0) exit (EXIT_FAILURE); T rval = data_[size_]; --size_; return rval; }

    • D. 

      { if (size_ == 0) exit (EXIT_FAILURE); --size_; return data_[size_ - 1]; }

  • 9. 
    Which of the following is a correct initialization of class variables by a constructor for class Date?
    • A. 

      Date::Date (int d, int m, int y) : day_(d), month_(m), year_(y) { //optional code here }

    • B. 

      Date::Date (int d, int m, int y) : d(day_), m(month_), y(year_) { //optional code here }

    • C. 

      Date::Date (int d, int m, int y) :: day_(d), month_(m), year_(y) { //optional code here }

    • D. 

      Date::Date (int d, int m, int y) :: d(day_), m(month_), y(year_) { //optional code here }

  • 10. 
    Consider the following classes and client program. What is the screen output? class Rectangle{  private:    float width_, height_;  public:    Rectangle(float width = 1, float height = 1) : width_(width), height_(height){}    virtual ~Rectangle() {}    float Area() const { return width_ * height_; }    virtual const char* Name() const { return "rectangle"; }}; class Square : public Rectangle{  public:    Square(float side = 1) : Rectangle(side, side) {}    const char* Name() const { return "square"; }}; int main(){  Rectangle* p1 = new Rectangle(2,4);  Rectangle* p2 = new Square (2);  std::cout << "p1 -> Name() = " << p1 -> Name() << '\n';  std::cout << "p1 -> Area() = " << p1 -> Area() << '\n';  std::cout << "p2 -> Name() = " << p2 -> Name() << '\n';  std::cout << "p2 -> Area() = " << p2 -> Area() << '\n';}
    • A. 

      P1 -> Name() = rectangle p1 -> Area() = 8 p2 -> Name() = square p2 -> Area() = 8

    • B. 

      P1 -> Name() = rectangle p1 -> Area() = 4 p2 -> Name() = square p2 -> Area() = 4

    • C. 

      P1 -> Name() = rectangle p1 -> Area() = 8 p2 -> Name() = square p2 -> Area() = 4

    • D. 

      p1 -> Name() = square p1 -> Area() = 4 p2 -> Name() = square p2 -> Area() = 4

  • 11. 
    The concept of "deep copy" relates to which of the following?
    • A. 

      Static member functions

    • B. 

      Initialization lists

    • C. 

      Global constants

    • D. 

      Making copies of objects

    • E. 

      Correct management of pointers

    • F. 

      Instantiating pointer member variables

    • G. 

      Static member variables

    • H. 

      Object ownership of resources

  • 12. 
    Given the classes: class BClass{  public:    void SetX(int);    void Print() const;  private:    int x_;}; class DClass : public BClass{  public:    void SetXY(int,int);    void Print() const;  private:    int y_;}; Which statement describes the class variables for DClass?
    • A. 

      DClass objects have two private variables x_ and y_ .

    • B. 

      DClass objects have one private variable y_ .

    • C. 

      DClass objects have one public variables x_ and one private variable y_ .

    • D. 

      DClass objects have one private variable x_ .

  • 13. 
    Runtime polymorphism in C++ requires the following:
    • A. 

      Virtual functions

    • B. 

      Pointers to base class in a type hierarchy

    • C. 

      Abstract base class

    • D. 

      More than one class constructor

  • 14. 
    Which statements are true about the Queue ADT?
    • A. 

      It models a first in first out system.

    • B. 

      It models a last in first out system.

    • C. 

      It is often used by CPUs to evaluate expressions.

    • D. 

      It is often used to manage communication between computers.

    • E. 

      It is used by the C++ runtime system to manage function calls.

    • F. 

      It can be efficiently implemented using an array.

    • G. 

      It can be efficiently implemented using dynamic links.

    • H. 

      It is usually realized as a container class template.

  • 15. 
    Consider the following program: int F(int& x, int y){  x = x + 1;  y = y + 1;  return x + y;} int main(){  int x,y,z;  x = 1; y = 2; z = 3;  std::cout << "x = " << x << '\n'            << "y = " << y << '\n'            << "z = " << z << '\n';  z = F(x,y);  std::cout << "x = " << x << '\n'            << "y = " << y << '\n'            << "z = " << z << '\n';} What is the screen output?
    • A. 

      X = 1 y = 2 z = 3 x = 1 y = 2 z = 5

    • B. 

      X = 1 y = 2 z = 3 x = 1 y = 2 z = 3

    • C. 

      X = 1 y = 2 z = 3 x = 2 y = 2 z = 3

    • D. 

      X = 1 y = 2 z = 3 x = 2 y = 2 z = 5

  • 16. 
    Given this code fragment: unsigned int n = 255;n = (n >> 4);std::cout << n; What value is output to screen?
  • 17. 
    Which of the following expressions is allowed, given that i and j are pointers to the same type and n is an integer?
    • A. 

      N = i + j

    • B. 

      N = j - i;

    • C. 

      N = i % j;

    • D. 

      J += n;

    • E. 

      *j;

    • F. 

      I = j + n;

    • G. 

      N += j;

    • H. 

      N = i / j;

  • 18. 
    What is the output from the following code fragment?   enum Courses {algebra, history, Pascal, philosophy, analysis};  Courses registered;  registered = philosophy;  std::cout << registered << std::endl; 
    • A. 

      3

    • B. 

      Philosophy

    • C. 

      "philosophy"

    • D. 

      4

  • 19. 
    Given the code: namespace MySpace{  void PrintResult();} Which of the following statements correctly accesses PrintResult? 
    • A. 

      MySpace.PrintResult();

    • B. 

      MySpace:PrintResult();

    • C. 

      MySpace->PrintResult();

    • D. 

      MySpace::PrintResult();

  • 20. 
    The concept Compile Time Polymorphism is sometimes applied to:
    • A. 

      Function templates

    • B. 

      Class templates

    • C. 

      Both of the above

    • D. 

      None of the above

  • 21. 
    Operator new T
    • A. 

      Requires the size of the object as an argument

    • B. 

      Automatically destroys the object when it goes out of scope

    • C. 

      Calls a constructor for the class T

    • D. 

      Returns a pointer to type T

  • 22. 
    To prevent objects from being copied by code implementing class member functions:
    • A. 

      Do not supply an implementation of the copy constructor.

    • B. 

      Make the copy constructor prototype private.

    • C. 

      Make the assignment operator prototype private.

    • D. 

      Do not supply an implementation of the assignment operator.

  • 23. 
    Consider the function template:  template < typename T >void Swap (T& x, T& y){  T z = x;  x = y;  y = z;} and the code fragment: fsu::String stringArray [20];...Swap(stringArray[i], stringArray[j]); What is the effect of the call to Swap?
    • A. 

      No values are changed outside the call to Swap.

    • B. 

      The values i and j are interchanged

    • C. 

      The values stringArray[i] and stringArray[j] are interchanged

    • D. 

      The values x and y are interchanged

  • 24. 
    Static member functions
    • A. 

      Can be called by an object using the dot notation

    • B. 

      Can use the this pointer in their implementation

    • C. 

      May change the state of an object (i.e., change one of its non-static variables)

    • D. 

      Can access other static member functions

    • E. 

      Can access static member variables

    • F. 

      Can access non-static member variables

    • G. 

      Can access non-static member functions

    • H. 

      Can be called when no object exists using the class scope resolution operator

  • 25. 
    Given the class definition: class Box {  public:     Box (float length = 0, float width = 0, float height = 0);     virtual ~Box();    float Volume() const;   private:    float length_, width_, height_;}; Which of the following correctly declares an object variable of type Box?
    • A. 

      B Box (2,4,8);

    • B. 

      Class Box b;

    • C. 

      Box b;

    • D. 

      Box b(2,4,8);

Back to Top Back to top