tt97 t6 [This question paper contains l6 printed pages.
(c) Write a function UpperTriangle0 thar accepts a Your Roll N o..,......... ...
square matrix A and its order n as input arguments.
The function should convert matrix A to an Sr. No. of Question Paper : 1 197 F
upper triangular matrix by assigning 0 to all Unique Paper Code 2312011201
elements below the diagonal (diagonal left to right
Namc of the Paper Object-Oriented Programming
from top). (5)
with c++ (DSC04)
Name of the Course B.Sc. (H) Computer Science
Semester II C'ol i(];l
6
., Duration : 3 Hours imum Marks : 9
u
t
Instructions for Candidates '!
t Write your Roll No. on the top
of this question paper.
2. Section A is compulsory (Question l).
3. Attempt any 4 questions from Section B (Questions
2 to 6).
Section A
(Compulsory Question)
(a) What are inline functions? Rewrite the following
code using the inline function. (3)
(1000) P.T.O.
tt97 .2 tt97 l5
#include<iostream> 5 (a) Write a program to define a class, Complex, with
the following features: ( l0)
using namespace std;
float mul (int x, int y) (i) data members hidden from outside the
class
{
return (x*y); (ii) a default and parametrised constructor
) (iii) a member function to add another complex
int main0 number to it maino function to show the
implementation of the class
{
inta:2,b=5; (b) Write a function that compares the two given
cout << mul(a, b) << "\n'' arrays arrl and arr2 of the same size (passed
return 0; as parameters) for equality, and returns true or
false. (5)
I
(b) what will be the output of the following program : 6 (a) What is a pure virtual function? Define an abstract
class Polygon, with a data member area that stores
(i) #include<iostream> (3)
the area of the Polygon, and a pure virtual l'unction
using namesPace std; that calculates the area of the Polygon. Inherit a
class construct Rectangle class from the Polygon. Complete the
program to show the use of the abstract class and
{
polymorphism. (10)
int p, q;
P.T.O
tt97 t4 Lt97 3
l.
Jt public:
int mainQ construct(int x, int y)
t t
basel + ptr; p : x;
der x; q=v;
ptr : &x;
ptr->print( ); void DisplayO
ptr->show0; {
I cout<<p<<"\n"<<q<<"\n";
)
(a) Write a program to print the following output: l.
(6)
int mainQ
I {
12
construct iteml(10, 20), item2 =
123
1234 construct(30,40);
12345 iteml.DisplayO;
item2.Display0;
(b) Write a program to print the area of a square and return 0;
circle using function overloading. (9) )
P. T. O.
t197 4 tt97 13
(ii) #include<iostream> (3) cout<<"print version of base class"<<endl;
using namespace std; )
void square(int* snum) void show0
{
{
of 10 is "; cout<<" Show version ofbase class"<<endl;
cout<<"Square
*snum *= tsnum; )
)
class der: public basel
int mainO
{
{
public:
int num = 10;
void print0
square (&num);
cout << num << endl; {
cout << "print version of derived class " <<
)
endl;
(iii) #include<iostream> (3)
)
using namesPace std; void showQ
void Myclass0 {
{ cout << "Slrow version of derived class" <<
try endl;
{ j
throw "Y";
P.T.O
It97 t2 tt97 5
3 (a) Create a class ThreeDim which contains x, y and )
z coordinates as integers. Define the following for catch (const char*)
the class :
{
(i) default constructor to initialize data cout<<"Exception inside MyclassVr";
members to zero throw;
)
(ii) parametrized constructor to initialize data
members to values passed )
int main0
(iii) function out0 to display the coordinates of
{
the class. (9)
cout<<"Now main starts\n";
(b) What will be the change in the output try
if a virtual
keyword is removed from the print O function of {
the class basel? Write the output for the following Myclass0;
code with the virtual keyword and without it.
)
(6)
catch (const char'*)
#include<iostream.h>
{
using namespace std; cout<<"Exception inside main\n" ;
class basel )
{ public: cout<<"Now main ends\n ".
virtual void printo return 0;
)
{
P.T.O.
tt97 6 tt97 tl
(c) Write a program that takes a character from the #include<iostream>
keyboard and displays its corresponding ASCII using namcspace std;
value on the screen. (3)
int func(int a, int* b, int& c)
(d) How do the properties of the following two derived {
classesAandBdiffer? inttemp:a+tb+c;
(i) class A: private C\11..-|; a += I0;
*g 1: 20;
(ii) class B: public CUl...l: (3 )
c += 30;
(e) Write a function to swap two numbers using return temp;
pointer datatype parameters. (3).
)
(l) Identify the error(s) in the following program int main0
(3) {
(i) #include<iostream>
int x - 1, y = 2, z = 3;
using namesPace std;
cout << x (( ", " (( y.. ", " << z << "\n";
class four seater
cout << func(x, &Y, z);
cout << "\n' << x << ", " << Y << ", " << zl
public:
return 0;
void ProPertY0
I
{
P.T.O.
1197 10 tt97 7
SECTION B cout<<rrlt has space for four
persons"<<end 1;
2_ (a) Write a program that reads a text file and creates )
an output file, named "out. dat". The output file is l.
identical to the text file except that every sequence
class four_wheeler
of consecutive blank spaces is replaced by a single
{
space. (5)
public:
(b) What is the sequence of constructors and void Property0
destructors being called in the tbllowing multilevel
{
inheritance : (5)
cout<<"It runs on four tyres'<<endl;
class X
)
class Car: public four_seater, public four_wheeler
class Y: public X;
, l.
int main 0
class Z: public Y; {
I Car Cl;
CI . four_seater;
(c) Write the output of the following code. Also,
C2. four_wheeler;
mention the call by value and call by reference
return 0;
parameters in the following code. (5)
)
P.T.O.
tt97 8 tt97 9
(ii) #include<iostream> (3 ) void main0
using namespace std;
Template<class Tl, class T2> Person <int, float> obj l(1, 2.34);
class Person Person <float, char> obj2(2.13,'r');
{
Tl m_tl;
T2 m_t2; (iii) # include <iostream> (3 )
#include <fstream>
public:
using namespace std;
Person (Tl tl, TZ t2)
int main0
{ {
m_tl=tl; const int size : 100;
m_t2=t2; char buffer[size];
cout<<m t1<<" "<<m t2<<endl; ifstream in ("pl.cpp");
ofstream out("p2.cpp");
)
while(in. get(bu ffer))
Person (T3 t2, T4 tl)
{
{ in.get0;
m_t2=t2; cout<<buffer<<end I ;
m_t1=tl; cout<<buffer<<end I ;
cout<<m t1<<" "<<m t2<<endl; )
in.close0;
out.close0;
)
P.T.O.