DOC-20250108-WA0005.
DOC-20250108-WA0005.
DOC-20250108-WA0005.
l(L~
Your Roll N 0 .
Semester I
1. Write your Roll No. on the top immediately on receipt of this question paper.
2. Section A is compulsory.
3. Attempt any four questions from Section B Parts of a question must be answered
together.
Section A
1. (a) Differentiate between while and do .. while loop giving suitable example for
each. (3)
(b) Assume the memory address of variable a is 400 and an integer variable is
of size 4 bytes. Write the output that will be produced on the execution of
the following code segment: (3)
int a= 7;
int *c = &a;
cout<<c<<endl;
cout<<c+l<<"\t"<<c+2<<"\t"<<endl;
PTO.
906 2
(c) Write the output that will be produced on the execution of the following
code segment: (3)
int main()
{
cout << sum(lO, 15)<<endl;
cout << sum(lO, 15, 25) <<endl;
cout << sum(lO, 15, 25, 30)<<endl;
return O;
(d) What is void pointer? What is the use of having void pointers? (3)
(f) List the different visibility modes used for declaring data members and member
functions in a class? (3)
(h) Write the output of the following code segment assuming address of x is
2000 and address of p is 3000: (3)
int X = 2;
int *p;
P = &x;
cout << *p;
*p = 4;
cout << p;
cout << *(&x);
906 3
(i) Differentiate between call by value and call by reference. (3)
(j) For the following statements state whether they are true or false: (3)
Section B
2. (a) What are the different types of inheritance? Give suitable diagrams depicting
each. (5)
(ii) If the input arguments are integers the function returns their sum. Else,
if the arguments are strings it returns a string formed by concatenating
the two input strings. (5)
(c) State whether the following statements are true or false: (5)
PTO.
906
4
(iv) Class members are public by default.
3. (a) Identify the error in the following program. Write the corrected code. (5)
#include <iostream>
Using namespace std;
class Room
{
int width, height;
public:
void setValue(int w, int h)
{
width= w;
height= h;
int main ()
{
Room objRoom;
objRoom.width = 12;
objRoom.height = 15;
4. (a) Write the output produced on the execution of the following C++ statements:
(5)
i)cout<<(30!=25)?10:20;
ii)cout<<55%9;
iii) cout<< (56<=100) I I ( 10>20&&5>=5);
iv) cout<<8+9*21-10/5;
v) x=5; y=x++;
cout<<0==0?x:y;
906
5
(b) Write a C++ code to display the following pattern on the screen taking
number of lines as input from the user. (5)
BA
CBA
DCBA
Give syntax of each of the above methods. Name the input stream and
output stream used with files in C++.
(5)
Data members
2. accountNumber
3. typeOfAccount
4. balanceAmount
PTO.
6
906
Member functions
(b) What are the different types of errors? List the different types of exceptions
in C++. (5)
(c) Write a program to store n numbers in an array. Display the largest number
in the array. (Taken as input from user). (5)
6. (a) Write the output that will be produced on the execution of the following
code segment: (5)
void main ()
{
int num[ 1={80,55,20,35,99};
int *ptr;
ptr = num;
cout <<"\nValue of ptr: "<<*ptr << "\n";
ptr++; "<<*ptr << "\n";
cout<<"\nValue of ptr++
ptr--;
cout<<"\nValue of ptr-- "<<*ptr << "\n";
ptr+=3;
cout<<"\nValue of ptr+3: "<<*ptr << "\n";
ptr=ptr-1;
cout <<"\nValue of ptr-1: "<<*ptr << "\n";
}
906 7
class One
{
public:
static int x;
};
class A { ... } ;
class B: public A{ ... };
class C: public B { ... } ;
class D: public B, public A{ ... };
7. (a) Write a program to write the following statements in the file" Filel": (5)
(b) Write the output that will be produced on the execution of the following
code segment: (5)
i)
for (int i=l; i<4; i++)
{
for (int j=l; j<=i; j++)
cout << j <<" ";
cout << "\n";
P.TO.
906 8
ii)
void increment( )
{
static inti ;
cout<< i <<endl;
i = i + 1 ;
int main( )
{
increment( ) ;
increment( ) ;
increment( ) ;
}
(c) Write a program to print the sum of the following series: (5)
(1000)