Examination Papers, 2000: (Delhi)
Examination Papers, 2000: (Delhi)
[Delhi]
Maximum Marks : 70
Note.
Duration : 3 Hours
1. (a) Illustrate the concept of function overloading with the help of an examples.
(b) Name the header file, to which following built- in function belong :
(i) isupper()
(ii) setw()
(iii) exp()
(iv) strcmp()
(c) Will the following program execute successfully ? If not, state the reason(s).
2
2
2
#include<stdio.h>
void main()
{
int s1,s2, num;
s1 = s2 = 0;
for(x=0; x<11; x++)
{
cin<< num;
if (num > 0) s1 += num; else s2 =/num;
}
cout<<s1<<s2;
}
(d) Give the output of the following program segment (Assume all required header files are included in
the program) :
2
char * NAME = "a ProFiLe";
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-1]);
else
NAME [x] ;
cout<<NAME<<endl;
#include<iostream.h>
int func(int &x, int y = 10)
{
if ( x % y == 0) return ++x; else return y--;
}
void main()
{
int p = 20, q = 23;
q = func (p,q);
cout<<p<<q<<endl;
p = func(q);
cout<<p<<q<<endl;
q = func(p);
cout<<p<<q<<endl;
}
Examination Paper
(f) Write a function seqsum( ) in C++ with two arguments, double x and int n. The function should return
a value of type double and it should find the sum of the following series :
4
1 + x/2! + x2/4! + x3/6! + x4/8! + x5/10! + + xn/(2n)!
Ans. (a) A function name having several definitions that are give same name to more than one different
functions having unique parameters is called function overloading or polymorphism.
//This program illustrate how to do function overloading with different no. of argument
#include<iostream.h>
#include<conio.h>
float area(float r);
float area(float l,float w);
void main()
{
char ch;
float len,radius,wid,a;
clrscr();
cout<<"\n Enter c for circle and r for rectangle:";
cin>>ch;
if (ch==c)
{
cout<<"Enter radius : ";
cin>>radius;
a=area(radius);
cout<<"The area of circle is : " <<a;
}
else
if((ch==r)&&(ch==r))
{
cout<<"Enter length : ";
cin>>len;
cout<<"Enter bredth : ";
cin>>wid;
cout<<"Area of rectangle is : "<area(len,wid);
}
}
float area(float r)
{
float pi=3.14159;
return (pi*r*r);
}
float area (float l,float w)
{
return (l*w);
}
(b)
// Correction 1
// Correction 3
Correction 1 :
Correction 2 :
Undefined symbol x
Undefined symbol cin, you must include iostream.h because all the input and
output header files are stored in that header file and replace << operator to >>
operator.
Expression syntax, you write s2/=num
Correction 3 :
(d) A OROoliE.
(e) The output of the given program is :
20
23
10
23
11
11
(f) // The required function is :
2. (a) Why is a destructor function required in classes ? Illustrate with the help of an example.
2
(b) Define a class worker with the following specification :
4
Private members of class worker
wno
integer
wname
25 characters
hrwrk, wgrate
float (hour worked and wage rate per hour)
totwage
float (hrwrk * wgrate)
calcwg( )
A function to find hrwrk * wgrate with float return type
Public members of class worker
in_data( )
a function to accept values for wno, wname, hrwrk, wgrate and invoke calcwg( ) to
calculate totpay.
out_data( )
a function to display all the data members on the screen you should give definitions
of functions.
(c) Consider the following and answer the questions given below :
4
class School
{
int A;
Examination Paper
protected :
int B,C;
public :
void INPUT(int);
void OUTPUT( );
};
class Dept : protected School
{
int X, Y;
protected :
void IN (int,int);
public :
void OUT();
};
class Teacher : public Dept
{
int P;
void DISPLAY (void);
public :
void ENTER();
};
(i) Name the base class and derived class of the class Dept.
(ii) Name the data member(s) that can be accessed from function OUT( ).
(iii) Name the private member function(s) of class Teacher.
(iv) Is the member function OUT( ) accessible by the objects of Dept. ?
Ans. (a) Destructor function required in classes because a destructor destroys the objects that have been
created by a constructor . It destroys the values of the object being destroyed.
For example :
# include<iostream.h>
class xyz
{
int a,b;
public:
void read();
xyz()
//Constructor
{
a = 0;
b = 0;
}
~xyz()
//Destructor
{
cout<< "\n Destructor ";
}
};
class worker
{
int wno;
char wname[25];
float hrwrk;
float wgrate;
float totwage;
float calcwg( )
{
return(hrwrk * wgrate);
}
public :
void in_data( );
void out_data( );
};
void worker :: in_data( )
{
clrscr( );
cout<<"Enter the worker no : ";
cin>>wno;
cout<<"Enter the worker name : ";
gets(wname);;
cout<<"Enter hours worked : ";
cin>>hrwrk;
cout<<"Enter wage rate per hour : ";
cin>>wgrate;
totwage = calcwg( );
}
void worker :: out_data( )
{
clrscr();
cout<<"Worker No : "<<wno;<<endl
cout<<"Worker Name : "<<wname<<endl;
cout<<"Hours Worked : "<<hrwrk<<endl;
cout<<"Wage rate per hour : "<<wgrate<<endl;
cout<<"Total Wage : "<<totwage<<endl;
}
(c)
3. (a)
(b)
(c)
(d)
(e)
Ans. (a)
Examination Paper
clrscr();
int A[M];
int B[N];
int C[M+N];
int i,j,k;
cout<<"\n\tEnter the first array in ascending order\n";
for(i=0;i<M;i++)
{
cout<<"\t";
cin>>A[i];
}
cout<<"\n\tEnter the second array in descending order\n";
for(i=0;i<N;i++)
{
cout<<"\t";
cin>>B[i];
}
// Sorting the second array in ascending order
for(i=0;i<N-1;i++)
{
for(j = i+1;j<N;j++)
{
if (B[i] > B[j])
{
int t = B[i];
B[i] = B[j];
B[j] = t;
}
}
}
i=0,j=0,k=0;
// Merging the first and second array
while((i<M)&&(j<N))
{
if(A[i]>B[j])
{
C[k]=B[j];
j+=1;
k+=1;
}
else
{
C[k]=A[i];
i+=1;
k+=1;
}
}
while(i<M)
{
C[k]=A[i];
i+=1;
k+=1;
}
while(j<N)
{
C[k]=B[j];
j+=1;
k+=1;
}
clrscr();
cout<<"\n\tThe merged arrays are ";
for(k=0;k<(M+N);k++)
cout<<"\n"<<C[k];
}
(b) Given :
Base = 1500
W = 4 bytes
N = 10
M = 15
I = 12
J=9
To find Row Major
The formula is applied :
VAL[I,J] = B +((I-1)* N+(J-1))*W
= 1500+((12-1)* 10 + (9-1))* 4
= 1500 + (110 + 8)*4
= 1500 + 118*4
= 1972 (Ans.)
To find Column Major
The formula is applied
VAL[I,J] = B +((J-1) * M +(I-1)) * W
= 1500 +((9-1) * 15 +(12-1)) *4
= 1500 +( 120 + 11)*4
= 1500 + 131*4
= 1500 + 524
= 2024 (Ans.)
(c) // Function to display the sum of both the diagonal elements of a two dimensional array
const M = 6;
const N = 6;
void sum()
{
clrscr()
int MATRIX[M][N];
int i,j;
int s1 = 0;
int s2 = 0;
cout << "Input steps";
cout << "\n\yEnter the element in the array\n";
for(i=0;i<M;i++)
for(j=0;j<N;j++)
{
cin >> MATRIX[i][j];
}
Examination Paper
Stack Status
1. Push 20
2. Push 8
3. Push 4
4. Pop 4, Pop 8
Calculate 8/4 = 2
Push 2
5. Push 2
6. Push 3
7. Pop 3, Pop 2
Calculate 3 + 2 = 5
Push 5
8. Pop 5, Pop 2
Calculate 5 * 2 = 10
Push 10
9. Pop 10, Pop 20
Calculate 20 10 = 10 Push 10
20
20,8
20,8,4
20,2
20,2,2
20,2,2,3
20,2,5
20,10
10
node *link;
};
// Function body for add queue elements
node *add_Q(node *rear, float val)
{
node *temp;
temp = new node;
temp->data = val;
temp->link = NULL;
rear->link = temp;
rear = temp;
return (rear);
}
Ans. (a) The two member functions of ofstream are open and rdbuf.
(b) // Program to demonstrate the file operation
#include <fstream.h>
#include <conio.h>
#include <string.h>
class DRINKS // Declares the class
{
int DCODE; // Data members
char DNAME[13];
int DSIZE;
float DPRICE;
public :
// Member functions
void getdrinks() { cin>>DCODE>>DNAME>>DSIZE>>DPRICE;}
void showdrinks() { cout << DCODE << DNAME << DSIZE << DPRICE; }
char *getname() { return DNAME; }
};
void read(); // General function to call the class member function
void show();
// Main programming started
int main()
{
read();
show();
Examination Paper
return 0;
}
void read()
{
DRINKS DRI; // Declares the class object
fstream afile; // Declare the file object
afile.open("Drink.dat", ios::app|ios::out|ios::binary); // Open the data file
int n, i;
clrscr();
cout << "Enter how many records U want to enter ";
cin >> n;
for (i =0; i < n; i++)
{
DRI.getdrinks(); // Call the member funciton to input data
afile.write((char *)&DRI, sizeof(DRINKS)); // Write the data values
}
a.close();
}
void show()
{
DRINKS DRI; // Declares the class object
fstream bfile;
bfile.seekg(0, ios::beg); // Pointed at the 0th location in data file
char tname[13];
if (!bfile)
cout << "File does not exists";
while (bfile)
{
bfile.read(char *)&DRI, sizeof(DRINKS)); // Read the data value in file
strcpy(tname, DRI.getname()); / Enter the searched value
if (strcmp(tname, "INDYCOLA") == 0) // Compare the data value
{
cout << "\n";
DRI.showdrinks(); // Display the resulted data through member function
}
}
bfile.close();
}
5. (a) What is the need for normalisation ? Define third normal form.
2
Write SQL commands for (b) to (f) and write the outputs for (g) on the basis of table CLUB :
Table : CLUB
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
COACH-ID
COACH NAME AGE SPORTS
DATE OFAPP
PAY SEX
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
1
KUKREJA
35
KARATE
27/03/1996
1000 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
2
RAVINA
34
KARATE
20/01/1998
1200 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
3
KARAN
34
SQUASH
19/02/1998
2000 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
4
TARUN
33
BASKETBALL 01/01/1998
1500 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
5
ZUBIN
36
SWIMMING
12/01/1998
750
M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
6
KETAKI
36
SWIMMING
24/02/1998
800
F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
7
ANKITA
39
SQUASH
20/02/1998
2200 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
8
ZAREEN
37
KARATE
22/02/1998
1100 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
9
KUSH
41
SWIMMING
13/01/1998
900
M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
10
SHAILYA
37
BASKETBALL 19/02/1998
1700 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
(b) To show all information about the swimming coaches in the club.
(c) To list names of all coaches with their date of appointment (DATOFAPP) in descending order.
(d) To display a report, showing coach name, pay, age and bonus (15% of pay) for all the coaches.
(e) To insert a new row in the CLUB table with the following data :
(f) Give the output of following SQL statements :
(i) Select COUNT (distinct SPORTS ) from CLUB;
(ii) Select MIN(AGE) from CLUB where SEX = F;
(iii) Select AVG(PAY) from CLUB where SPORTS = KARATE;
(iv) Select SUM(PAY) from CLUB where DATEOFAPP>{31/01/98};
(g) Assume that there is one more table COACHES in the database as shown below :
TABLE : COACHES
SPORTSPERSON
SEX
COACH-NO
AJAY
SEEMA
VINOD
TANEJA
1
1
1
1
2
Examination Paper
11
(e) Represent the Boolean expression X'Y + Y'Z with the help of NAND gates only.
1
(f) Write the sum of products from of the function G(U,V,W). Truth table representation of G is as
follows :
1
U
X.Y
X+X.Y
10
(d) Half Adder
1
1
1
1
sum = x + y
y
carry = x . y
(X'.Y')'
X'Y + Y'Z'
Y''
Z
(Y'.Z)'
(f) (U+V+W)(U+V+W')(U'+V+W)(U'+V'+W)
7. (a) What are Routers ?
1
(b) What is the purpose of using Modem ?
1
(c) Write the two advantages and two disadvantages of Bus Topology in network.
2
(d ) What is the difference between LAN and WAN ?
1
Ans. (a) On Internet it is not necessary that all the packets will follow the same path from source to destination.
A special machine router tries to load balance between various paths that exists on networks.
(b) MODEM is used to convert digital data into analog form and vice versa.
(c) Advantages of BUS Topology :
(i) Short cable length - Because there is single common data path connecting all nodes.
(ii) Easy to extend - Additional nodes can be connected to an existing bus network at any point
along its length.
Disadvantages of BUS Topology :
(i) Fault diagnosis is difficult - Although the bus topology is very simple, but in this topology
fault detection is very difficult.
(ii) Nodes must be intelligent - Each node on the network is directly connected to the central bus.
This means that some way of deciding who can use the network at any given time must be
performed in each node. It tends to increase the cost of the nodes irrespective of whether this
is performed in hardware or software.
(d) (i) A LAN is confined to restricted distance up to one building or near by building. On the other
hand scope of WAN is up to one continent.
(ii) Because of the short distances involved, the error rates in LANs are much lower than WANs.
Examination Paper
13