0% found this document useful (0 votes)
62 views25 pages

OOP in C++

This document contains a test paper on Object Oriented Programming with C++. It has 7 questions assessing concepts like classes, objects, inheritance, polymorphism, templates and file operations. Students are required to define terms, write programs, explain concepts and identify differences between procedural and object oriented programming. The paper is out of 80 marks and aims to evaluate the student's understanding of key OOP concepts in C++.

Uploaded by

zk3136891
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)
62 views25 pages

OOP in C++

This document contains a test paper on Object Oriented Programming with C++. It has 7 questions assessing concepts like classes, objects, inheritance, polymorphism, templates and file operations. Students are required to define terms, write programs, explain concepts and identify differences between procedural and object oriented programming. The paper is out of 80 marks and aims to evaluate the student's understanding of key OOP concepts in C++.

Uploaded by

zk3136891
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/ 25

s- 4

Total nu m be r of pr in te d pa ge
44 (3) OOPR 3· 4 (0 )

20 21
( Held in 20 22 )
OGRAMM IN G
O B JE C T O R IE N T E D PR
IN C + +

Pa pe r : BCA 3· 4

Fu ll Marks : 80

Time : Three ho ur s
in di ca te
The fi gu re s in th e m ar gi n
ns .
fu ll m ar ks fo r th e qu es tio

ns as di re ct ed :
1. Answer th e fallowing qu es tio IxB=B
ra m m in g,
(a) In O bj ec t O ri en te d Pr og
entity.
_ _ _ is th e ba si c ru nt im e
(Fill in th e blank)
no t be
(b) A re fe re nc e va ri ab le m ay
initialized. (State true or false)
is us ed to
(c) In C++, _ _ _ op er at or
.
allocate memory dynamically
(Fi.ll in th e blank)

Contd.
(d) A constructor function can return
values. (State true or false)
{e) Destructor functions can be overloaded.
(State tnte or false)
(I) _ _ _ operator cannot be overloaded.
· (Fi.ll in the blank}

(g} An _ _ _ class cannot be used to


create objects. (Fill in the blank}

{h) It is legal to have an object of one class


as a member of another class.
(State trne or false)

2. Define the following terms : 2x6=12

(a) Keyword
(b) Identifier
(c) Function Prototype
(d) Return by reference
(e) Copy constructor
(I) Stream

3. Answer any four of the following questions:


Sx4=20

(a.) W~at are the advantages of Object


Oriented Programming ?

44 (3) OOPR 3·4 (0)/G 2


(b) Wh at is re fe ren ce va ria ble ? Wh at is 1Ls
ma jor use ?
(c) Wh en will you ma ke a fun ctio n inli nc ?
Sta te adv ant age s and di sadvan tag es of
inl ine fun ctio n.
(d) Wh at do you me an by overlo a din g of a
fun cti on ? Wh en do we us e thi s
con cep t?
(e) Wh at are the rul es for ove rlo adi n g
op era tor s ?
{f} Give a bri ef int rod uct ion of for ma ttin g
fla gs and ma nip ula tor s.

4. An sw er an y fou r of the following que stio n s :


10x 4=4 0

(a) Ex pla in the use s of sco pe res olu tio n


op era tor wit h sui tab le exa mp le.

(b) Wh at is frie nd fun cti on ? Wh at are the


pro per tie s of frie nd fun cti on ? Wh en
frie nd fun cti ons are use d to overlo ad
op era tor s ? 2+4 +4= l 0

(c) Wh at is dy nam ic con str uct o r ? Ex pla in


wi th a sui tab le exa mp le.
at are th e
(d) Wh at is inh eri tan ce ? Wh
typ es of inh eri ta n ce ? Explain.

Contd.
,, ,-...
(e) What is run-ti me polym orphis m ? How
to achiev e run-ti me polym orphis m ?
Expla in with suitab le examp le. fl
t
(f) Define a class to store matri ces. Write
suitab le friend functi ons to add and
multip ly two matric es.
(g) Write a class templ ate for storin g an
array of eleme nts.
Overl oad the<< and>> opera tors.
(h) Briefl y expla in the fallow ing classe s
• !strea m
• Ostre am
• Ifstream
• Ofstre am
• filebuf
Total num.ber of printed p ages- 3
44 (Sem-3 ) OOPR 3·4
2018
'
OBJE CT ORIE NTED PROG RAMM ING
INC+ +
Paper : 3·4
Full Marks : 80
Time : Three hours
The figure s in the margi n indica te
full mark_s for the questio,:i.s.
Answe r any five questions.
1. Define the following terms with examp les:
4x4=1 6
i) Polymorphism
ii) Encaps ulation -
iii) Multilevel Inherit ance
· iv) Inline function.
2. i) Differences between object oriented and
proced ure oriented programming. 4
Contd.
ii) Wh at is fun ctio n ? How can you define
me mb er fun ctio n ins ide and out sid e
cla ss? Wr ite a pro gra m in C++ to
illu stra te the con cep t of friend function.
1+4+7=12

3. i) Wh at do me an by this poi nte r ? Give


one example. 4

ii) . Wr ite a pro gra m to cre ate a cla ss


pro duc t wh ich · sto re info rma tion suc h
as pro duc t_i d, pro duc t_n am e, and
pri ce. Wr ite me mb er · fun ctio ns. for
cre atin g and dis pla yin g the · val ues of
var iou s cla sse s and objects. 10

iii) Wh at is a vir tua l bas e cla ss? 2

4. i) Wh at do you me an . by fun cti on


ove rloa din g ? How can you dec lare and
def ine ove rlo ade d fun ctio n ? Exp lain
wit h a pro gra m in C++. 9

ii) Wr ite a · C++ pro gra m to- sw ap two


num ber s usi ng cal l by val ue and call
by refe ren ce. · 7

5. i) Is the re any differe~ce bet we en pri vat e


and pro tec ted inh eri tan ce? Ex pla in
wit h sui tab le exa mp les. 10

ii) Exp lain the con cep t of dyn am ic binding.


6
44 (Sem - 3) OOPR 3·4/ G 2
6. i) W ha t do me an by ab str ac t cla ss?
2

ii) Wr ite a C++ pro gra m to im ple me nt


single inh eri tan ce with pu bli c ac ce ss
specific. 7

iii) Write a pro gra m to de mo ns tra te us e of


sta tic da ta me mb er an d sta tic me mb er
fun cti on . 7

7. i) W ha t is tem pla te ? Briefly explain with


on e example.
5

ii) Ex pla in va rio us file op era tio ns in C++


wi th sui tab le examples. 8

iii) W ha t is the ne ed of virtual fun cti on ?


3

3 80 0
4a {Sem - 3) OOPR 3·4 / G
Tota l num ber of prin ted pag es- 7
42 (2) 09P C 3 (El)
201 7
G
OB JEC T OR IEN TED . PROGRAMMIN
WITH C++
Pap er : 2.3
Ful l Ma rks : 70
Time Three hou rs
The fig ure s in the ma rgi n ind ica te
ful l ma rks for the _questions.·
1. Answer the following : (any ten)
2•5x 10= 25
(a) Wh at are objects ? How are they crea ted
in C++ ? Sho w wit h ari example.
(b) How doe s a C++ stru ctu re differ from
a C++ clas s ?
Con td .
{c) Define a class to represen t · a bank
account. Include the following
members.

Data members

(i) Name of account holder

(ii) Account number

(iii) Type of account

(iµ) Current Balance

Member functions :

(i) to assign initial values

(ii). to deposit an amount ·

(iii) to withdraw an amount.

You have not been asked to write the


complete -body of the functions.

(d) Name two logical operators used in C++.


Explain in short how they work.

42 (2) OOPC 3 (El)/G 2


t
(e) Ex pla in ho vl the 'br ea k' sta tem en
v.~ork s giv ing on e ex am ple .

(f) Na me 4 ke yw ord s in C++.

(g) Na me 2 ari thm eti c op era tor s tha t co uld


th
be ap pli ed on pr int er va ria ble s. Wi
·
an ex am ple sh ow ho w the y work.

se
{h) W ha t is the dif fer en ce be tw ee n a ba
cla ss an d a de riv ed cla ss ? Give on
e

ex am ple .

e
{i) W ha t ar e th e ru les go ve rn ing th
de cla rat ion of a co ns tru cto r ?

t
@ In wh at wa y a de str uc tor is dif fer en
fro m a de let e op era tor · ?

{k) In wh at wa y a me mb er fu nc tio n is
di ffe re nt fro m a co nv en tio na l us er
de fin ed fu nc tio n ?

(!) Give an ex am ple of an arr ay of objects.

Co ntd .
3
42 (2) OOPC 3 (El )/ G
I

2. Answer an y fiv e of the foJlowing quc ~tio ns :


ax5 = 15

(a) Name two compilers sup por ting C++.


In C/C++, why is the ma in () fun ctio n
popularly called as the driver fun ctio n ?

(b) Wh at is the difference bet wee n inli ne


fun ctio ns and nor ma l fun ctio ns ? Write
an inline function to find the ma xim um
of thre e num ber s.

(c) Date con sist s of day, mo nth and yea r.


Can this item be modeled as a cla ss ?
If so write app rop riat e sta tem ent to do
it. Write a me mb er fun ctio n for this
cla ss to pri nt a dat e as dd- mn -yr .

(d) Wh at is a dat a type ? Wh at are the


bas ic dat a typ es sup por t~d by C++ ? Is
C++ cas e sen siti ve ? Na me two
qualifiers tha t can be app lied to dat a
typ es to yield add itio nal dat a types.

42 (2) OOPC 3 (El) /G 4


em en t to
(e) W ri te a de cl ar at io n st at
tin g to a
d ec la~e a po in te r 'ic ' po in
of * ic ?
ch ar ac te r. W ha t is th e type
de cl ar e an
Also w rit e a st at em en t to
te rs . How
ar ra y of po in te rs . to ch ar ac
em en ts of
ca n yo u ac ce ss in di vi du al el
po in te r ?
th is ar ra y? W ha t is a nu ll
ng le level
(f} Give one ex am pl e ea ch of si
he ri ta nc e.
in he ri ta nc e an d multilevel in
ha t is vi si bi lit y m od e ? W ha t ar e th e
(g) W
or te d by
di ff er en t visibility m od es su pp
C++ ?

wing :
3. A ns w er an y tw o of th e follo
2x l0 =2 0

rit e ap pr op ri at e st at em en ts in C++
(a) W
ct an gl e' to
to de fi ne a cl as s na m ed 're
two da ta
re pr es en t re ct an gl es , ha vi ng
ad th ', bo th
m em be rs 'le ng th ' an d 'b re
w hi ch ar e re al nu m be rs . W rit e a
of
zero va lu es
de fa ul t co ns tr uc to r to as si gn
rs . W ri te
to bo th th e da ta m em be
w it h tw o
an ot he r co ns tr.u ct or
va lu es to
pa ra m et er s to as si gn in iti al
o m em be r
th e da ta m em be rs . W rit e tw
ar ea of a
fu nc tio ns , on e to find th e
find th e
re ct an gl e an d th e ot he r to
pe ri m et er of a re ct an gl e.
5 Contd.
42 (2) OOPC 3 (E l)/ G
! .~;.
\
\
{b) Co ns id er an ex am
pl e of de cl ar in g
ex am in at io n re su lt. De sig
cl as se s : St ud en t, E~am an
n th re e .I
d Result.
Th e stu de nt cla ss ha s da ta
me mb er s \
roll nu m be r, na m e etc. Crea
te th e class
Ex am by in he rit in g th e stu \
de nt cla ss . .
Th e Bx am cl as s ad ds da ta \
me mb er s
re pr es en tin g th e m ar ks -sco
r.ed in four
su bj ec ts, En gl ish , Physics,
Ch em ist ry
an d M at he m at ic s. Derive
th e Re su lt
cl as s from th e Ex am cl as s
ad di ng two
da ta m em be rs to ta l-m ar ks
an d cla ss -
ob ta in ed . Write an in ter ac tiv
e pr og ra m
to m od el th is re lat io ns hi p.
W ha t type
of. in he rit an ce is th is ?
(c) W rit e ap pr op ria te sta
te m en ts in C++
to de fin e a cl as s na m ed
'iv ec to r' to
re pr es en t an in te ge r ve cto
r of va ria bl e
le ng th . It will ha ve tw o da
ta m em be rs ,
th e na m e of th e ve ct or an
d its len gt h.
W rit e a de fa ul t co ns tru ct
or to as sig n
ze ro va lu es to all th e el em
en ts of th e
ve ct or . A no th er co ns tru ct
or wi th an
in te ge r ty pe pa ra m et er to
as si gn th at
va lu e to al l th e el em en ts
of th e ve cto r.
W rit e a m em be r fu nc tio
n to -so rt th e
ve ct or in de sc en di ng or de
r.
i 2 (2) OOPC 3 (E l)/G
6
4. Write short notes on any two of the
following : 2x5=10

(i) Concept of operator overloading

(ii) Abstract class and pure virtual function

(iii) Dynamic initialization of objects

(iv) Concept of destructors

(v) Procedural programming yersus OOP.


44(3JOOPR(N/o )3.4
Total No. of Printed Pages =04
2016
OBJECT ORIENTED PROGRAMMING INC++
(NEW&OLD)
Paper: 3.4
Full Marks: 80
Time: 3 Hours
Tlie figures in the margin indicate/ull marks for
the questions.
2x I 0=20
1. Answer the following questions
(a) Is C++ is a superset of C? If yes, then justif
y the
statement.
and
(b) (e) Point out the error if any, in the following class
correct it.
Class employee
{
Inti;
Static int j;
Public:
Employee()
{
i=IO;
j=IO;
}
};
(c) Why we have called that objects are basic run time
entities in object oriented system? P.T.0
(d) How we can differ the following two statements-
,J
(2)
PRODU CT G l(G2); PRODUCT O I ==G2;
(, 1 und G2 arc objects of PRODUCT class
(t) ''using namespacc std;"- What do you mean by this?
('f) Suppose a c]ass p is inherited from two base classes M
and N. All three classes have a member function-'disp lay
() '. In this scenario, what wilJ be the ambiguity and how
can we solve it?
(g) class UNARY
{
Jnt a;
Public:
UNARY (int x)
{a=x;}
Friend void operator-(UNARY z)
{z.a==-z.a;}

Void display()
{cout<<a<<"\n";}
};
fnt main()
{
UNARY S(20);
-S·
'
S.display();
Return O;

What is the output? Justify your answer.


(h) Class D is derived from class B. The class D does not
contain any data members of its own. Does the class D
require constructors? Justify your answer?
(i) Explain how reusability of code can be achieved in C++.
U) "Generic pointer is also called void pointer'·'-lllustrate
the statement with proper example.
2. (a) How we . do the salient features object oriented 4+4+2=1 0
program1ning approach? State the properties of static
member function. How we can access a static member
function? Give an example.

(b) Design a class STUDENT to perform the following 10


(3)
functions-
(i) To read the basic information of a student. (Name,
~?ll_No., Branch, Age)
(u) To display the basic infonnation of the youngest
student.
(i_ii) To modify the branch name if one student changes
his/her branch.
3. (a) Consider a class network as shown in the figure- I:
10

A
a_name enterdata()
reg_no displayO
head

B
b_name

D
name
C name
a amount

The class 'D' derives information from both 'B' and 'C'
classes publicly, which are deriving information from the
class 'A' publicly. Define all the four classes and write a
program to create, update and display the infonnation
contained in 'D' object.

(b) List different access specifier used in C++. How we can


access a private data member of a class using a non-
member function? Explain the significance of virtual base
class in inheritance represented by Figure- I. 2+4+4=10

P.T.O
(4)
4. a) \Vrite name of any two of any two operators 2+8= 10
that cannot be overloaded . Create a class
~sTRING i.
wnich will take strings of length ' I'
dynamically. Now overloaded the addition
operator to add two string and display the
resultant string. Use proper constructor to
initialize the data members and destructors to
free the memory.
b) \Vhat do you mean by constructor? What 4+4+2= 1o
are the different type of call of a constructor?
Show with examples. Give the output of the
following program
int flag=();
class OOP
{
Public:
OOP0
{
cout<<"\nCREATED:";
coat<<- - flag<<"\t'';
}
-OOPO
{
cout<<"\nDESTROYED:";
coat <<flag++<<"\t"; .
}
};
Int main0
{
{
OOPA;
{
OOPE;
}
}
Return 0;
}
5. Write short notes on (any four) 5x4=20
(a) File Modes (d) Function Overloading
(b) Templates (e) Constructor
(c) Data Encapsulation
Total number of printed pages-4
42 (2) OOPC 2·3
2 0 16
OBJE CT O RIENT ED
PROGRAMM IN G WITH. C++
Paper : 2·3 (iii)
Full Marks : 70
Time : Three hours
The figures in the margin indicat e
full marks for the questions.
Answer any four questions from Part A.
PART A
1. Differentiate between : 3x5=15
(a) Pr?cedu ral program ming and object
oriented programming.
(b) Class and Object.
(c) Keyword and Identifier in C++.
(d) Functio n Prototy pe and Functio n
Definition.
(e) Member function and Friend function.
Contd.
- c:
2. (a) W ha t i s d a t a o b ~ I. r n c 1 1 n n ~ n d
en<" ap s t1fM ion m thr <ont,' x' o f <J() P ?
Explt1m briefly h rJw dosCJ<'R art! u~wd Ir>
encapsulate data . S
(b) What 1s inheritance ? What- are th <-
advantages of inhe ritance in OOP ?
5
{c) What is operator preced ence ? Explain
with an example the precede n ce of
various operators in C++ . 5
3. (a) What are Basic Data types and User
defined Data types in C++ ? 6
(b) What are the different ways of defining
me1nber functions in C++ ? How can
we access a private member function ?
4+1 =5
(c) What is meant by default arguments of
a function ? Demonstrate their use with
an example. What are constant
arguments ? 3+1 =4
4. (a) Explain with examples the different
ways of passing objects as fun c tion
argurnents. 5
42 (2) OOPC 2·3/G 2
(b) Define static data members ao<l static
member functions with proper
examples. 5

(c} What is a constructor ? What are the


different types of constructors ? 5

5. (a) What is dynamic initialization of


objects? How can we initialize an object
dynamically ? 5
(b) What is operator overloading ? What
are, the operators that cannot be
overloaded ? 3+ 1=4

(c) Explain the different types of


inheritance in C++. 6

6. Define the fallowing : 3x5=15

(a) Virtual base class


(b) Abstract class

(c) New and Delete operators

(d) Null point~r and Void pointer


'

(e) 'this' pointer.

42 (2) OOPC 2·3/G 3 Contd.


PART B

7. An swer any one ques tion


(a) Define priva te, p·u blic and protected
members of a clas s. Explain h ow they
are inherited in public, priva te an d
protected derivation with examples .
10

{b) What is dynamic binding ? What


mechanism is used to implement
runtime polymorphism in C++ ? Explain
with proper examples. 10

(c) Write a program in C++ to create a


class named 'matrix'. Define
constructors-default, parameterized and
copy constructors. Define member
fun ctions to read and display a matrix.
Overload the '+' and '-' operators to
add subtract two matrices. 10

42 (2 ) OOPC 2·3/G 4
2015

OBJECT ORIENTED PROGRAMMING


Paper: 3.4
Full Marks: 80
Time : Three hours

The figure in the margin indicate full marks for


the questions

Answer any four questions

Ql. (a). What 1s Object Oriented


Programming(OOP)? Describe its benefits. 2+3=5
(b). Differentiate call by pointer and call by
reference with a valid reason. 5
(c) Define the tenns encapsulation and
Abstraction. 5
(d) What is function protyping? Explain
briefly with an example. 2+3=5

Q2. (a) Define constructor and destructor. Write a


program to implement constructor and destructor.
2+3===5
(b) What is Operator overloading? ,,
J
a :

(c) How does a class enforce encapsulation


data hiding and abstraction? Explain with
example of each. 3+3=6

(d) Explain friend function. Write a program to


implement it. 2+4=6

Q3. (a) What is meant by inheritance? Explain


its different types. 2+4=6

(b) What is polymorphism? Define virtual Base


class? 3+3=6

(d) Define a class student with the following


specification:
rollno : integer
sname : 20 characters
Derive two classes engineeringMech and
engineeringComp. The class engineeringMech
will represent students belonging to Mechanical
stream and the class engineeringComp will
represent students belonging to Computer
Science stream. The engineeringMech class
will have additional data _members
sub l ,sub2,sub3 and to store marks obtained by
a student in three subjects The class
engineeringComp will have additional data
members sub l ,sub2,sub3 and sub4 to store
marks obtained by a student in four subjects.
.,, SC

Write the rollowing men1ber functions in the


clas ses engineeringMech and engineeringC01np.
Sto tal( ) A function to calculate the total
n1arks obt ain ed by a student
tak eda ta() function to accept values of the
dat a me mb ers
Sho wd ata () : function to display the ma rk sheet
of a stu den t . 8

Q4 (a) De fine a class time to store time as hou


r,
min ute and sec ond , all being ipteger values. Write
me mb er fun ctio ns to display time in standar
d
formats. Als o ove rloa d the ++ and -- operators to
inc rea se and dec rea se a giv en time by one second
wh ere the min ute and hou r values will hav e to be
upd ate d wh ene ver .necessary. 10

(b) Define a structure em plo yee wit h the ~ollowing


specifications.
Em pno : Int ege r
Ename: 20 character
Basic, hra, da: float
Ca lcu late () : a function to compute net pay as
bas ic+ hra +d a with float return type. Getd~ta():_ a
function to read values for empno, ~name, basic,
bra , da. Dispdata(): a function to display all the
dat a on the screen l0
Write a ma in program to test the program.

You might also like