You are on page 1of 13

Examination Papers, 2000

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

1. (a) Illustrate the concept of function overloading with the help of an examples. 2
(b) Name the header file, to which following built- in function belong :
(i) isupper() (ii) setw() (iii) exp() (iv) strcmp() 2
(c) Will the following program execute successfully ? If not, state the reason(s). 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;
(e) Write the output of the following program : 3
#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 1
(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) (i) isupper( ) :ctype.h
(ii) setw( ) :iomanip.h
(iii) exp( ) :math.h
(iv) strcmp( ) :string.h
(c) The correct program is :
#include<stdio.h>
#include<iostream.h>
void main()
{
int s1,s2, num;
s1=s2=0;

2 Together with ® Computer Science (C++) – XII


for( int x=0;x<11;x++) // Correction 1
{
cin>>num; // Correction 2
if(num>0) s1+=num;
else
s2/=num; // Correction 3
}
cout<<s1<<s2;
}
Correction 1 : Undefined symbol ‘x’
Correction 2 : 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.
Correction 3 : Expression syntax, you write s2/=num
(d) A OROoliE.
(e) The output of the given program is :
20 23
10 23
11 11
(f) // The required function is :
double seqsum(double x, int n)
{
float sum=1,num=1,div=2,fact=1;
float term;
for(int i=2;i<=n;i++)
{
num=num*n;
fact=fact*(div)*(div-1);
term=(num/fact);
div=div+2;
sum=sum+term;
}
return sum;
}
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 3
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 ";
}
};
(b) The class is :
class worker
{
int wno;
char wname[25];
float hrwrk;
float wgrate;
float totwage;
float calcwg( )
{

4 Together with ® Computer Science (C++) – XII


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) (i) Base class of class Dept - School
and Derived class of class Dept - Teacher
(ii) X,Y,B,C
(iii) Display()
(iv) Yes.
3. (a) Suppose A, B, C are arrays of integers of size M,N and M+N respectively. The numbers in array A
appear in ascending order while the numbers in array B appear in descending order. Write a user
defined function in C++ to produce third array C by merging arrays A and B in ascending order. Use
A, B and C as arguments in the function. 4
(b) An array VAL[1..15][1..10] is stored in the memory with each element requiring 4 bytes of storage. If
the base address of array VAL is 1500, determine the location of VAL [12][9] when the array VAL is
stored (i) Row wise (ii) Column wise. 3
(c) Write a user-defined function in C++ to find and display the sum of both the diagonal elements of a
two dimensional array MATRIX[6][6] containing integers. 2
(d) Evaluate the following postfix expression using a stack. Show the contents of stack after execution
of each operation : 2
20, 8, 4, /, 2, 3, +, *, -
(e) Give necessary declarations for a queue containing float type numbers; also write a user defined
function in C++ to insert a float type number in the queue. You should use linked representation of
queue. 4
Ans. (a) The function is :
const M = 10;
const N = 10;
void merge()

Examination Paper 5
{
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;
}

6 Together with ® Computer Science (C++) – XII


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 7
// Display the array elements
for(i=0;i<M;<i++)
{
for(j=0;j<N; j++)
{
cout << MATRIX[i][j] << "\t";
}
cout << “\n”;
}
// Find the diagonal sum in s1 from left index to right
for(i=0;i<M;i++)
{ for(j=0;j<N; j++)
{
s1 = s1 + MATRIX[i][j];
i++;
}
}
// Finding the diagonal sum s2 from right index to left
for(i=0;i<=M;i++) {
for(j=N-1;j>=0; j--)
{
s2 = sw + MATRIX[i][j];
i++;
}
}
// The resulted sum of diagonals
cout << s2 << " " << s1;
getch();
}
(d) The stack operation is :
Operation Stack Status
1. Push 20 20
2. Push 8 20,8
3. Push 4 20,8,4
4. Pop 4, Pop 8
Calculate 8/4 = 2
Push 2 20,2
5. Push 2 20,2,2
6. Push 3 20,2,2,3
7. Pop 3, Pop 2
Calculate 3 + 2 = 5
Push 5 20,2,5
8. Pop 5, Pop 2
Calculate 5 * 2 = 10
Push 10 20,10
9. Pop 10, Pop 20
Calculate 20 – 10 = 10 Push 10 10
(e) // Declares a queue structure
struct node
{
float data;

8 Together with ® Computer Science (C++) – XII


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);
}
4. (a) Name two member functions of ofstream class. 1
(b) Assume the class DRINKS defined below, write functions in C++ to perform the following : 4
(i) Write the objects of DRINKS to a binary file.
(ii) Read the objects of DRINKS from binary file and display them on screen when DNAME has
value “INDY COLA”.
class DRINKS
{
int DCODE;
char DNAME[13]; // Name of the drink
int DSIZE; // size in litres
float DPRICE;
public :
void get drinks( ) {cin>>DCODE>>DNAME>>DSIZE>>DPRICE;}
void showdrinks()
{
cout<<DCODE<<DNAME<<DSIZE<<DPRICE<<endl;
}
char *get name( ) { return DNAME;}
};
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 9
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
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
5 ZUBIN 36 SWIMMING 12/01/1998 750 M
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

10 Together with ® Computer Science (C++) – XII


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
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345678
10 SHAILYA 37 BASKETBALL 19/02/1998 1700 M
(b) To show all information about the swimming coaches in the club. 1
(c) To list names of all coaches with their date of appointment (DATOFAPP) in descending order. 1
(d) To display a report, showing coach name, pay, age and bonus (15% of pay) for all the coaches. 1
(e) To insert a new row in the CLUB table with the following data : 1
(f) Give the output of following SQL statements : 2
(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 : 2
TABLE : COACHES
SPORTSPERSON SEX COACH-NO
AJAY M 1
SEEMA F 2
VINOD M 1
TANEJA F 3
What will be the output of the following query :
SELECT SPORTSPERSON COACHNAME
FROM CLUB, COACHES
WHERE COACH_ID = COACH_NO
Ans. (a) The basic objective of normalization is to reduce redundancy, which means that data is to be stored
only once. Because storing data many times lead to wastage of storage space and increase the
access time. So, relations are to be normalized so that we can alter them at any time without doing
much change.
In 3 NF relation nonkey attributes are non-transitively dependent upon the primary key.
(b) SELECT * FROM CLUB WHERE SPROTS = “swimmimg”.
(c) SELECT COACHNAME FROM CLUB ORDER BY DATOFAPP
(d) SELECT COACHNAME, PAY, AGE , Pay * 15/100 FROM CLUB
(e) INSERT INTO CLUB VALUES (11, “Rajiv”, 40, “Hockey”,{27/05/2000, 2000, “M”)
(f) (i) 4 (ii) 34 (iii) 1100 (iv) 7800
(g) SPORTS PERSON COACHNAME
VINOD KUKREJA
AJAY KUKREJA
SEEMA RAVINA
TANEJA KARAN
6. (a) State Absorption Laws. Verify one of the Absorption Laws using a truth table. 2
(b) Prove X'.Y + Y'.Z = X'.Y.Z + X'.Y'.Z' + X.Y'.Z + X'.Y'.Z algebraically. 2
(c) Obtain simplified from for a Boolean expression 3
F(x,y,z,w) = Σ(1,3,4,5,7,9,11,12,13,15) using Karnaugh Map.
(d) Draw the logic circuit for a half-adder. 1

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 V W G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
Ans. (a) Absorption Law state that
(i) X + X.Y = X
(ii) X(X+Y) = X
Truth Table
X Y X.Y X+X.Y
0 0 0 0
0 1 0 0
1 0 0 1
1 1 1 1
(b) X'Y + Y'Z = X'YZ + X'YZ' + XY'Z + X'Y'Z
L.H.S = X'Y + Y'Z
= X'Y[Z + Z'] + Y'Z[X + X'] [X + X' = 1]
= X'YZ + X'YZ' + XY'Z + X'Y'Z
(c) F(x, y, z, w) = Σ(1, 3, 4, 5, 7, 11, 12, 13, 15)
yz
wx 00 01 11 10
00 1 1
01 1 1 1
11 1 1 1
10 1 1
(d) Half Adder
x sum = x + y
y

carry = x . y

12 Together with ® Computer Science (C++) – XII


(e) X'Y + Y'Z
X' (X'.Y')'
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

You might also like