0% found this document useful (0 votes)
3 views6 pages

Oop Model Answer Key

The document provides answer keys for multiple-choice questions and descriptive questions related to C++ programming concepts. It covers topics such as tokens, destructors, inline functions, friend functions, polymorphism, abstract classes, static members, file modes, and object-oriented programming characteristics. Additionally, it includes explanations of inheritance types, operator overloading, templates, exception handling, and C++ stream class hierarchy.

Uploaded by

saranyabs.cse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Oop Model Answer Key

The document provides answer keys for multiple-choice questions and descriptive questions related to C++ programming concepts. It covers topics such as tokens, destructors, inline functions, friend functions, polymorphism, abstract classes, static members, file modes, and object-oriented programming characteristics. Additionally, it includes explanations of inheritance types, operator overloading, templates, exception handling, and C++ stream class hierarchy.

Uploaded by

saranyabs.cse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PART – A (MCQ) Answer Key

1. d) Top-down approach ✅
2. b) :: ✅
3. b) Initialize objects ✅
4. c) Friend function ✅
5. c) Multiple inheritance ✅
6. b) Function overloading ✅
7. c) virtual ✅
8. c) Abstract class ✅
9. b) Templates ✅
10. c) ofstream ✅

PART – A (3 Marks) Answer Key


11) What are tokens in C++? List their types.
Answer:
Tokens are the smallest individual units in a C++ program.

Types:

● Keywords (int, class, if)


● Identifiers (sum, Student)
● Constants (10, 3.14)
● Strings ("Hello")
● Operators (+, -, *)
● Special symbols (;, {}, ())

12) What is a destructor? How does it differ from a constructor?


Destructor: Special member function used to destroy objects and release memory.

Syntax:

~ClassName(){}

Difference:

Constructor Destructor

Initializes object Destroys object


Same name as class Same name with ~

Can be overloaded Cannot be overloaded

Called at object creation Called at object destruction

13) What is an inline function? State its advantages.


Function expanded at the point of call.

Syntax:

inline int square(int x){


return x*x;
}

Advantages:

● Reduces function call overhead


● Faster execution
● Suitable for small functions

14) Define friend function. How is it useful?


A non-member function that can access private/protected members of a class.

Syntax:

friend void show();

Uses:

● Operator overloading
● Access private data without inheritance
● Increase flexibility

15) What is polymorphism? Differentiate compile-time and runtime


polymorphism.
Polymorphism: One function/operator behaving in multiple ways.

Compile-time Runtime

Early binding Late binding

Function overloading Virtual functions


Faster Slightly slower

16) Significance of this pointer

this is a pointer to current object.

Uses:

● Refers current object


● Resolves naming conflicts
● Returns current object

Example:

this->x = x;

17) Define abstract class with example


Class containing at least one pure virtual function.

Example:

class A{
public:
virtual void show()=0;
};

Cannot create objects directly.

18) Static data members and static member functions


Static Data Member: Shared by all objects.

Static Function: Accesses only static members.

Example:

static int count;


static void show();

19) Explain File Modes

● ios::in → Read
● ios::out → Write
● ios::app → Append
● ios::ate → End position
● ios::trunc → Delete old content
● ios::binary → Binary mode

20) What are file pointers? Give example


Pointers used to move file position.

● seekg() → get pointer


● seekp() → put pointer
● tellg() → current read position
● tellp() → current write position

Example:

[Link](0);

PART – B
21(a)
Characteristics of OOP

● Encapsulation
● Abstraction
● Inheritance
● Polymorphism
● Data hiding
● Message passing

POP vs OOP

● POP → Function oriented


● OOP → Object oriented
● POP → Top-down
● OOP → Bottom-up
● POP → Less secure
● OOP → More secure

21(b)
Explain:

● Tokens
● Variables
● Data types
● Operators
● Type conversion with examples

(Write examples for each.)

22(a)
Constructors Types

● Default constructor
● Parameterized constructor
● Copy constructor
● Dynamic constructor

Include syntax + examples.

22(b)
Program: Array of Objects (Employee Details)
Use the employee array program already discussed.

23(a)
Explain:

● Multiple inheritance
● Hierarchical inheritance
● Hybrid inheritance
with neat diagrams + example programs.

23(b)
Explain:

● Unary operator overloading


● Binary operator overloading
● Friend function operator overloading
with examples.
24(a)
Explain:

● Function templates
● Class templates
● Template overloading
with syntax + examples.

24(b)
Explain:

● try
● throw
● catch
with division-by-zero example.

25(a)
C++ Stream Class Hierarchy

ios
├── istream
├── ostream
└── iostream
├── ifstream
├── ofstream
└── fstream

Explain each class.

25(b)
Program:

● Sequential file access → write/read line by line


● Random access → seekg(), seekp() usage program

You might also like