0% found this document useful (0 votes)
2 views6 pages

QP CPP 2

Uploaded by

parsole03
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)
2 views6 pages

QP CPP 2

Uploaded by

parsole03
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

.

De 2b18

[This question paper contains 10 printed pages.]

Your Roll No......

Sr. No. of Question Paper : 46

Unique Paper Code 32341101

Name of the Paper Programming Fundamentals using


C++

Name of the Course :[Link]. (H) Computer Science


Semester :I

Duration: 3 Hours Maximum Marks : 75

Instructionsfor Candidates
. Write your Roll No. on the top immediately on receipt of
this question paper.
2. The question paper consists of two Sections. Section A is
compulsory.
3 Attempt any four questions from Section B.

Section A

a) Write a single C++ statement to calculate following (assuming variables 2


a, band care already declared as integers):

Va2+b2
C
4a

b Consider three integer variables initialized as: x=1, y=0, and z=1
What are the values of x, y, and z after executing the following code
segment?

P.T.O.
46 2
46
if(x>y&&x2) class Base
(v)
public:
2=X*1; void print ()
else if(x+y>=z) Base Class";
cout<<"\n P r i n t

Xt+ void show()


=
0;
virtual
2=x*1;
else y=z+*; Base
Derived : public
class

c)Given the following declarations: public:


int num=10; 2 void print()
int val=&num; out<<"\nPrint Derived Class";

What will be
printed on execution of
each part
independent of other)? following statements
) cout<<*val;
(consider
void show()
(i) cout<(*val+1) *2; Class";
cout<"\n Show Derived
d) Find output of each of the
following code segments
) String 2X4
s1="Hello", s2="Beautiful world I!! ";
String s3="Be Happy" void main( )
String s=s1+" "+s2+""+s3 {
[Link] (5, '! ') Base *Bptr;
cout<<s<<endl; Derived D;
cout&<[Link]('"Be") ; Bptr = &D;

Bptr->print( );
(i) void main() Bptr->show( );

int val=1;
do of the following code segments
Find error(s) (if any) in each

val++; int func1 (int *aa, int &bb)


(i)
++val;
while(val++>25) ;
coutc<val;
&bb-8
aaf0]=bb;

ii)int x=0,y=0, 2=1;


(i) class Fun

if(z<x|ly>=z&&z==1)
if(z&&y) private: int x;
y 1; protected: int y;
else public: int z
x=1;
cout<<x<<" "<<y<<" "<<z;
P.T.C
46
46
4
class Funny : public Fun prototype:
{ replace with the following
function named
Write a
private: int u; h) String replace(String s t r 1 ) ;
protected: int v;
public: int wi the lower
substituting all
returns à new string obtained by s t r 1 passed to
it as a
The function letters in the string
void main() c a s e letters by
uppercase "Hello
World! !!"
[Link] example, "HELLO for the input string WORLD!!!"
Fun fun; output
Funny funny; Thefunction should of the following
of first n tenms
fun.z 2 Write a function
that returns the sum

funny.y =12; i)
funny .u= 5; series
funny. Z=l0;
What is a copy
the help of an
constructor? llustrate the use of copy declaration:
) Give one wordexample.
answer
constructor with
1+2
Given the following
float num = 576.21f
for the
following: c o u t statement?
) In the executing the following
following declaration for the class
4
What will be printed on

Test, indicate scope


of the is"<<setw(8)
variable x (private, coute<"The t a x
public or
protected). < < setprecis ion(
6)<<num;

class Test Section BB


int x;
switch statement:
(ii) Consider the Rewrite the following code segment using a
2 a)
following code segment:
'a')
if(ch='A'||ch
==

class base
countA++
public elseif(ch=='B'||ch=='b')
int x; countB+*
int yi elseif(ch=='C'||ch=='c')
countc+*;
class
derived: else
private base cout<<"Error-Not A, B, or C \n" ;

Indicate access integer variables to be initialized as: x=4, y=7


and
class. scope of variables b) Consider three
each of
x and y in the z=-4. What are the values of x,y and z after evaluation of
(ii) Which derived the following expressions (consider each part
independent of other)?
type of class
member function
ofavariable(s)
class?
can be
accessed by a static ( ) x++ + Y- Z--

(iv) What do we (i) ++x + 2


call a class (iii)x-1 + y+++++z
member function? that has at
least one iv)++z + ++y+X-
pure virtual

P.T.
46
6
6
c Assume that you are code segment:

factorial of any numberprovided to function named fact to find the in the following
a
Find error(s)
(passed it as a parameter) with the 4 b)
prototype: following class X
nt
fact(int num) ;
private:
Using this fact function, write int i,J
n even numbers.
a
program to print the factorial of first
virtual
i
x() 1 ; j=1;}
void show()=0;

3 a) Find output of the


following code segment: public:
void p r i n t ( )

void main() cout<<i<<" "<<j;


{
int i , j
for(i=l0; i>=0; i--) X
{ class Y: public
cout<<" \n "
for (j=i; j>=0; j--) int k;
publi:
void print()
coutej;
if(j==5 ) break; coute<k;

b) Assuming you are given with two 2-Dimensional i=j=k=2;}


Baxp Write program matrices An and
segments to perform the following matrix 3+3
operations:

(i) AxB
(Multiplication of two
ain()
void main ()
Y WW
Gi) A
(Transpose of the squarematrices)
matrix)
.print();

Test. txt and prints the


that reads a text file, say,
4 a) Write a program
Find output of the vowels in it.
following code segment: total number of

void main() following:


Find output of the
a)

int arrt]={1, 2, 3,
int *ptr1, *ptr2; 4, 5, 6, 7, 8, 9};
class polygon

ptrl=arI; protected:
ptr2=ptrl+2; int width, height;
cout<<ptr2-ptrl; public:
set_values(int a, int b)
void

width=a; height=b;

class output1
P.T
46 8 46 9
6
Account and Employee having
public: C) Declare the classes Person, Create the required
inheritance hierarchy shown in the figure below.
void output(int i); the following
runtime polymorphism for
objects to demonstrate
operations
void outputl: :output(
int i) (i) Accept the information of an employee.
of an employee.
Gi) Display information
cout<<i<<endl;
PeTsona
Name
Code
class rectangle : public polygon, public outpu
t1

AC ount
PaY_
public:
int area()

Enmployee
return(width * height);
statements:

each of the following


Rectify the error (if any) in
6 a)
class
triangle: public polygon,public output (i) cout>>put(c);
1
(i)cin<<get(c);
ii)[Link](c)
public: (iv)[Link] (c);
int area()
2
with the following prototype:
Define a function mysqr
b)
return (width*height/2); int mysqr(int n);
function.
a number using this
the square of and
to compute for validity
Write a program must be tested
void main() n given to
this function must be
The input value
should raise an
exception that
this program
if found negative,
rectangle rect caught.
triangle trgl; declarations/definitions
for the following
rect.set_values (4, 5) a) Write C++
reference to a floating point
trgl.set_values (4, 5) func1 accepting a returns a pointer to
(i) A function integers. It
[Link] ([Link]())E number, a string and
an array of
[Link] ([Link]()); a character A of size 3 rows and 4 columns

dimensional integer aray


two
(11) A
zero.
initialized to
elements
with each of its of a class
Test to 100.
three
memberx
static Testl having
111)lnitialize a class
constructor
for a
default argument.
parameterized y is a
b) Name the header files for the following operations: (iv)A yand z, where,
arguments x,
integer

) Console input and output.


(i) Using formatting functions like setw()

P.T
10
46

of data members longitude


Create a class Location consisting 2+4
b) the following member functions for this class:
and latitude. Write

to initialize the data members.


(i) A parameterized constructor
+ to add two Location
(ii) A function for overl oading operator
objects

(1400)

You might also like