Previous year paper

THEORY EXAMINATION (SEM–IV) 2016-17 OBJECT ORIENTED PROGRAMMING WITH C++

Computer Science B.Tech 0 downloads

About this previous year paper

Course: B.Tech (Computer Science / IT)
Subject Code: CS403
Subject Title: Object-Oriented Programming with C++
Exam Type: Theory
Duration: 3 Hours
Maximum Marks: 100

SECTION – A (10 × 2 = 20 Marks)

Short conceptual questions testing understanding of OOP fundamentals

No.ConceptExplanation
(a)GeneralizationProcess of extracting common properties and behaviors from multiple classes to create a base class.
(b)Abstract ClassA class with at least one pure virtual function; cannot be instantiated directly.
(c)this PointerImplicit pointer used to refer to the invoking object inside a member function.
(d)DestructorSpecial member function with ~ClassName() used to free resources when an object goes out of scope.
(e)PolymorphismAbility of a function or operator to behave differently based on input or object type — achieved via overloading or virtual functions.
(f)Derived AttributeAttribute computed from other attributes, not stored directly (e.g., total = price × quantity).
(g)InheritanceMechanism of deriving a new class from an existing one to reuse and extend its functionality.
(h)Characteristics of OOPsEncapsulation, inheritance, polymorphism, abstraction, reusability.
(i)Pure Virtual FunctionA virtual function declared as =0; defines an interface for derived classes.
(j)Inline FunctionFunction expanded inline to reduce function call overhead; declared with keyword inline.

SECTION – B (5 × 10 = 50 Marks)

Analytical and programming-based questions

(a) Copy Constructor

Used to initialize an object from another of the same class.

(b) Constructor Example – Area of Circle

 

#include <iostream> using namespace std; class Circle {  float r; public:  Circle(float radius) { r = radius; }  float area() { return 3.14 * r * r; } }; int main() {  Circle c1(5);  cout << "Area = " << c1.area(); }

(c) Function Overloading

Functions with the same name but different parameter lists.

(d) Operator Overloading

Overloading operators for user-defined types.
Example: Binary + operator

(e) OOP vs Procedural Programming

FeatureOOPProcedural
StructureClass-basedFunction-based
DataEncapsulatedGlobal
ReusabilityHighLimited
ExamplesC++, JavaC, Pascal

(f) Sorting Ten Integers (C++)

 

#include <iostream> using namespace std; int main() {  int a[10];  for(int i=0;i<10;i++) cin >> a[i];  sort(a, a+10);  for(int i=0;i<10;i++) cout << a[i] << " "; }

(g) Command Line Arguments – Factorial

 

#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char* argv[]) {  int n = atoi(argv[1]);  int f=1; for(int i=1;i<=n;i++) f*=i;  cout << "Factorial = " << f; }

(h) Exception Handling

Handles runtime errors gracefully using try, catch, and throw.

SECTION – C (2 × 15 = 30 Marks)

Advanced C++ programming and conceptual application

Q3. (i) File Operations

File Handling in C++:

(ii) Class Template

 

template <class T> class Calculator { public:  T add(T a, T b) { return a + b; } }; int main() {  Calculator<int> c;  cout << c.add(4, 5); }

Q4. Inheritance (All Types with Example)

TypeExampleDescription
SingleA → BOne base, one derived class.
MultipleA,B → CDerived from multiple base classes.
MultilevelA → B → CDerived in successive levels.
HierarchicalA → B, COne base → many derived.
HybridCombinationMix of above types.

Q5. Short Notes

(i) Virtual Function
Used for runtime polymorphism — ensures that the derived class function is invoked via base class pointer.

(ii) Function Template
Generic function that works with multiple data types:

 

template <class T> T add(T a, T b) { return a + b; }

Summary

This Object-Oriented Programming with C++ (CS403) paper thoroughly tests:

TopicCore Concepts
OOP FundamentalsAbstraction, encapsulation, inheritance, polymorphism
Functions & OperatorsOverloading, inline, virtual functions
Classes & ObjectsConstructors, destructors, copy constructor
Templates & FilesGeneric programming and file I/O
Error HandlingException handling and robustness

 

ofstream fout("data.txt"); fout << "Hello World!"; fout.close(); ifstream fin("data.txt"); string s; fin >> s; cout << s; fin.close();

 

try {  int x = 5, y = 0;  if(y == 0) throw "Divide by zero!";  cout << x / y; } catch(const char* msg) {  cout << msg; }

 

class Complex {  int r, i; public:  Complex(int a, int b) { r = a; i = b; }  Complex operator+(Complex c) {    return Complex(r + c.r, i + c.i);  } };

 

void print(int a);   void print(double a);

 

class Demo {  int x; public:  Demo(int a) { x = a; }  Demo(Demo &d) { x = d.x; } // copy constructor };

TypePrevious year paper
SubjectComputer Science
Board / courseB.Tech
FilePDF · 50.4 KB
Shared by SuGanta International

Added by the SuGanta team.