Sei sulla pagina 1di 10

Examination Papers, 1998

[Delhi]

Maximum Marks : 70
Note.

Duration : 3 Hours

All the questions are compulsory.


Programming Language : C++

1. (a) Define the following terms : (i) Inheritance (ii) Encapsulation


(b) Name the header files, to which following built-in functions belong to :
(i) cos()
(ii) setw()
(iii) toupper()
(iv) strcpy()
(c) Find the syntax error(s), if any, in the following program :
include<iostream.h>
void main()
{
int R; W = 90;
while W > 60
{
R = W-50;
Switch (W)
{
20:cout << Lower Range" << endl;
30:cout << Middle Range" << endl;
40:cout << Higher Range" << endl;
}
}
}

2
2
2

(d) What is the output of the following program :

(e) Write the output of the following program :

char *Name = "IntRAneT";


for (int x = 0; x < strlen(Name); x++)
if (islower(Name[x]))
Name[x] = toupper(Name[x]);
else
if (isupper(Name[x]))
if (x % 2 == 0)
Name[x] = tolower(Name[x]);
else
Name[x] = Name[x-1];
puts(Name);
#include<iostream.h>
void Execute(int &X, int Y = 200)
{
int TEMP =X+Y;
X += TEMP;
if(Y != 200)
cout << TEMP << X << Y << endl;
}
void main ( )
{
int A = 50, B = 20;
Execute(B);

Examination Paper

cout << A << B << endl;


Execute(A, B);
cout << A << B << endl;
}

(f) Write a C ++ function having two value parameters X and Y with result type float to find the sum of
series given below.
4
1+ X1/2! + X2/3! + ..+ XN/(N+1)!
Ans. (a) (i) Inheritance : It is an ability to derive a new class in terms of an existing class. The existing class
is known as a base class and the new class is known as derived class.
(ii) Encapsulation : It means wrapping up of data and functions which operate on the data into a
single unit called the object (or class).
(b) (i) math.h
(ii) iomanip.h
(iii) ctype.h
(iv) string.h
(c) The correct program is :
# include<iostream.h>
// Correction 1
void main()
{
int R,W=90;
// Correction 2
while (W>60)
// Correction 3
{
R=W-50;
switch (W)
{
case 20:cout<<"Lower Range"<<endl; // Correction 4
case 30:cout<<"Middle Range"<<endl; // Correction 5
case 40:cout<<"Higher Range"<<endl; // Correction 6
}
}
}

// Correction 1 : Declaration syntax error # missing before include


// Correction 2 : Undefined symbol W. So put comma (,) before W at ;
// Correction 3 : While statement missing (
// Correction 4 : Unreachable code case missing and double quote missing
// Correction 5 : Same as correction 4
// Correction 6 : Same as correction 4
(d) The output is : iNTTaNEE
(e) The output is as :
50 240
290 340 240
340 240
(f) // Function to find the sum of series of float type
float sum_series(float X, float N)
{
float sum = 1.0, temp = 1.0;
for (int i = 2; i <= N+1; i++)
{
temp = temp * (X/i);
sum += temp;
}
return sum;
}

// Initialize the series first value 1


// Starting series value is 2
// (4/2!) and so on

2. (a) What is copy constructor ? What do you understand by constructor overloading ?

2 Together with Computer Science (C++) XII

(b) Define a class student with the following specifications :


4
private members of class student
admno
integer
sname
20 characters
eng, math, science
float
total
float
ctotal()
A function to calculate eng + math + science with float return type public
member function of class student
Takedata()
function to accept values for admno, sname, eng, math, science and invoke
ctotal() to calculate total.
Showdata()
function to display all the data members on the screen.
(c) Consider the following declarations and answer the questions given below :
class PPP
{
int H;
protected :
int S;
public :
void INPUT(int);
void OUT();
};
class QQQ : private PPP
{
int T;
protected :
int U;
public :
void INDATA(int, int)
void OUTDATA();
};
class RRR : public QQQ
{
int M;
public :
void DISP (void);
};

(i) Name the base class and derived class of the class QQQ.
(ii) Name the data member(s) that can be accessed from function DISP() .
(iii) Name the member function(s), which can be accessed from the objects of class RRR.
(iv) Is the member function OUT() accessible by the objects of the class QQQ ?
Ans. (a) A copy constructor is that constructor which is used to initialize one object with the values from
another object of same class during declaration. A constructor overloading is similar to function
overloading as it can also be overloaded for various combinations of parameter types. The only
difference is that the overloaded function can return a value while the overloaded constructor
cannot return a value.
(b) // Class and function declaration of the student data
class student
{
int admno;
char sname[20];
float eng, math, science;
float total;

Examination Paper

float ctotal()
{
return (eng + math + science);
}
public :
void Takedata()
{
cout << "Enter admission no : ";
cin >> admno;
cout << "Enter name : ";
cin >> sname;
cout << "Enter english mark : ";
cin >> eng;
cout << "Enter math mark : ";
cin >> math;
cout << "Enter science mark : ";
cin >> science;
total = ctotal();
}
void Showdata()
{
cout << "Admission no is : " << admno<<endl;
cout << "Name is : " << sname << endl;
cout << "English mark : " << eng<<endl;
cout << "Math mark : " << math<<endl;
cout << "Science mark : " << science << endl;
cout << "Total mark is : " << total<<endl;
}
};

(c)

3. (a)

(b)
(c)
(d)
(e)

(i) Base class : PPP


Derived class : RRR
(ii) M and U
(iii) DISP(), INDATA(int, int) and OUTDATA()
(iv) No
Suppose an array P containing float is arranged in ascending order. Write a user defined function in
C++ to search for one float from P with the help of binary search method. The function should return
an integer 0 to show absence of the number and integer 1 to show presence of the number in the
array. The function should have the parameters as (i) an array P (ii) the number DATA to be searched
(iii) number of elements N.
4
An array T[15][10] is stored in the memory with each element requiring 2 bytes of storage. If the base
address of T is 2000, determine the location of T[7][8] when the array T is stored by
3
(i) Row major (ii) Column major.
Write a user -defined function in C++ to display the sum of column elements of a two dimensional
array R[7][7] containing integers.
2
Evaluate the following postfix expression using a stack and show the contents of stack after execution
of each operation :
2
50, 40, +, 18, 14, , 4, *, +
Give the necessary declaration of a linked implemented stack containing integer type numbers; also
write a user defined function in C++ to pop a number from this stack.
4

Ans. (a) // This function search an element in an array using binary search.
int binary(float P[10], float data ,int n)
{

4 Together with Computer Science (C++) XII

int i, flag = 0, first = 0, last, pos = 1, mid;


last = n 1;
while ((first <= last) && (flag == 0))
{
mid = (first + last) / 2;
if (P[mid] == data)
{
pos = pos + mid;
flag = 1;
}
else
if (P[mid] < data)
first = mid + 1;
else
last = mid 1;
}
if (flag == 1)
return(1);
else
return(0);
}

(b) Let us assume that the Base index number is [0][0].


The Base Address of T = B = 2000,
No. of Rows = R = 15,
Number of Columns = C = 10,
Size of each element = W = 2,
And let the location of T[7][8] = L
(i) The given array T is stored as Row Major
Using the formula
L = B + W * [7 *C + 8]
= 2000 + 2 * [ 7 * 10 + 8]
= 2000 + 2 * 78
= 2000 + 156
= 2156
(ii) When the given array T is stored as Column Major
Using the formula
L = B + W * [7 + 8 * R]
= 2000 + 2 * [7 + 8 * 15]
= 2000 + 2 * 127
= 2000 + 254
= 2254
(c) // Function to find the sum of column elements of a two dimensional array
void calculate(int R[7][7])
{
int i, j, sum;
sum=0;
for(i=0; i<7; i++)
{
sum=0;
for(j=0; j<7; j++)
{
sum = sum + R[j][i];

Examination Paper

}
cout<<"\n\t sum of " <<(i+1)<<"column is "<<sum;

(d) The stack operation is :


Scanned elements

Operation

Stack

50
40
+

PUSH 50
PUSH 40
POP 40
POP 50
Calculate 50+40 = 90
PUSH 90
PUSH 18
PUSH 14
POP 14
POP 18
Calculate 1814 = 4
PUSH 4
PUSH 4
POP 4
POP 4
Calculate 4*4 = 16
PUSH 16
POP 16
POP 90
Calculate 90+16 = 106
PUSH 106

50
50, 40

18
14

4
*

Ans = 104
(e) // Declaration for linked stack

struct node
{
int data;
node *link;
};
// Function body for delete stack elements
node *pop(node *top,int &val)
{
node *temp;
clrscr();
if (top == NULL )
{
cout<<"Stack Empty ";
val = 1;
}
else
{
temp = top;
top = top->link;
val = temp->data;
temp->link = NULL;

6 Together with Computer Science (C++) XII

90
90, 18
90, 18, 14

90, 4
90, 4, 4

90, 16

106

delete temp;
}
return (top);
}

4. (a) Write name of two member functions belonging to fstream class.


(b) Assuming the class Employment given below, write functions in C++ to perform following :
(i) Write the objects of Employee to a binary file.
(ii) Read the objects of Employee from binary file and display them on screen.

2
4

class EMPLOYEE
{
int ENO;
char ENAME[10];
public :
void GETIT() {cin>>ENO;(ENAME);}
void SHOWIT(){cout<<ENO<<ENAME<<endl;}
};

Ans. (a) ifstream and ofstream.


(b) (i) // Function to write the object of class to the binary file

void create(EMPLOYEE emp)


{
ofstream afile;
afile.open("Emp.dat", ios::out | ios :: binary);
if (!afile)
{
cout << "\n Unable to open the file ";
exit(1);
}
afile.write((char *)&emp,sizeof(emp));
afile.close();
}
(ii) // Function to read the object of class from the binary file
void read_file()
{
ifstream afile;
afile.open("Emp.dat", ios::in | ios :: binary);
if (!afile)
{
cout << "\n File does not exist ";
exit(1);
}
EMPLOYEE emp;
while(afile)
{
afile.read((char *) &emp, sizeof(emp));
emp.SHOWIT();
}
afile.close();
}

5. (a) What is relation ? What is the difference between a tuple and an attribute ?
2
Write the SQL commands for (b) to (g) and write the outputs for (h) on the basis of the table
HOSPITAL:

Examination Paper

TABLE : HOSPITAL

(b)
(c)
(d)
(e)
(f)
(g)
(h)

Ans. (a)
(b)
(c)
(d)
(e)
(f)
(g)
(h)
6. (a)
(b)
(c)
(d)

No.

Name

Age

Department

Dateofadm

Charges

Sex

Arpit

62

Surgery

21/01/98

300

Zarina

22

ENT

12/12/97

250

Kareem

32

Orthopaedic

19/02/98

200

Arun

12

Surgery

11/01/98

300

Zubin

30

ENT

12/01/98

250

Ketaki

16

ENT

24/02/98

250

Ankita

29

Cardiology

20/02/98

800

Zareen

45

Gynaecology

22/02/98

300

Kush

19

Cardiology

13/01/98

800

10

Shilpa

23

Nuclear Medicine

21/02/98

400

To show all information about the patients of cardiology department.


1
To list the names of female patients who are in ENT department.
1
To list names of all patients with their date of admission in ascending order.
1
The display Patients Name, charges, age for female patients only.
1
To count the number of patients with age<30.
1
To insert a new row in the HOSPITAL table with the following data :
1
11, Aftab, 24, Surgery, {25/02/98}, 300, M
Give the output of the following SQL statements :
2
(i) Select COUNT (DISTINCT Charges) from HOSPITAL;
(ii) Select MIN (Age) from HOSPITAL where Sex = F;
(iii) Select SUM(Charges) from HOSPITAL where Department = ENT;
(iv) Select AVG (Charges) from HOSPITAL where Dateofadm < {12/02/98};
A relation is two-dimensional table.
Attribute : The column of the table is referred as attribute. This is also called the field of the table.
Tuple : A complete row is considered to be one record and also called a tuple.
SELECT * FROM HOSPITAL
WHERE department = Cardiology;
SELECT name FROM HOSPITAL WHERE department = ENT AND sex = F;
SELECT name FROM HOSPITAL
ORDER BY dateofadm;
SELECT name, charges, age FROM HOSPITAL WHERE SEX = F;
SELECT COUNT(*) FROM HOSPITAL
WHERE age < 30;
INSERT INTO HOSPITAL VALUES(11, Aftab,24, Surgery, {25/02/98},300, M);
(i) 5
(ii) 16
(iii) 750
(iv) 380
State Demorgans Laws. Verify one of the Laws using truth table.
2
Prove XY + Z = (X + Y + Z)(X + Y + Z)(X + Y + Z).
2
Write the dual of the Boolean expression (U + W)(VU + w)
1
Obtain a simplified form for a Boolean expression :
2
F(u,v,w,z) = (0, 1, 3, 5, 7, 9, 10, 11, 12, 13, 14, 15) using Karnaugh map.

8 Together with Computer Science (C++) XII

(e) Draw logic circuit for half adder.


1
(f) Represent the Boolean expression X + YZ with the help of NOR gates only.
1
(g) Write the Product of sum form of the function H(U, V, W). Truth table representation of H is as
follows :
1
U

Ans. (a) DeMorgans first theorem states that (X + Y) = X.Y


and second theorem states that (X.Y) = X + Y
The truth table for second theorem is :
X

X.Y

(X.Y)

X+Y

(b) R.H.S = (X+Y+ Z) (X+Y+Z)(X+Y+Z)


= (X+Y+Z) [(X.X) + (Y + Z)]
[ Using Distributive Law]
= (X+Y+Z) (Y+Z)
[X.X = 0 & 0 + A = A]
= XY + YY + Z.Y + X.Z + Y.Z + Z.Z
[Using Distributive Law]
= XY + 0 +Z(Y+X+Y) + Z
[YY = 0, Z.Z = Z]
= XY + Z
[Z + Z.M = Z] [Absorbtion Law]
= L.H.S
(c) Dual is U.W + VUW
(d) The Karnaugh map of the given expression is :
wz
uv
00
01
11
10
00
1
1
1
01
1
1
11
10

F = uvw + uv + uw + z

Examination Paper

(e) The logic circuit for a half adder is :


x

sum = x + y

y
carry = x . y
(f) The Boolean expression X + YZ using NOR gate is :
x

x + yz

y
z'
(g)
7. (a)
(b)
(c)
(d)
Ans. (a)
(b)
(c)

(d)

H(U,V,W) = (U+V+W) . (U+V+W) . (U+V+W) . (U+V+W)


What are repeaters ?
1
What is the difference between LAN and MAN ?
1
Describe the following in brief :
2
(i) MOSAIC
(ii) Usenet.
What do you understand by backbone network ?
1
Repeater is used to regenerate data and voice signals when they become weaker before reaching
destination node. Repeater reads the incoming packet and amplifies it and transmits to another
segment of the network.
LAN and MAN is different in their geographical area and the speed of transfer. LAN is restricted to
one building or nearby two or three buildings but MAN can cover one metropolitan, i.e., from one
small city to one town.
(i) MOSAIC : Mosaic is a program for cruising the Internet. The National Centre wrote this
program for Supercomputer Application at the university of Illinois. It has a simple windows
interface, which creates useful hypertext links that automatically perform some of the menu bar
and button functions.
(ii) Usenet : In Internet, Usenet is the way to meet people and share information. Usenet newsgroup
is a special group set up by people who want to share common interests ranging from current
topic to cultural heritages.
When we connect number of LANs to form one WAN, the network which is used as a backbone to
connect the LANs is called backbone network.

10 Together with Computer Science (C++) XII