0% found this document useful (0 votes)
57 views2 pages

C++ Test3 2009

The document provides sample questions and answers for an object-oriented programming exam in C++. It includes two sections - Section A with multiple choice questions worth 4 marks each on topics like data encapsulation, virtual functions, abstract classes, polymorphism, and memory management. Section B includes longer form questions worth 5 marks each, including defining missing member functions for a Complex class and providing a complete class specification for a Length class with meters and centimeters private data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views2 pages

C++ Test3 2009

The document provides sample questions and answers for an object-oriented programming exam in C++. It includes two sections - Section A with multiple choice questions worth 4 marks each on topics like data encapsulation, virtual functions, abstract classes, polymorphism, and memory management. Section B includes longer form questions worth 5 marks each, including defining missing member functions for a Complex class and providing a complete class specification for a Length class with meters and centimeters private data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

1

M.Sc Marine Geophysics II Semester 2009 Object-Oriented Programming in C++ Test 3


19 - 3 - 2009 Time: 2 hrs. SECTION - A Answer ANY 10 questions. Each question carries 4 marks. 1. What is meant by data encapsulation / data hiding? What is its significance? 2. What is a Virtual function? What is its use? 3. What is meant by pure virtual function? Give one example of a pure virtual function. 4. What is the necessity for an abstract class? How to recognize an abstract class? 5. What are overloaded functions and overloaded operators? Give two examples in each. 6. What is polymorphism in object-oriented programming? Give an example of it. 7. What are late binding and early binding? How is it implemented in C++? 8. What is the keyword new in C++? Show an example of dynamically creating an array of size given by the user. 9. What is meant by heap / free storage in C++? What is its use? How to avoid the risk of heap getting exhausted in a program? 10. What is the necessity for a virtual class? Show one example for it. 11. What is default argument in a function? What are the conditions for giving default arguments? 12. What is meant by inheritance in object-oriented programming? Give two examples. 13. What are constructors and destructors in C++? What are the uses for them? SECTION B Answer ALL questions. Each question carries 5 marks. 14. The specifier / declaration of a class called complx, which uses complex numbers as user defined data, is shown below. Define all those member functions of the class which are not defined. See the comments to find what is function does.
// This shows a complex class and how it is used in a program class complx { private: double real; double imag;

Max.Marks:50

// to keep the real part a COMPLEX // NUMBER // to keep the imaginary part of a COMPLEX // NUMBER

public: complx() {real = imag = 0.0;} complx(double r, double img = 0) {real = r; imag = img;} void setval(double r, double i) {real = r; imag = i;} void getval(); void showval(); double r2pabs(); double r2pang(); complx operator + (complx); complx operator - (complx); complx operator * (complx); complx operator / (complx); }; 15.

// empty constructor // constructor with two // arguments

// allows user to set the values // // // // // // // // // // // // gets the values from user displays the complex number in the usual format of displaying complex numbers returns the absolute value returns the angle in degrees adding two complex nos. and returns the result as an object of class complx. subtract one from another multiply two complex nos. divide one from another

// END OF CLASS SPECIFICATION

Give the complete class specification for showing the length as a user defined data in meters and centimeters. Call this class length. Let there be two private data members like int mt and float cm and appropriate public member functions so that one can use the length as any standard data. Show a simple test program to use the objects of this class.

You might also like