0% found this document useful (0 votes)
2 views12 pages

cpp2024pyq

This document is a question paper for the Object Oriented Programming with C++ course, intended for B.Sc. (H) Computer Science students in their second semester. It consists of 12 printed pages, with a total of 90 marks, and includes instructions for candidates, compulsory questions in Section A, and additional questions in Section B. The questions cover various programming concepts, including code snippets, function definitions, class implementations, and error identification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

cpp2024pyq

This document is a question paper for the Object Oriented Programming with C++ course, intended for B.Sc. (H) Computer Science students in their second semester. It consists of 12 printed pages, with a total of 90 marks, and includes instructions for candidates, compulsory questions in Section A, and additional questions in Section B. The questions cover various programming concepts, including code snippets, function definitions, class implementations, and error identification.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

|This question paper contains 12 printed pages.

Your Roll No...

Sr. No. of Question Paper : 4076 H

Unique Paper Code :2342011201

Name of the Paper : Object Oriented Programming


with C++ (DSC-04)

Name of the Course : B.Sc. (H) Computer Science

Semester : II

Duration: 3Hours Maximum Marks: 90

Instructions for Candidates


2: 4+

1. Write your Roll No. on the top immediately on receipt


of this question paper. 5:6 (eue (ot

2. Section A is compulsory (Question 1). : 10


3. Attempt any 4 questions from Section B (Questions
2 to 6).

4. Parts of a question must be answered


together.

P.T.0.
2
4076
Section A

(Compulsory Question)

following: (3)
Write a code snippet to do the
1. (a)
initialized
to char and
" Declare str, a pointer
aue to the value NITIN".

" Display the ASCII value of each character


of the pointer str.

(b) What will be the output after executing the


followingcode segments? Assume all the required
header files have been included. (3×6=18)

i) double sal[]={3415.5, 6718.8, 7911.5):


double total=0;
for (int k=0; kK3; k++)
18o45. totalt=sal [k];
cout << "The total salary is" << total;

k
(ii) for (int j=l;j<=4 2
2 ;j++)
for (int k=l;k<=j; k=k+2) 2

46 cout<< (j+k) ;
cout<<endl:

3
4076 3

(iii) char A){"R', 'G','Y','P', '\0'


for (int k-0;A[k] ; k++)

switch(A(k})
case 'R': cout<<"It is red color";
break;
case 'G': cout<<"It is green color";
break;
case 'Y': cout<<"It 1s yellow color";
break;
default: cout<<"No color":

(iv) class Frt


int %,yi
public: Zuideft
23
Frt (int %, int y)

cout<<"Inside Frt"<<endl; H
this->>X=%;
this->y=yi
cout<<this->x<<this->y<<endl;
}

class S Frt: public Frt


int k;
public:
S Frt (int i,int j, int kl) :Frt
(i,j)
cout<<"Inside S Frt"<<endl;
k=kl;
cout<<k;

void main()

s_Frt obj (2,3, 4):

P.T.O.
4 4076
4076
m)
fl(int& I, int&
(v) void

I-I+10;

m=m+15;

int main ()

int x=40, y=50;


cout << x <K y <<
endl; yo,
fl (x, y)i (c) W
cout<<x<<y<<endl; 65 pr
return 0;
Vo

(vi) void excl (int i) wh


{ br
try
{ ele
if (i%2==0)
throw 1;
aunghr
else (d) Ass
throw 'y': Wri
catch (int i) show

} cout<<"Caught"<<i<<endl; clas

publ
virtu
int main() {
Cout
try
{ };
4076 5

exc1 (4) ;
excl (5) ;

catch (...)
cout<<"all caught":

return 0;

(c) Write the definition for the following function


prototype : (3)
void concatenate(char a[], char b[], int n, int m)
where n and m. are the sizes of the arrays a and
respectively. The function, concatenate appends
elements of array b at the end of array a.

(d) Assume all relevant header files are


included.
Write. the main function for the following
code to
show runtime polymorphism.
(3)
class Base

public:
virtual void show()
{
cout<<"Inside base B1";

Alun) P.T.0.
x
4076
Derived:
6

public Base
optcam fout(Ca 2.tx 4(
class

public:
void show ()
cout<<"Inside d e r i v e d " :
3
void main ()

-i moondett
(e) Write a program to copy the content of the file
*Al.txt" to another file A2.txt", word by word.
Also, display the number of words copied.
3.
(3)

Section B {

2. (a) Write a program


that accepts x and n as De
1nput
from the command line to
compute the following app
series.
Def
s = X- x/3! t x/5! - men
x/7! +
where is the
number of terms in the above (i)
series.
(9)
4076 7
2bxt");
(b) RewTite the following code using for and switch
statements. Also. give the output of the code. (5)

char * ch"hello world"; 442


int county=0, countalp=:
int i=0;
while (ch [i])
if (ch [il ==a' 1
ch[i]=='c" ll c[i]='-')
else

it;

coutKecotKKaál;

3. Conside e following claSs:


(15)
class Barkaoont

Declare cata members n. 2cc00 d bal2ce oi


appropriate data types for the class
Bankaccou
Define its meber fnctions
LO perform ibe 123k
mentioned below

(i) Default and


parameterized constructoIs 10
initialize data members of the
class Bankaccou.
4076 8

function reads values for name,


(i1) void input(0: This
from the user.
accno and balance

debits
void withdraw (double x): This function
(11)
only if the
(subtracts) x from the balance
"unable to
(balance-x) >=500 else the message,
debit, the minimum balance should
be 500" is

printed.

(iv) void deposit (double x) : This function credits


(adds) x to the balance.

(v) void display(0: This function prints all account


details of a given bank account object.

Write a main function to create the Bankaccount


objects and illustrate the usage of the above functions.

4. a) Give the output of the following code


: (5)
class Figure

protected:
double area;
public :
Figure ()
4076
cout<<" Figure Constructor":
area-0:

virtual void display () =0:

class circle: public Figure

double radíus;
publíc:
circle (double r)

cout<<" Inside Circle Constructor"<<endl;


radiug=r;

voíd display ()
area-3.14*radiug*radius;
ig"<<areaxkendl;
cout<<"The area of círcle

class rectangle: publíc Pigure


double length, breadth;
public:
rectangle (double l, double b)
cout<<" Inside Bectangle Constructor"<<endl;
length=l;
breadth=b;

void display ()
area=length*breadth;
cout<<"The area of rectangle is"<<area<<endl;

int main ()

circle cl(4.5) ;
rectangle rl(5, 6) ;
cl.display () i 6395
rl.display () i
return 0;

30.
P.T.0.
4076 10

(b) Consider the following declaration of the Vector


class : (10)
teantlale <ceas
class Vector

int a(20);
int n; clas (R)
T aJ ;
AeH (3)
Rewrite the above class using templates suitably.
Also, define the following member functions in
the class :

(i)) Default and Copy


constructor.
(ii) void input (int n): This
function reads n
values in an array.
(iiü) Vector add(....):
This function adds two
vector objects
element-wise, stores the
result in a new vector
object, and returns
the new vector
object.
(iv) void display() :
This
elements of the vector. function prints

5. (a) ldentify an error


in the following code and give
reasons for the same.
(6)
11
4076
class first c

int pi
protected:
char s;
public
float qi
first c(int pl, char s1, float ql) :p(p1), s(sl),
q(q1)}

class second c: public first_c


{
double tl;
public:
second c(int i, float j, char l, double p)
first c(i,l,j):
tl-p;

void nain ()

first_c tl(
cout<<tl.p; l o
cout<<ti.s: leu
cout<<tl.q:
ottd
secondc t2(1,3.4£, 'y',56.7):
cout<<t2.pi |) Prt ein
cout<<t2.si
cout<<t2.qi
cout<<t2.tl: |/ tl ret
(b) Consider the following
function declaration:
void sort (int al],int
n)
4076 12

Detine the tunction sort to sort an array


of
integers, Show step-by-step execution
of the above
S + 4
sort tunetion tor the following data.
34, 50, 71, 1, 2
fr
(a) Write C+t deelarations/code for the following
(i) Atunction f sum takes three arguments as
follows: x, an array of integers, constant y
of datatype double, and chi a character
Louat douhle Y, reference variable. The return type of the
funetion is void.
chan elai)
(ii) Declare a function fx, that accepts two
parameters: A: a pointer to double, B: a
Hzaude A, 2-dimensional array of integers, and returns
a void datatype.
(ii) An array of float Binitialized to values
3.4, 5.6, 7.8, 9.1.
$3.4,S., 7.4, (iv) Declare two pointer variables p and q
initialized to the address of two float
4; variables x and y. Write statements to
foats,yes increment the value of x and y using p and

Write a statement to find the maximum of


two numbers, pvalue and rvalue using the
(*pltt; ternary operator. (10)
(*) fti
(b) Create a class Box with a static data member,
count. Write the class definition that displays the
number of objects created and destroyed. (5)
(2000)

You might also like