DOC-20250108-WA0005.

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

03,0,. 2.1)2..

l(L~
Your Roll N 0 .

Sr. aper 906 G


2342571101

Name of the Paper Programming Fundamentals Using C++

Name of the Course B. A. (Prog) & BSc (Non-Major)

Semester 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. 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 sum(int x, int y, int z = O, int w = 0)


{
return (x + y + z + w);

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)

(e) Which header file is required to implement file input/output operations in


C++? Mention the two ways of opening a file in C++? (3)

(f) List the different visibility modes used for declaring data members and member
functions in a class? (3)

(g) Find errors, if any, in the following C++ statements: (3)

i) if stream. infile ("DATA");


ii) cin>>a, b;
iii)int mul(int a,b);

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

(i) Constructors can be declared as private members of the class.

(ii) Contructors can have default arguments.

(iii) Contructors can be used to return values from the function.

Section B

2. (a) What are the different types of inheritance? Give suitable diagrams depicting
each. (5)

(b) Write an overloaded function add () that does the following:

(i) Accepts two arguments as input

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

(i) A function declared as private in a class is accessible only


to member functions of that class.

(ii) Inheritance aids in data hiding.

(iii) Virtual functions are used to create pointers to base classes.

PTO.
906
4
(iv) Class members are public by default.

(v) Static data members of a class can be initialized using an object of


the class.

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;

(b) Write an inline function for calculating volume of a cube. In which


situations would an inl ine function not work? (5)

(c) Write a program to swap two values using function template. ( 5)

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

(c) What is the difference between opening a file using


(5)

(i) constructor function

(ii) file object

Give syntax of each of the above methods. Name the input stream and
output stream used with files in C++.

5. (a) Define a class bankAccount. Include the following members:

(5)

Data members

1. name of the depositor

2. accountNumber

3. typeOfAccount

4. balanceAmount

PTO.
6
906
Member functions

1. Constructor to assign initial values to data members

2. deposit () to modify balanceAmount

3. display () to print name and balance

Create an object of bankAccount in main () and call the above


mentioned 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

(b) Consider the following class definition. (5)

class One
{
public:
static int x;
};

Create an object of class One. Assign a value to variable x and display


its value in main () function.

(c) Name the type of inheritance for class B, class B, class C,


class Din the following code segment: (5)

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)

"Together we may learn."


"May our learning be bright and luminous."

Print the contents of "Filel".

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

l+t/22+ 1/33+1/44+ ... +tin"


Take n as input from the user.

(1000)

You might also like