

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Programming 2, do this to understand the concept of OOP and master it
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!
CS 274—Object Oriented Programming with C++ Final Exam December 16 th
(2) 1. TRUE or FALSE: Namespaces allow you to have multiple memory locations with the same variable name.
(6) 2. Explain the error in the following groups of function declarations or write “No Error”
(a) void f(int x, string y); int f(int x, string y);
(b) float g(int x, float y = 2.31, string z);
(c) void h(int x); void h();
(2) 3. Explain the difference between the keywords struct and class.
(6) 4. Consider the following class definition:
class TwoPoint{ private: int x, y; public: void set(int x, int y); };
Provide the definition of the method set. Write the method outside the class and do not change the prototype of the method.
(4) 5. Give two reasons to pass an object by reference.
(3) 6. Refer back to the TwoPoint class in #4 above. Write a default constructor for the class that does not have an empty parameter list.
(2) 7. Give one reason why a class would need a destructor.
(2) 8. Why can’t the constant pointer this be used inside a static method?
(4) 9. Assume the necessary operators are overloaded: (a) Write the following in operator form: b.operator=(a.operator+(c)); (b) Write the following in functional form: z = x + w*y;
(4) 10. Consider a class Complex in which addition has been overloaded. Let the variable z represent an object of type Complex. What two things need to be true in order for the expression 2 + z to be legal?
(3) 11. Why can’t << be overloaded as a method and still retain its standard functionality (ie, cout << x , where x is an object type)?
(2) 12. TRUE or FALSE: The assignment operator must be overloaded as a top-level function.
(4) 13. Consider the following inheritance hierarchy: class A{ protected: int x, y; public: int z; }
class B: public A{ private: int a, b, c; } (a) How many data members does B have? (b) How many of B’s data members are visible in B?
class A{ public: int x; }
class B: public A{ private: int x; public: void set(int a, int b); }
Write the definition for the method set that assigns the inputs a and b to B’s data members.
(2) 17. TRUE or FALSE: If a base class has a default constructor, then none of the constructors in the derived class need to explicitly call a base class constructor.
(2) 18. TRUE or FALSE: If a base class has a parameterized constructor but no default constructor, then derived class objects cannot be instanced unless the derived class constructor explicitly calls one of the base class constructors.
(2) 19. TRUE or FALSE: If a base class has no constructors whatsoever, then a derived class object cannot be instanced.
(3) 20. With which type of binding is the vtable used?