Lab. Cepy = 2€|e7 2022
(This question paper contains 16 printed pages.]
Your Roll No...
Sr. No. of Question Paper: 1197 F
Unique Paper Code : 2342011201
Name of the Paper : Object-Oricnted Programming
with C+— (DSC04)
Name of the Course : B.Se. (H) Computer Science
Semester : IL
Duration ; 3 Hours Maximum Marks : 90
Instructions for Candidates
1. Write your Roll No. on the top immediately on receipt
of this question paper.
2. Section A is compulsory (Question 1).
3. Attempt any 4 questions from Section B (Questions
2 to 6).
Section A
(Compulsory Question)
1. (a) What are inline functions? Rewrite the following
code using the inline function @)
PTO.1197 2
#include
using namespace std;
float mul (int x, int y)
{
return (x*y);
}
int mainQ)
t
inta = 2,b = 5;
cout << mul(a, b) << "\n";
return 0;
(b) What will be the output of the following program :
(i) #include
using namespace std;
class construct
int p, q;
@)
1197
public:
construct(int x, int y)
QB) }
using namespace std; catch (const char*)
void square(int* snum) A
{ coul<<"Exception inside Myclass\n";
cout<<"Square of 10 is "; throws
*snum *= *snum: !
i }
}
i fi int main()
int main()
t
{
cout<<"Now main starts\n";
int num = 10;
try
square (&num); ‘
cout << num << end];
Myclass();
1
f d
}
Siac ats . catch (const char*)
(iii) #include (3)
{
using namespace std; .
. cout<<"Exception inside main\n" ;
void Myclass()
;
{
cout<<"Now main ends\n";
try
return O;
t
cays ;
throw “y”;1197 6 1197
(c) Write a program that takes a character from the
keyboard and displays its corresponding ASCII
value on the screen. @)
(d) How do the properties of the following two derived
classes A and B differ?
(i) class A: private C{//...};
(ii) class B: public C{//...}; (3)
(e) Write a function to swap two numbers using
pointer datatype parameters, (3)
(f) Identify the error(s) in the following program:
(i) #include (3)
using namespace std;
class four seater
1
public:
void Property()
B
v4
coul<<"It has space for four
persons"< (3)
using namespace std;
Template
class Person
1
Tl m_tl;
T2 m_t2;
public:
Person (TI! tl, T2 t2)
t
m_tl=tl;
m_t2=t2;
cout< obj1(1, 2.34);
Person obj2(2.13, ‘r°);
5
(iii) # include (3)
#inelude
using namespace std;
int main()
1
const int size = 100;
char buffer[size];
ifstream in ("pl.cpp");
ofstream out("p2.cpp");
while(in.get(buffer))
{
in.get();
cout<
using namespace std;
int func(int a, int* b, int& c)
i
int temp = a + *b + ¢;
at= 10:
*b += 20;
c t= 30;
return temp;
}
int main()
t
int x = 1.y = 2, 2= 3)
cout << x < Oh ats eet Tes
i me ¥ eee
cout << func(x, &y, 2);
capes Nn" eg
using namespace std;
class basel
{ public:
virtual void print()
t
1197 13)
cout<<"print version of base class"<print();
ptr->show();
(a) Write a program to print the following output :
(6)
12
123
1234
12345
(b) Write a program to print the area of a square and
circle using function overloading. (9)
1197
(b)
(a)
15
(a) Write a program to define a class, Complex, with
the following features : (10)
(i) data members hidden from outside the
class
(ii) a default and parametrised constructor
(ii) a member function to add another complex
number to it main() function to show the
implementation of the class
Write a function that compares the two given
arrays arrl and arr? of the same size (passed
as parameters) for equality, and returns true or
false. (5)
What is a pure virtual function? Define an abstract
class Polygon, with a data member area that stores
the area of the Polygon, and a pure virtual function
that calculates the area of the Polygon. Inherit a
Rectangle class from the Polygon. Complete the
program to show the use of the abstract class and
polymorphism. (10)
P.O1197 16
(c) Write a function UpperTriangle() that accepts a
square matrix A and its order n as input arguments.
The function should convert matrix A to an
upper triangular matrix by assigning 0 to all
elements below the diagonal (diagonal left to right
from top). (5)
(1000)