Make your own free website on Tripod.com
 C++ Programmers quiz
 Please complete the following quiz in under thirty minutes.  All
 questions count equally.
 
 
 Definitions
 
 1. What is a class?
 
 
 
 2. What is an object?
 
 
 
 3. What is encapsulation?
 
 
 
 4. What is composition?
 
 
 5. What is inheritance?
 
 
 
 6. List three advantages of OO programming vs. structured programming?
 
 
 
 
 Constructors & Destructors
 
 7. What is the purpose of a class constructor?
 
 A. Assign values to static data members B. Define public
 methods
 C. Define virtual methods D. Free unused memory
 E. None of the above
 
 
 8. What is the output of the following program?
 
 class A
 {
 public:
 A() {};
 ~A() { cout << "Destroying A "; }
 };
 
 class B : public A
 {
 public:
 B() {};
 ~B() {  cout << "Destroying B "; }
 };
 
 
 void main()
 {
 A objectA;
 B* objectB = new B();
 
 delete objectB;
 }
 
 A. Destroying B B. Destroying B Destroying A Destroying A
 C. Destroying A D. Destroying A Destroying B Destroying A
 E. Destroying A Destroying A
 
 
 
 9. In the program above, which constructors are invoked and in what
 order?
 
 A. A(), B() B. A(), B(), B()
 C. A(), A(), B() D. B()
 E. None of the above
 
 
 
 10. When are reference data members initialized?
 
 A. During the object construction B. During the object
 destruction
 C. During object assignment D. Before any objects are
 created
 E. After all objects are created
 
 
 
 11. When are static data members initialized?
 
 A. During object construction B. During object
 destruction
 C. During assignment D. Before any objects are created
 E. After all objects are created
 
 
 
 
 
 Inheritance
 
 12. What is the syntax for protected inheritance?
 
 A. class A : B {}; B. protected class A : B {};
 C. class A : protected B {}; D. class A : B protected
 {};
 E. None of the above
 
 
 13. An abstract class contains ...?
 
 A. No methods B. Only public methods
 C. Only private methods D. One or more pure virtual
 methods
 E. None of the above
 
 
 
 14. What is the purpose of a pure virtual member?
 
 A. Provide a consistent class interface B. Force derived
 classes to use base methods
 C. Prevent inheritance by another class D. Allow
 assignment of static data members.
 E. None of the above
 
 
 
 15. It's possible for a derived class to access the private members of
 its base class
 
 True False
 
 
 
 16. Complete the display method in class B so that it also calls the
 base class display method.
 
 class A
 {
 virtual void display() { cout << "class A"; }
 };
 
 class B : public A
 {
 void display();
 };
 
 void B::display()
 {
 cout << "class B";
 
 (...insert code here...) // call the base class
 display() method
 }
 
 
 
 References and const
 
 Class A
 {
 public:
 
 int GetDay () const    { return _data; }
 const int& GetMonth() { return _data; }
 void SetDay(const int& data) { _data = data; }
 void Swap(int &a, int b) { b = a; a = 2;  }
 
 private:
 int _data;
 };
 
 
 17. What is the purpose of the const keyword in GetDay()?
 
 A. It prevents this method from modifying data members of class
 A.
 B. It allows this method to modify passed in parameters.
 C. It prevents this method from modifying passed in parameters.
 D. It allows private derivations of class A from using this
 method.
 E. It prevents users of the class from modifying the return
 value.
 
 
 
 18. What is the purpose of the const keyword in GetMonth ()?
 
 A. It prevents this method from modifying data members of class
 A.
 B. It allows this method to modify passed in parameters.
 C. It prevents this method from modifying passed in parameters.
 D. It allows private derivations of class A from using this
 method.
 E. It prevents users of the class from modifying the return
 value.
 
 
 
 19. What is the purpose of the const keyword in SetDay ()?
 
 A. It prevents this method from modifying data members of class
A.
 B. It allows this method to modify passed in parameters.
 C. It prevents this method from modifying passed in parameters.
 D. It allows private derivations of class A from using this
 method.
 E. It prevents users of the class from modifying the return
 value.
 
 
 
 20. What does the & mean in the code above?
 
 A. It prevents this method from modifying data members of class
 A.
 B. It allows this method to modify passed in parameters.
 C. It prevents this method from modifying passed in parameters.
 D. It allows private derivations of class A from using this
 method.
 E. It prevents users of the class from modifying the return
 value.
 
 
 
 21. What is the output of the following program?
 
 void main()
 {
 A objectA;
 int x = 10, y = 20;
 
 A.Swap (x, y);
 cout << x << y;
 }
 
 
 STL (Standard Template Library) Usage
 
 22. How would a list container of integers be defined?
 
 A. list(int) B. list<int>
 C. int<list> D. <int>list
 E. None of the above
 
 
 23. Which of these is a valid way to insert an item into myMap?
 
 typedef map <int, char, less <int> > myMap;
 
 A. myMap.insert(1, 'a');
 B. myMap[] = 'a';
 C. myMap.insert(myMap::value_type(1, 'a'));
 D. myMap = 1;
 E. myMap = {1, 'a'};
 
 
 
 24. How do you determine how many items are in a list container?
 
 A. int count = list[END];
 B. int count = list<int>.count();
 C. int count = list.size();
 D. int count = !list.empty();
 E. None of the above
 
 
 
 25. What is the difference between a map and a multimap?
 
 A. A map contains less than ten elements; a multimap contains ten
 or more elements
 B. A map is sorted; a multimap is not sorted
 C. A map does not allow duplicates entries; a multimap allows
 duplicate entries
 D. A map allows duplicate entries; a multimap does not allow
 duplicate entries
 E. None of the above
 
 
 
 26. How can any STL container be emptied of all elements?
 
 A. MyContainer.delete();
 B. MyContainer.erase();
 C. MyContainer.erase(myContainer.begin(), myContainer.end());
 D. MyContainer.erase(ALL);
 E. None of the above