0% found this document useful (0 votes)
31 views8 pages

C+ Paper 24

Uploaded by

syalkamya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views8 pages

C+ Paper 24

Uploaded by

syalkamya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

[This question paper contains 8printed pages.

]
Your Roll No...

G
Sr. No. of Question Paper : 906

2342571101
Unique Paper Code
Name of the Paper Programming Fundamentals Using C++

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

Semester
Maximum Marks :90
Duration:3 Hours

Instruetions 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+1<<"\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 = 0, int w= 0)

return (x + y+ z + w);

int main()

cout << sum (10, 15)<<endl;


cout << sum (10, 15, 25) <<endl;
cout << sum (10, 15, 25, 30) <Kendl;
return 0;

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

() 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) ifstream. infile (" DATA"):


ii) cin>>a,b;
ii) 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)i
906 3

(i) Differentiate between call by value and call by reference. (3)

(i) For the following stalements state whether they are true or false: (3)

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

(ii) Contructors can have default arguments.

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

() Accepts two arguments as input

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

(iü) Inheritance aids in data hiding.

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

PT.O.
906

(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 = Wi
height = h;

int main ()

Room obj Room;


obj Room. width = 12;
objRoom. height = 15;

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


situations would an inline 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<<5589;
ii) cout<<(56<=100) ||( 10>20&&5>=5) ;
iv) cout<<8+9*21-10/5;
v) x=5; y=xtti
cout<<0==0?x:y ;
5
906
screen taking
display the following pattern on the
(b) Write a C++ code to (5)
number of lines as input from the user.

BA

CBA

DCBA

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

() constructor function

(ü) file object

methods. Name the input stream and


Give syntax of cach of the above
C++.
output stream used with files in

Include the following members:


(a) Define a class bankAccount.
(5)

Data members

1. name of the depositor

2. accountNumber

3. typeOfAccount

4. balanceAmount

PI.0.
906 6

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 ma in ()
and call the above
mentioned member functions.

(b) What are the different types of errors? List


in C++, the different types of exceptions
(5)
(C) Write a program to store n numbers in an array. Display the largest number
in the array. (Take n as input from user).
(5)

6 (a) Write the output that will be produced on the


code segment: execution of the following
(5)

void mna in ()
int num[ ]={80,55,20,35,99)}
int *ptr;
ptr = num;
cout <<"\nValue of ptr :
ptr++; "<<*ptr << "\n";
cout<<"\nValue of ptrt+
ptr--: :
"<<*ptr << "\n";
cout<<"\nValue of ptr--: "<<*ptr <« "\n";
ptr+=3;
cout<<"\nValue of ptr+3: "<<*ptr << "\n";
ptr=ptr-1;
cout <<\nValue of ptr-l: "<<*ptr << "\n";
906 7
A 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{..:

Filel":
7. (a) Write a program to write the following statements in the file" (5)

"Together we may learn.


luminous.
"May our learning be bright and

Print the contents of "Filel".

following
(b) Write the output that will be produced on the execution of the
(5)
code segment:

i)
for (int i-l; i<4; i++)

for (int j=l; j<=i; j++)


Cout << i << " ";
Cout << "\n";

P.T.0.
906 8

ii)
void increment ( )

static int i
cout<< i <<endl;
i = i + 1

int main( )
{
increment ( );
increment ( );
increment ( );

(c) Write a program to print the sum of the following series:


(5)
1+1/2+ 1I/3+1/4+ .. +l/n"
Take n as input from the user.

You might also like