0% found this document useful (0 votes)
1 views

Solved_CPP_Question_Paper

The document is a solved question paper on C++ covering key concepts such as encapsulation, binding types, inline functions, streams, friend functions, and constructors. It includes examples of file manipulation, function overloading, inheritance types, and operator overloading. Additionally, it discusses the use of the virtual keyword and file manipulators for output formatting.

Uploaded by

p9280840
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Solved_CPP_Question_Paper

The document is a solved question paper on C++ covering key concepts such as encapsulation, binding types, inline functions, streams, friend functions, and constructors. It includes examples of file manipulation, function overloading, inheritance types, and operator overloading. Additionally, it discusses the use of the virtual keyword and file manipulators for output formatting.

Uploaded by

p9280840
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Solved Question Paper - C++

a) What is Encapsulation?
Encapsulation is the process of wrapping data members and functions into a single unit (class). It hides
internal implementation from outside access.
b) Define Early Binding & Late Binding
Early Binding: Function call resolved at compile time.
Late Binding: Function call resolved at runtime using virtual functions.
c) What is Inline Function?
Inline function reduces function call overhead by inserting code directly at the call site.
d) Explain get() and put() function
get() reads a character, put() writes a character.
e) What is Stream?
A stream is a flow of data between program and device like keyboard, file, or screen.
f) Define Friend Function
Friend function can access private members of class but is not a member itself.
g) Explain new operator & syntax
new allocates memory at runtime.
Syntax: int *p = new int;
h) Need of virtual keyword
virtual allows runtime polymorphism by enabling function overriding.
i) User-defined data types in C++
Structure, Class, Union, Enum
j) Scope Resolution Operator
Used to define function outside class or access global variable when local variable exists.
a) Types of Constructors
1. Default
2. Parameterized
3. Copy
Example - Parameterized:
class Circle {float r; Circle(float x) {r=x;}}
b) Function Overloading
Same function name, different parameters.
Example: int add(int,int) & float add(float,float)
c) Types of Inheritance
Single, Multiple, Multilevel, Hierarchical, Hybrid
d) Virtual Base Class
Prevents duplication in diamond inheritance using 'virtual' keyword.
e) File Manipulators
Solved Question Paper - C++
setw(), setprecision(), setiosflags() - used to format file output.
a) Copy file contents
#include <fstream>
#include <iostream>
using namespace std;
int main() {ifstream in("source.txt"); ofstream out("dest.txt");
char ch; while (in.get(ch)) out.put(ch);
cout << "Copied"; return 0;}
b) Inline function for circle
inline float area(float r) {return 3.14*r*r;}
inline float circ(float r) {return 2*3.14*r;}
c) Vehicle class with derived types
class Vehicle {}; class TwoWheeler:public Vehicle{}; class ThreeWheeler:public Vehicle{}; class
FourWheeler:public Vehicle{};
d) setfill() and setiosflags()
cout << setfill('*') << setw(10) << 123;
cout << setiosflags(ios::left) << setw(10) << 123;
e) Compare strings using operator overloading
class String {char str[100]; void get() {cin>>str;}
bool operator==(String s) {return strcmp(str, s.str)==0;}};

You might also like