Examination Papers, 1998: (All India)
Examination Papers, 1998: (All India)
[All India]
Maximum Marks : 70
Note.
Duration : 3 Hours
1. (a) Write two major differences between Object Oriented Programming and Procedural Programming. 2
(b) Name the header files, to which following built-in functions belong to :
2
(i) isalnum()
(ii) gets()
(iii) fabs()
(iv) strlen()
(c) Find the syntax error(s), if any, in the following program :
2
#include (iostream.h)
void main( )
{
int X, Y;
cin >> X;
for (Y = 0; y < 10, Y++)
If X == Y
cout << Y+X;
else
cout >> Y;
}
Examination Paper
(f) Write a C ++ function having two value parameters U and n with result type float to find the sum of
series given below :
4
1 U + !U2 1/3! U3 + ! U4 +..... ..+.....
Ans. (a) Procedural Programming :
(i) The emphasis is on doing things rather than data.
(ii) It is based on the sequence of instructions.
Object Oriented Programming :
(i) It emphasises on the data.
(ii) It is based on the principle of data hiding, abstraction, inheritance and polymorphism.
(b) (i) ctype.h
(ii) stdio.h
(iii) math.h
(iv) string.h
(c) The correct program is :
#include <iostream.h>
void main()
{
int X,Y;
cin>>X;
for (Y=0; Y<10; Y++)
If ( X == Y )
cout<<Y+X;
else
cout<< Y;
}
//Correction - 1
// Correction - 2
// Correction - 3
// Correction - 4
2. (a) What do you understand by constructor and destructor functions used in classes ? How are these
functions different from other member functions ?
2
class WORLD
{
int H;
protected :
int S;
public :
void INPUT(int);
void OUTPUT();
};
class COUNTRY : private WORLD
{
int T;
protected :
int U;
public :
void INDATA( int, int)
void OUTDATA();
};
class STATE : public COUNTRY
{
int M;
public :
void DISPLAY (void);
};
(i) Name the base class and derived class of the class COUNTRY.
(ii) Name the data member(s) that can be accessed from function DISPLAY().
(iii) Name the member function(s), which can be accessed from the objects of class STATE.
(iv) Is the member function OUTPUT() accessible by the objects of the class COUNTRY ?
Ans. (a) A constructor is a special initialization function that is called automatically whenever an instance of
your class is declared. The name of the constructor is same as that of class and it returns no
value.This function is the opposite of the constructor in the sense that it is invoked when an object
ceases to exit. It also has a same name as that of class but with a prefix ~. The difference between
the constructor, destructor and other functions is that the functions can return a value but the
constructor and destructor do not return any value.
(b) // Class and function declaration of employee class
class employee
{
int empno;
char ename[20];
Examination Paper
float
basic, da, hra;
float
netpay;
float
calculate()
{
return (basic + da + hra);
}
public :
void havedata()
{
cout << "Enter employee no. : ";
cin >> empno;
cout << "Enter name : ";
cin >> ename;
cout << "Enter basic salary : ";
cin >> basic;
cout << "Enter DA : ";
cin >> da;
cout << "Enter HRA : ";
cin >> hra;
netpay = calculate();
}
void dispdata()
{
cout << "Employee no is : " << empno<<endl;
cout << "Name is : " << ename << endl;
cout << "Basic Salary : " << basic<<endl;
cout << "DA is : " << da<<endl;
cout << "HRA is : " << hra << endl;
cout << "Netpay is : " << netpay<<endl;
}
};
(c)
3. (a)
(b)
(c)
(d)
(e)
Ans. (a) // This function search an element in an array using binary search.
int binary(float ARR[10], float data ,int n)
{
int i, flag = 0, first = 0, last, pos = 1, mid;
last = n 1;
while ((first <= last) && (flag == 0))
{
mid = (first + last) / 2;
if (ARR[mid] == data)
{
pos = pos + mid;
flag = 1;
}
else
if (ARR[mid] < data)
first = mid + 1;
else
last = mid 1;
}
if (flag == 1)
return(1);
else
return(0);
}
Examination Paper
Operation
Stack
100
40
8
+
PUSH 100
PUSH 40
PUSH 8
POP 8
POP 40
Calculate 40 + 8 = 48
PUSH 48
PUSH 20
PUSH 10
POP 10
POP 20
Calculate 20 10 = 10
PUSH 10
POP 10
POP 48
Calculate 48 + 10 = 58
PUSH 58
POP 58
POP 100
Calculate 58 * 100 = 5800
PUSH 5800
100
100, 40
100, 40, 8
20
10
Ans = 5800
(e) // Declares a stack structure
struct node
{
float data;
node *link;
};
// Function body for add stack elements
node *push(node *top, float val)
{
node *temp;
temp = new node;
temp->data = val;
temp->link = NULL;
if(top ==NULL)
top = temp;
else
{
temp->link = top;
top = temp;
}
100, 48
100, 48, 20
100, 48, 20, 10
100, 48, 10
100, 58
5800
return(top);
}
2
4
class STOCK
{
int ITNO;
char ITEM[10];
public :
void GETIT( ) {cin>>ITNO;gets(ITEM);}
void SHOWIT( ){cout<<ITNO<< " "<<ITEM<<endl;}
};
Ans. (a)
ifstream
(i) This class is derived from istream class
(ii) It associates an input buffer with a file
(iii) It is used to read data from a file.
(b)
ofstream
(i) This class is derived from ostream class
(ii) It associates an output buffer with a file
(iii) It is used to write data onto a file.
void create(STOCK s)
{
ofstream afile;
afile.open("stock.dat", ios::out | ios :: binary);
if (!afile)
{
cout << "\n Unable to open the file ";
exit(1);
}
s.GETIT();
afile.write((char *)&s,sizeof(s));
afile.close();
}
(ii) // Function to read the object of class from the binary file
void read_file()
{
ifstream afile;
afile.open("stock.dat", ios::in | ios :: binary);
if (!afile)
{
cout << "\n File does not exist ";
exit(1);
}
STOCK s;
while(afile)
{
afile.read((char *) &s, sizeof(s));
s.SHOWIT();
}
afile.close();
}
5. (a) What is the need for normalisation ? Define first, second and third normal forms.
Examination Paper
Write the SQL commands for (b) to (g ) and write the outputs for (h) on the basis of the table
HOSPITAL :
TABLE : HOSPITAL
No.
Name
Age
Department
Dateofadm
Charges
Sex
Sandeep
65
Surgery
23/02/98
300
Ravina
24
Orthopaedic
20/01/98
200
Karan
45
Orthopaedic
19/02/98
200
Tarun
12
Surgery
01/01/98
300
Zubin
36
ENT
12/01/98
250
Ketaki
16
ENT
24/02/98
300
Ankita
29
Cardiology
20/02/98
800
Zareen
45
Gynaecology
22/02/98
300
Kush
19
Cardiology
13/01/98
800
10
Shailya
31
Nuclear Medicine
19/02/98
400
X.Y
X+X.Y
(b) L.H.S
= X + Y'Z = (X+Y').(X+Z)
[ by distributive law]
= (X+Y'+Z'.Z) (X+Y'.Y+Z)
[ because Z'Z = Y'.Y = 0 & 0+A = A]
= (X+Y'+Z')(X+Y'+Z)(X+Y'+Z)(X+Y+Z) [by distributive law]
= (X+Y'+Z')(X+Y'+Z)(X+Y+Z)
[(X+Y'+Z).(X+Y'+Z) = (X+Y'+Z). by idempotent law]
= R. H. S.
proved.
(c) Dual is (U+V).W + V'U
Examination Paper
10
F = x'y'z' +w + xy'z
(e) The logic circuit for a half adder is :
sum = x + y
x
y
carry = x . y
(f) The Boolean expression X + YZ' using NAND gate is :
x
x
x + yz'
y
z
(g)
7. (a)
(b)
(c)
(d)
Ans. (a)
(b)
(c)
(d)
yz