CPP (PS) 2022 23
CPP (PS) 2022 23
CPP (PS) 2022 23
)
2022-2.3
Your Roll No.. e
2. Section A is compulsory.
3. Answer any four questions from Section B.
4. Parts of a question must be answered together.
5. Write program statements in C++ language.
P.T.0.
1002 2 1002 3
Section A
(c) Wrie afunction swap() to interchangc the values
of two numbcrs using call by refercnce. (3)
1. (a) Name any three built-in data types used in C+++.
() Name the type of inheritancc for class B, class
Also write number of bytes used by each of them,
(3) Cand class D in the following code scgmcnt.
(3)
(b) ldentify the errors in the following C+t statements:
class A{...};
() char ch="Hello" ;
clasS B: public A{...}:
(ii) int b(6): class C: public A{...}i
(iii) int 1ine Count=4; (3) class D: public B, public c{...};
(c) Rewrite the following code using while loop: (g) List any three properties of constructor function.
(3)
for (int number=l; number<=l2; number++)
(h) State True or False for each of the following
Cout<<number; (3)
statements: (3)
(d) Give the output of the following code: (3)
(i) The member function of the derived class
int total=0; can access the protected members of the
int N=5; base class.
for (int i-0; i<N; i++) (ii) The while loop runs at least one time.
total+=l;
(iii) Statement return (0); at the end of
Cout<< total; main ) function indicates an error.
P.T.0.
1002 4
1002 5
() Which file mode would you use while opening a
Section B
file under following situations: (3)
(i) To add data to the end of the file only 2. (a) Write afunction in C++ that takes a number n
as input and returns its factorial if ' n ' is an even
(ii) To open a file for the purpose of writing number else returns 0. (5)
only.
(b) What will be the output of the following code
(ii) To delete the contents of the file if it segments: (5)
exists.
(i) int a=10;
int b=a-- +3;
(i) Identify the error in the following code and correct cout<<"a="<<a<<endl<<"b="<<b;
(v) 4 +9*6/2
P.T.0.
6 1002 7
1002
scope resolution
display the following (c) Explain the significance of using
3. (a) Write a C++ program to following
number of rows operator :: in C+t. Give the output of the
pattern on the output screen. The (5)
For
should be taken from the user as an input. program:
then the
example if the number of rows is 5
following output should come. (5)
#include<iostream>
A using namespace std;
BB int m=10;
int main ()
CCC
DDDD int m=20;
EEEEE
int k=m;
int, m=30;
block \n":
cout<<"we are in inner
(b) (i) Identify the error(s) if any, correct the cout<<"k="<<k<<"\n";
error(s) and give output of the following cout<<"m="<<m<<"\n":
<<"\n";
code: (5) cout<< "::m=" <<::m
outer block \n";:
cout<< "\n We are in
int main () Cout<< "m=" <<m<<"\n";
{int a=3500, b=3000 "::m=" << ::m << "\n";
cout<<
cout<<"atb", -(atb) ; return 0;
return 0;
segment:
(ii) Give the output of the following code
compute the area of a circle
4. (a) Write a program to
int i; function overloading. (5)
for (i=8; i>=0; i--) and arectangle using
if (i82==0) segment: (5)
continue; (b) Consider the following code
else
cout<<i<<endl;
P.T.0.
1002 8 1002
(c) With the help of a suitable example explain the (c) Differentiate between compile-time polymorphism
concept of inline functions, Under what and run-time polymorphism. Explain the concepts
circumstances does an inline function not work? of early binding and late binding related to the
(5) same. (5)
P.T.0.
1002 12
(500)