You are on page 1of 10

Examination Papers, 2002

[All India]
Maximum Marks : 70
Note.

Duration : 3 Hours

All the questions are compulsory.


Programming Language : C++

1. (a) Illustrate the concept of Inheritance with the help of an example.


(b) Name the header files of C++ to which the following functions belong:
(i) get( )
(ii) open( )
(iii) abs( )
(iv) strcat( )
(c) Find the syntax error(s), if any, in the following program :

2
2
2

#include <iostream.h>
void main( )
{
int x;
cin >> x;
for(int y=0, y<10, y++);
cout << x+y;
}

(d) Write the output of the following program :

(e) Write the output of the following program :

void main( );
{
int x = 5, y = 5;
cout << x;
cout << ",";
cout << x;
cout << ",";
cout << y << ","<< y;
}
#include <iostream.h>
void X(int &A, int &B)
{
A = A+B;
B = AB;
A = AB;
}
void main( )
{
int a=4, b=18;
X(a, b);
cout << a << "," << b;
}

(f) Write a function called zero_Small( ) that has two integer arguments being passed by reference and
sets the smaller of the two numbers to 0. Write the main program to access this function.
4
Ans. (a) Inheritance is a capability to define custom data types using classes, enables you to reuse the code
you develop. Inheritance enables you to more readily reuse an object, making slight adjustments,
wherever necessary. For Example,
class Student
{

Examination Paper

private :
char name[20];
int check (int e);
public :
void getdata( );
void putdata( );
protected :
int total;
void calc( );

};
class School : private Student
{
protected :
char class_stu[10];
public :
void getdata( );
void putdata( );
};

In the above example Student is the base class and School is the derived class.
(b) (i) iostream.h
(ii) fstream.h
(iii) math.h
(iv) string.h
(c) The errors are :
#include<iostream.h>
void main( )
{

int x;
cin>>x;
for(int y=0, y<10, y++);
cout << x+y;

// Error 2

Error 1 : Comma is missing,


Corrected program :

#include<iostream.h>
void main( )
{
int x;
cin>>x;
for(int y=0;y<10;y++);
cout<< x+y;
}

(d) 5, 3, 4, 4
(e) 18, 4
(f) The function is :
#include <iostream.>
void zero_small(int &a, int &b)
{
if (a<b)
a = 0;
else
b = 0;
}
void main( )
{
int x, y;

2 Together with Computer Science (C++) XII

cout << "Enter the values X and Y : ";


cin >> x >> y;
zero_small(x, y);
cout << "The final values of X and Y are : ";
cout << x << y;
}

2. (a) What do you understand about a member function ? How does a member function differ from an
ordinary function ?
2
(b) Define a class Student for the following specifications.
4
Private members of the Student are :
roll_no integer
name array of characters of size 20
class_st array of characters of size 8
marks array of integers of size 5
percentage float
calculate that calculates overall percentage marks and returns the percentage
Public members of the Student are :
readmarks reads mark and invoke the calculate function
displaymarks prints the data
(c) Write the output of the following program.
4
#include <iostream.h>
class Counter
{
private:
unsigned int count;
public :
Counter( ) {count = 0;}
void inc_Count( ) { count ++;}
int get_Count( ) { return count;}
};
void main( )
{
Counter C1, C2;
cout << "\n C1=" << C1.get_Count( );
cout << "\n C2=" << C2.get_Count( );
C1.inc_Count( );
C2.inc_Count( );
C2.inc_Count( );
cout << "\n C1=" << C1.get_Count( );
cout << "\n C2=" << C2.get_Count( );
}

Ans. (a) Member functions are functions defined within a class that act on the data members in the class. The
use of member functions distinguishes a class from a struct. Whereas an ordinary function can call
in any function without an object, the member function can call only by using its object. The member
function is a member of its own class but an ordinary function is not.
(b) The class is :
class student
{
int roll_no;
char name[20];
char class_st[8];
int marks[5];

Examination Paper

float percentage;
float calculate( );
public :
void readmarks( );
void displaymarks( );

};
float student :: calculate( )
{
float total = 0;
for (int I = 0; I < 5; I++)
total += marks[I];
return (total / 5);
}
void student :: readmarks( )
{
cout << "Enter 5 marks :";
for (int I=0; I < 5; I++)
cin >> marks[I];
percentage = calculate( );
}
void student :: displaymarks( )
{
cout << "The 5 marks are : ";
for (int I=0; I < 5; I++)
cout << marks[I] << endl;
cout << "\nPercentage = " << percentage << endl;
}

(c) The output is :


C1 = 0
C2 = 0
C1 = 1
C2 = 2
3. (a) Define array and pointer.
(b) Given the following class,

2
4

char *msg[ ] = {"over flow", "under flow"};


class Stack
{
int top, //the stack pointer
stk[5]; //the elements
void err_rep(int e_num) { cout << msg[e_enum]; } //report error message
public:
void init( ) { top = 0; } //initialize the stack pointer
void push(int); //put new value in stk
void pop( ); //get the top value
};

Define pop outside the Stack. In your definition take care of under flow condition. Function pop
should invoke error_rep to report under flow.
(c) Change the following infix expression into postfix expression.
3
(A+B)*C+D/E-F
(d) The array A[20][10] is stored in the memory with each element requiring one byte of storage if the
base address of A is C0, determine the location of A[10][5] when the arrayA is stored by column major.
3

4 Together with Computer Science (C++) XII

(e) Considering the following key set : 42, 29, 74, 11, 65, 58, use insertion sort to sort the data in
ascending order and indicate the sequences of steps required.
3
Ans. (a) An array is a sequence of objects all of which have the same type. The objects are called elements of
the array and are numbered consecutively 0, 1, 2, ...... These numbers are called index values or
subscripts of the array.
A pointer is a variable that contains the memory address of an item rather its value. A pointer can
point to any type of data item or to a function.
(b) The function is :
void Stack :: pop( )
{
if (top == 0)
err_rep(1);
else
cout << stk[top];
}

(c) (A+B) * C + D / E - F
((((A+B) *C) + (D/E)) - F)
Input

Stack

Output

(
(
(
(
A
+
B
)
*
C
)
+
(
B
/
E
)
)

(
((
(((
((((
((((
((((+
((((+
(((
(((*
(((*
((
((+
((+(
((+(
((+(/
((+(/
((+
(
(
(
Empty

A
A
AB
AB+
AB+
AB+C
AB+C*
AB+C*
AB+C*
AB+C*D
AB+C*D
AB+C*DE
AB+C*DE/
AB+C*DE+
AB+C*DE+
AB+C*DE+F
AB+C*DE+F

F
)

Final result is :AB+C*DE+F


(d) A[I][J] = B + W((I L1) + M(J L2))
B = C0
W=1
A[10][5] = C0 + 1((10 1) + 20(5 0))
= C0 + 1(10 + 20 x 5)
= C0 + 1(10 + 100)
= C0 + 110

Examination Paper

(e) Using bubble sort, the sequence of steps are :


42

29

74

11

65

58

29

42

74

11

65

58

29

42

74

11

65

58

11

29

42

74

65

58

11

29

42

65

74

58

11

29

42

58

65

75

4. (a) What is the difference between put( ) and write( ) ?


1
(b) Write a C++ program, which initializes a string variable to the content. Time is a great teacher but
unfortunately it kills all its pupils. Berlioz and outputs the string one character at a time to the disk
file OUT.TXT. You have to include all the header files if required.
4
Ans. (a) The put( ) is used in context of Text file/Binary file.
The write( ) is used in context of character/multiple character.
(b) The program is :
#include <fstream.h>
void main( )
{
char line[80= {"time is a great teacher but unfortunately ........."};
int C = 0;
fstream fout;
fout.open("out.txt", ios::out);
while (line[C] != \0)
{
fout << line[C];
}
fout << endl;
fout.close( );
}
Or
#include <fstream.h>
void main( )
{
char line[80= {"time is a great teacher but unfortunately ........."};
ofstream fout("OUT.TXT");
for (int C=0; line[C] != \0; C++)
fout << line[C];

6 Together with Computer Science (C++) XII

fout << endl;


fout.close( );
}

5. (a) Differentiate between Data Definition Language and Data Manipulation Language.
Given
the following Teacher relation : Write SQL command for question (b) to (h).
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901

12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
No
Name
Department
Dateofjoining
Salary
Sex
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
1.
Raja
Computer
21/05/98
8000
M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
2.
Sangita
History
21/05/97
9000
F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
3.
Ritu
Sociology
29/08/98
8000
F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
4.
Kumar
Linguistics
13/06/96
10000
M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
5.
Venkatraman
History
31/10/99
8000
M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
6.
Sidhu
Computer
21/05/86
14000
M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
7.
Aishwarya
Sociology
11/01/98
12000
F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901

(b)
(c)
(d)
(e)
(f)
(g)
(h)

Ans. (a)

(b)
(c)
(d)
(e)
(f)
(g)
(h)
6. (a)
(b)
(c)
(d)
(e)

To select all the information of teacher in computer department.


1
To list the name of female teachers in History department.
1
To list all names of teachers with date of admission in ascending order.
1
To display Teachers name, Department, and Salary of female teacher.
1
To count the number of items whose salary is less than 10,000.
1
To insert a new record in the Teacher table with the following data :
1
8, Mersha, Computer, {1/1/2000}, 12000, M.
Give the output of the following SQL command :
2
(i) SELECT MIN(DISTINCT Salary) FROM Teacher
(ii) SELECT MIN(Salary) FROMTeacher WHERE Sex = M
(iii) SELECT SUM(Salary) FROM Teacher WHERE Department = History
(iv) SELECT AVG(Salary) FROM Teacher WHERE Dateofjoining < {1/1/98}
DDL. It provides statements for creation and deletion of the database.
DML. It provides statements for manipulating the database. It includes commands to insert, delete
and modify tuples in the database.
SELECT * FROM Teacher WHERE Department = Computer;
SELECT * FROM Teacher WHERE Sex = FAND Department = History;
SELECT Name FROMTeacher ORDER BY Dateofjoining;
SELECT Name, Department, Salary FROM Teacher WHERE Sex = F;
SELECT COUNT(*) FROM Teacher WHERE Salary < 10000;
INSERT INTO Teacher VALUES (8, Mersha, Computer, (1/1/2000}, 12000, M);
All the outputs are same whether the new 8th row is included or not
(i) 8000
(ii) 8000
(iii) 17000
(iv) 11000
State the distributive law and verify the law using truth table.
1
Prove XY + YZ + Y'Z = XY+Z, algebraically.
2
Obtain the simplified form of a Boolean expression using Karnaugh map.
2
F(w, x, y, z) = (2, 3, 6, 10, 11, 14)
Draw a logic circuit of full Adder. Give truth table of full Adder.
2
Represent the Boolean expression (X+Y)(Y+Z)(X+Z) with help of NOR gate only.
1

Examination Paper

(f) Given the following truth table, write the product of sums form of the function F(x, y, z)
x

Ans. (a) The distributive law states


X.(Y + Z ) = X.Y + X.Z (ii) X + Y.Z = (X + Y) . (X+Z)
The truth table for X(Y+Z) = XY + XZ is given below :
Input

Output

Y+Z

XY

XZ

X(Y+Z)

XY+XZ

Both the columns X(Y+Z) and XY+YZ are identical, hence proved.
(b) L.H.S. = X.Y + Y.Z + Y'.Z
= X.Y + (Y.+Y')Z
= X.Y + 1.Z
= X.Y + Z = R. H. S.
(c) F = (2, 3, 6, 10, 11, 14)
YZ
WX
00
01

00

01

11
1

11
10

10
1

F = YZ' + X'Y

8 Together with Computer Science (C++) XII

1
1

(d) The truth table of Full Adder is :


x

sum

carry

The logic circuit of Full Adder is :


x
z
y

sum = x + y + z

carry = x . y + y . z + x . z

(e) (X+Y)(Y+Z)(X+Z)
Take the double complement.
= [(X+Y)(Y+Z)(X+Z)''
= ((X+Y) + (Y+Z) + (X+Z)']'
i.e.,
x
y

(x + y)'

y
z

(y + z)'

z
x

(z + x)'

(x + y) + (y + z) + (z + x)

(f) F (X, Y, Z) = x'y'z + x'yz' + xy'z' + xyz


7. (a) What is a MODEM ?
(b) Write the following abbreviations in their full form :
FTP, WAN, WWW
(c) Mention one difference between circuit switching and packet switching.

Examination Paper

1
1
2

(d) Write two advantages and disadvantages of the following topologies in network :
1
(i) Bus
(ii) Ring
Ans. (a) A modem is a device which is used to convert data from digital bit strream into an analog signal and
vice versa.
(b) FTP. File Transfer Protocol
WAN. Wide Area Network
WWW. World Wide Web.
(c) Circuit Switching. In this technique, firstly the complete physical connection between two computers
is established and then data is transmitted from the source computer to the destination computer.
A Packet Switching network divides the data traffic into blocks called packets that have a maximum
length. Each packet of user data travels in a data envelope, which gives the destination address of
the packet and a variety of control information.
(d) 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.
Advantages of Ring topology :
(i) Short cable length In ring topology less connections will be needed which increases network
reliability.
(ii) The amount of cable needed in this topology is comparable to bus and relatively smallto star.
Disadvantages of Ring topology :
(i) Node failure causes network failure Since each node in this network is connected to its
neighbouring node and data travels through each node, there is one traffic flow until defective
node is removed.
(ii) Each node must handle the data being transferred on the ring.

10 Together with Computer Science (C++) XII

You might also like