OOP in C++
OOP in C++
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}
(a) Keyword
(b) Identifier
(c) Function Prototype
(d) Return by reference
(e) Copy constructor
(I) Stream
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 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
Member functions :
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 ?
Co ntd .
3
42 (2) OOPC 3 (El )/ G
I
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
Void display()
{cout<<a<<"\n";}
};
fnt main()
{
UNARY S(20);
-S·
'
S.display();
Return O;
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.
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
42 (2 ) OOPC 2·3/G 4
2015