Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Examination Papers, 1998: (Delhi)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Examination Papers, 1998

[Delhi]
Maximum Marks : 70 Duration : 3 Hours
Note. All the questions are compulsory.
Programming Language : C++

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


(b) Name the header files, to which following built-in functions belong to : 2
(i) cos() (ii) setw() (iii) toupper() (iv) strcpy()
(c) Find the syntax error(s), if any, in the following program : 2
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;
}
}
}
(d) What is the output of the following program : 2
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);
(e) Write the output of the following program : 3
#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 1
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; // Initialize the series first value 1
for (int i = 2; i <= N+1; i++) // Starting series value is 2
{
temp = temp * (X/i); // (4/2!) and so on
sum += temp;
}
return sum;
}
2. (a) What is copy constructor ? What do you understand by constructor overloading ? 2

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 3
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) (i) Base class : PPP
Derived class : RRR
(ii) M and U
(iii) DISP(), INDATA(int, int) and OUTDATA()
(iv) No
3. (a) 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
(b) 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.
(c) 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
(d) 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, *, +
(e) 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 5
}
cout<<"\n\t sum of " <<(i+1)<<"column is "<<sum;
}
}
(d) The stack operation is :
Scanned elements Operation Stack
50 PUSH 50 50
40 PUSH 40 50, 40
+ POP 40
POP 50
Calculate 50+40 = 90
PUSH 90 90
18 PUSH 18 90, 18
14 PUSH 14 90, 18, 14
– POP 14
POP 18
Calculate 18–14 = 4
PUSH 4 90, 4
4 PUSH 4 90, 4, 4
* POP 4
POP 4
Calculate 4*4 = 16
PUSH 16 90, 16
+ POP 16
POP 90
Calculate 90+16 = 104
PUSH 104 104
∴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


delete temp;
}
return (top);
}
4. (a) Write name of two member functions belonging to fstream class. 2
(b) Assuming the class Employment given below, write functions in C++ to perform following : 4
(i) Write the objects of Employee to a binary file.
(ii) Read the objects of Employee from binary file and display them on screen.
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 7
TABLE : HOSPITAL
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
No. Name Age Department Dateofadm Charges Sex
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1 Arpit 62 Surgery 21/01/98 300 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
2 Zarina 22 ENT 12/12/97 250 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
3 Kareem 32 Orthopaedic 19/02/98 200 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
4 Arun 12 Surgery 11/01/98 300 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
5 Zubin 30 ENT 12/01/98 250 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
6 Ketaki 16 ENT 24/02/98 250 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
7 Ankita 29 Cardiology 20/02/98 800 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
8 Zareen 45 Gynaecology 22/02/98 300 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
9 Kush 19 Cardiology 13/01/98 800 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
10 Shilpa 23 Nuclear Medicine 21/02/98 400 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234

(b) To show all information about the patients of cardiology department. 1


(c) To list the names of female patients who are in ENT department. 1
(d) To list names of all patients with their date of admission in ascending order. 1
(e) The display Patients’ Name, charges, age for female patients only. 1
(f) To count the number of patients with age<30. 1
(g) To insert a new row in the HOSPITAL table with the following data : 1
11, ‘Aftab’, 24, ‘Surgery’, {25/02/98}, 300, ‘M’
(h) 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};
Ans. (a) 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.
(b) SELECT * FROM HOSPITAL
WHERE department = “Cardiology”;
(c) SELECT name FROM HOSPITAL WHERE department = “ENT”AND sex = “F”;
(d) SELECT name FROM HOSPITAL
ORDER BY dateofadm;
(e) SELECT name, charges, age FROM HOSPITAL WHERE SEX = “F”;
(f) SELECT COUNT(*) FROM HOSPITAL
WHERE age < 30;
(g) INSERT INTO HOSPITAL VALUES(11, “Aftab”,24, “Surgery”, {25/02/98},300, “M”);
(h) (i) 5 (ii) 16 (iii) 750 (iv) 380
6. (a) State Demorgan’s Laws. Verify one of the Laws using truth table. 2
(b) Prove X’Y + Z = (X’ + Y’ + Z)(X’ + Y + Z)(X + Y + Z). 2
(c) Write the dual of the Boolean expression (U + W)(V’U + w) 1
(d) 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 V W H
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
Ans. (a) DeMorgan’s 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 Y X.Y (X.Y)’ X’ Y’ X’+Y’


0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0
(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]
= X’Y + Y’Y + Z.Y + X’.Z + Y’.Z + Z.Z [Using Distributive Law]
= X’Y + 0 +Z(Y+X’+Y’) + Z [Y’Y = 0, Z.Z = Z]
= X’Y + Z [Z+Z.M = Z] [Absorbtion Law]
= L.H.S
(c) Dual is U.W + V’UW
(d) The Karnaugh map of the given expression is :
wz
uv 00 01 11 10
00 1 1 1
01 1 1
11 1 1 1 1
10 1 1 1
F = u’v’w’ + uv + uw + z

Examination Paper 9
(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) H(U,V,W) = (U+V+W’) . (U+V’+W’) . (U’+V+W) . (U’+V’+W)
7. (a) What are repeaters ? 1
(b) What is the difference between LAN and MAN ? 1
(c) Describe the following in brief : 2
(i) MOSAIC (ii) Usenet.
(d) What do you understand by backbone network ? 1
Ans. (a) 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.
(b) 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.
(c) (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.
(d) 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

You might also like