0% found this document useful (0 votes)
62 views16 pages

CPP QN 2019

This 3 sentence summary provides the essential information about the document: The document is a 16 page question paper for the course "Programming Fundamentals using C++" containing 7 questions in two sections - Section A with 1 compulsory question and Section B with 4 questions to attempt. The questions cover topics like arrays, classes, functions, operator overloading and file handling in C++ and require writing code segments, identifying errors, determining output, and more. Students are provided instructions on writing their roll number and attempting the required number of questions within the 3 hour duration.

Uploaded by

kanishk vohra
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)
62 views16 pages

CPP QN 2019

This 3 sentence summary provides the essential information about the document: The document is a 16 page question paper for the course "Programming Fundamentals using C++" containing 7 questions in two sections - Section A with 1 compulsory question and Section B with 4 questions to attempt. The questions cover topics like arrays, classes, functions, operator overloading and file handling in C++ and require writing code segments, identifying errors, determining output, and more. Students are provided instructions on writing their roll number and attempting the required number of questions within the 3 hour duration.

Uploaded by

kanishk vohra
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/ 16

[This question paper contains 16 printed pages.

Your Roll NolI9252t0I0


Sr. No. of Question Paper: 8591

Unique Paper Code 32341101

Name of the Paper Programming Fundamentals


using C++

Name of the Course B.Sc. (H) Computer Science

Semester :I

Duration: 3 Hours Maximum Marks: 75

Instructions for Candidates

1. Write your Roll No. on the top immediately on receipt


of this question paper.

2. Question 1 is compulsory in Section A.

3.
3 Attempt any four questions from Section B.

4. Parts of a question should be attempted together.

SECTION A

1. (a) Consider the following declaration statements

float f;
int *b &f

P.T.O.
8591

Identify the error and write the code to correct


it. (2)

(b) Assuming that the required header files have been


included where required, what will be the output
produced on execution of the following code
segments:

(i) double z1;


double Y 56.7
int X 34
if (x)

zl = Y+t

cout<<zl<< \n"<<y

else

z1 y+x/2;
cout<<z1<<y;
(2)

(i) int x 4, Y = 3;

for (int i =1;i<=x; i++)

for (int i Y; j>=1:j-)


cout < (i*j)
cout<<"\n"
(4)
8591 3
(iii) int V
int k 10
V =(1508k ?k+5 ++k) ;
cout<<"y=" <<v <<"k=" <<k;

(2)

iv) int i
int b[]={101, 120, 130,-340, -112,
-114};
for
for (i = 0: b[i]>0; i++)

cout <<i; (2)

(v) int i =
890
double x = 4.678

cout<<setw ( 5) <<i<<"\n" ;

cout<fixed;

cout<<setprecision (6)
cout <"x="<<x<<" \n";
cout<<oct<<"Octal="<<i; (4)

(vi) string s ( T h e basic program

of C plus plus");
int j
int k = 0;

int count=0
S.find ( 'u' , k);

P.T.O.
8591 4

while (j!=-1)

Count++;
j s.find( "u',j+1);

Cout<<count; (4)
(vii) class Base

publiC:
Base ()

coute"Inside Base \n";

class Derivedl : public Base

public:
Derived1 ()

cout<<"Inside Derivedl\n";
8591
class Derived2 public Derived1

publiC
Derived2 ()

cout <"Inside Derived 2\n";

void main ())

Base o1
Derivedl o2
Derived2 o3;
(3)

that the required header files have been


(c) Assuming
Find out the error in the
included where required,
following code fragments

) void f(int *p)

int a

*p a
a *at1
return ai
(3)

P.T.O.
8591 6
(i) void try(int a,int b)

if (a<0) throwS "Negative


number";

(1)
(d) Write a function to remove duplicate element from
one dimensional integer array A of size n. (5)

(e) Rewrite the following while statement as an


equivalent for statement:

int x =

0
while (x<10)

cout <x<<endl;
x++

(3)

SECTION B

2. (a) Write a program to count the number of vowels in


a
string entered as command line argument.
(3)
8591 1

(b) Consider four integer variables that has been


initialized as: y = 5,z = 0 andt = -4. What

is the value of cach of the following expressions


on evaluation (consider each part independent of
other)?

)t I z <(y+5) && Y

ii) 3*y/4856&y

(ii) ! (4+5*y>=z-4) && (z-2) (3)

C++ function that takes an array of


(c) Write a
characters to
characters to convert all lowercase
built-in functions) and
(without using
uppercase
return type is void. (4)

execution of
What will be the output produced on
3. (a)
the following code segment:

#include<iostream>

using namespace std

void main()

int i
int j = 11;

int m 6
i 1;i<=m i++)
for (int =

P.T.O.
8591 8

{
for (int t 1; t<=j; t++)
cout<<t;
j j-2
cout<" \n";

(5)

(b) Write a function UpperTriangular () that


accept a matrix A of order n*n as an input
argument as well as its order. The function should
convert matrix A to
uppertriangular matrix by
assigning 0 to all elements below principal
diagonal(diagonal left to right from top) (5)

4. (a) Consider the following class :

class Rationalnumber

int P,q

The above class is designed


define a rational
to
number with numerator p and denominator q. For
the above class write the definitions of the

following member functions:


8591 9
(i) Parameterized constructor
(i) Overload + operator to add two rational
numbers

(ii) Display function

Write the suitable statements to create


three
rational numbers rl, r2 & r3 having 5/7, 6/7 and
8/7. Use operator
overloading to store the sum of
two objects in third object r3. Use the display
function to print the content of object rl, r2 and
r3
(6)
(6) Write a program that reads a file and print the
number of lines in it. (4)

5. (a) What will be the output produced on execution of


the following code segment

#include<iostream>
using namespace std;
void main ()

int arr[]={12, 34, 56,89);


int temp;
int size = 4;

f o r (int i = 0,j = size-1;i<j; i+t,j-)

P.T.O
8591 10

temp arr [il1:


arr [i] =
arr [jl:
arr [j] temp;

for (int i = 0:i<size; i++)

cout<<arr [i]<<" \n";


(4)

(b) Consider a following class

class X

int il;

publicc:
x()

il =
15

virtual void display ()

cout<<"il="<<il<<endl;

class Y public X

int j1
8591 11

public
Y()

j1 10;

class Z:public Y

int k1;
publiC:

k1 20;

Replace ellipses ... by appropriate C++ code to


override method display () in class Y and 2.
Use Runtime polymorphism to display the content
of objects of class X, Y and Z. (6)

6. (a) Consider the following declarations:


string s1 = Hello World";

string s2 = Program in C++";

P.T.O.
8591 12
Write code fragments for the following:

(i) To compare the first four characters of


s1 with the last two characters of s2

(ii) To cxtract the last six characters of s2


(5)

(b) Write the output on execution of the following


code:

#include<iostream>
using namespace std;
class myexception

string str;

public

myexception (string p)

str=p;

void display ()

cout <str;
8591
13

void main ()

int n, m;

try

5;
-6
if (n<0)
throw myexception ( "Negative
number") ;
cout<<n<<endl;

if (m0)

throw myexception ("Negative


number");
cout<<m;

catch (myexception o1)

o1.display ();

(5)

P.T.O.
8591 14
7.
1. (a) Identify in the
an error
following code and give
reasons for the same

) #include <iostream>
using namespace std;
class US1

int P
protected:

int q
public
int ;

class US2 public US1

protected:

float S,u;

void main()

US1 o1;
US2 02;

cout<<ol.p;

anmmYAE
15
8591
cout<<ol.qi

cout<Kol.r;

cout<<o2.p;

cout<<o2.q;
cout<<o2.r;

cout<<o2.s;

cout<<o2.u;

(3)

(ii) do

int ctr=0;

cout<<ctr;
ctrt+

while (ctr!=10); (2)


(il) void f( int n)

if (n==0) return 1

(1)
(b) Write C++ declarations for the
following:
(2+2)

P.T.O.
8591 16

() A function that accepts an array of

integers, a character variable and


returning a pointer to an integer.

(1i) print integer x with field width as 10 and


fill character as .

(1300)

You might also like