CPP (PS) 2022 23

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

(This question paper contains 12 printed pages.

)
2022-2.3
Your Roll No.. e

Sr. No. of Question Paper : 1002 D

Unique Paper Code : 2342571 101

Name of the Paper Programming Fundamentals


Using C++

Name of the Course : B.Se. (Multidisciplinary


Courses of Study with Three
Core Disciplines under
UGCF 2022)

Semester :First (I)


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.
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;

it. Give the output of the corrected code. (3)


(ii) int x=5;
if (x=30)
class one cout<<"\a x is odd":
public: else
int i;
one (int x) {
cout<<"\n x is even";
i=x;
Cout<<"Object created with value "<<i<kendl; (c) Find the output of the following expressions in
~one (int x) ( C++: (5)
)
cout<<"Bye! "<<i<<"\n":
(i) 20
int main()(
one objl (20) ; (ii) (2l==22) ?5: 6
one obj2 (70) ;
return 0;
) (iii) 19%3

(iv) 56! = 90 56<100

(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

A default constructor to initialize a and b to 0.


switch (choice)
- A parameterized constructor to initialize a and
Case l:
b to passed values.
case 4: cout<<"Hello ";
Cout<<"World\n";
break; A function print () to display the complex
Case 2: number in the form a+ib, i.e. for a=4 and b=5,
case 3:cout<<"Banana\n"; the output of print should be 4+i5.
cout<<"Apple\n";
de fault: cout<<"Orange\n";
cout<<"Guava\n" (b) Add appropriate catch blocks for the following
break; piece of code: (5)
}
tryl
if (x == 1)
What will be the output for following values of throW X;
choice : if (x== 0)
throw 'x';
(i) choice=l if (x == -1)
throw 1.0;
(ii) choice=3

(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)

5. (a) Write a program to create a class Complex which


has two data members: real part a (integer) and
6. (a) Write a C+t program to open a text file and to
imaginary part b (float). Write the following display the total number of characters it contains.
member functions for this class: (5)
(5)
P.T.0.
1002 11
1002 10

(b) Give output of the following C++ program. (5)


(c) What is an exception? Discuss in brief the
exception handling mechanism in C++. (S)
#include <iostream>
using namespace std;
class Base{ (a) Write a C++ function to perform linear search in
public: 7.
void display ( )( an array. Also rewrite this function using
cout<< "\n Display base "; (5)
templates.
virtual void show ( ){
cout<< "\n Show base";
(b) Write the sequence of constructors and destructors
being called in the following inheritance: (5)
class Derived: public Base
public:
void display ( ) class A{...):
cout<<"\n Display derived" ; class B: public A{...}:
void show ( ){
cout<< "\n show derived" ; class c{...};
class D,: public c{...}:
int main( )(
class E: public D, public B{...};
Base B;
Derived D; E obj;
Base *bptr;
bptr = &B; (c) Consider the following C++ program and write
bptr->display O: the final output. (5)
bptr->show ( ):
bptr = &D; #include <iostream>
bptr->display()
bptr->show ( ):
using namespace std;
int main ()
return 0; { int arr (] = (10,20, 30,40,50);
int *ptr;
ptr arr;

P.T.0.
1002 12

cout<<" \nValue at ptr: "<< *ptr<<endl;


ptr-ptr+3;
cout<<" \nValue at ptr+3 "<< *ptr<<endl;
ptrt+:
cout<<"\nValue at ptrt+ "<< *ptr<<endl;
cout<<"\nValue at ptr-- " << * (ptr--)<Kendl;
return 0;

(500)

You might also like