Professional Documents
Culture Documents
[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;
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( )
{
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;
}
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;
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
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
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