Delhi 2002 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Examination Papers, 2002

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

1. (a) What is the purpose of a header file in a program ? 2


(b) Name the header files of C++ to which the following functions belong : 2
(i) write( ) (ii) arc( ) (iii) open( ) (iv) strlen( )
(c) Find the syntax error(s), if any, in the following program : 2
#include <iostream.h>
void main( )
{
int x;
cin << x;
for (int y=0; y<10; y++);
cout >> x+y;
}
(d) Find the output of the following program : 2
void main( );
{
int x =5, y=5;
cout << x++;
cout << ",";
cout << ++x;
cout << ",";
cout << y++ << "," << ++y;
}
(e) Write the output of the following program : 3
#include <iostream.h>
void X(int A, int &B)
{
A=A+B;
B=A-B;
A=A-B;
}
void main( )
{
int a=4, b=18;
X(a, b);
Cout << a << "," << b;
}
(f) Raising a number n to a power p is the same as multiplying n by itself p times. Write a function called
power that takes two arguments, a double value for n and an int value for p and returns the result as
double value. Use default argument of 2 for p, so that if this argument is omitted the number will be
squared. Write the main function that gets value from the user to test power function. 4
Ans. (a) Header files, also called include files, provide function prototype declarations for library
functions.
(b) (i) fstream.h (ii) graphics.h (iii) fstream.h (iv) string.h

Examination Paper 1
(c) The errors are :
#include<iostream.h>
void main( )
{
int x;
cin << x; // Error 1
for(int y=0; y<10; y++);
cout >> x+y; // Error 2
}
Error 1 : Illegal structure operation
Error 2 : Illegal structure operation
Corrected program :
#include<iostream.h>
void main( )
{
int x;
cin >> x;
for(int y=0; y<10; y++);
cout << x+y;
}
(d) 5, 7, 6, 6
(e) 4, 4
(f) The function is :
#include<iostream.h>
#include<conio.h>
double power(double n,int p = 2)
{
int s = 1;
for(int i = 1; i <= p; i++)
s = s*n;
return(s);
}
void main( )
{
double num, result;
int po;
clrscr();
cout << "Enter the number ";
cin >> num;
cout << "Enter the power to be calculated ";
cin >> po;
result = power(num,po);
cout << "\nResult when the power is given "<<result;
result = power(num);
cout << "\nResult when the power is not given "<<result;
}
2. (a) What do you understand about a base class and a derived class ? If a base class and a derived class
each include a member function with the same name and arguments, which member function will be
called by the object of the derived class if the scope operator is not used ? 2
(b) Considering the following specifications : 4
Structure name Data Type Size
Name first array of character 40
mid array of character 40

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


last array of character 60
Phone area array of character 4
exch array of character 4
numb array of character 6
P_rec name Name
phone Phone
with member functions constructor and display_rec.
(i) Declare structures in C++ for Name and Phone.
(ii) Declare a class for P_rec.
(iii) Define the constructor (outside the class P_rec) that gathers information from the user for the
above two structures Name and Phone.
(iv) Define the display_rec (outside the class P_rec) that shows the current values.
(c) Consider the following class declaration and answer the questions below : 4
class SmallObj
{
private:
int some, more;
void err_1( ) { cout << "error"; }
public:
void Xdata(int d) {some = d; more = d++;}
void Ydata( ) { cout << some << " " << more;}
};
(i) Write the name that specifies the above class.
(ii) Write the data of the class with their access scope.
(iii) Write all member functions of the class along with their access scope.
(iv) Indicate the member function of the SmallObj that sets data.
Ans. (a) Base class. When a class is defined in normal class declaration is called a base class.
Derived class. A derived class inherits data members and member functions from its base class.If
there is the member function in base class and derived class with the same name and the object of the
derived class is created it will call the function of the derived class.
(b) (i) The structures are :
struct Name
{
char first[40];
char mid[40];
char last[60];
};
struct Phone
{
char area[4];
char exch[4];
char numb[6];
};
(ii) The class is :
class P_rec
{
Name name;
Phone phone;
public :
P_rec( );
void display_rec( );
};

Examination Paper 3
(iii) The constructor is :
P_rec :: P_rec( )
{
cout << "Enter the first name ";
cin >> name.first;
cout << "Enter the middle name ";
cin >> name.mid;
cout << "Enter the last name ";
cin >> name.last;
cout << "Enter the area code ";
cin >> phone.area;
cout << "Enter the exchange ";
cin >> phone.exch;
cout << "Enter the number ";
cin >> phone.numb;
}
(iv) The member method is :
void P_rec::display_rec( )
{
cout << "The first name "<< name.first;
cout << "The middle name "<< name.mid;
cout << "The last name "<< name.last;
cout << "The area code "<< phone.area;
cout << "The exchange "<< phone.exch;
cout << "The number "<< phone.numb;
}
(c) (i) The name specifies the above class as SmallObj.
(ii) The data members are some and more and their access scope is private, i.e., they can be
available inside the class only.
(iii) The member functions are err_1( ) with private access and Xdata( ), Ydata( ) with public access,
i.e., err_1( ) is available inside the class only while Xdata( ) and Ydata( ) cane be call outside the
class also.
(iv) The member function of the SmallObj that sets data is Xdata( ).
3. (a) Define Queue and Stack. 2
(b) Given the following class : 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_num]; } //report error message
public:
void init( ) { top = 0; } //intialize the stack pointer
void push(int); //put new value in stk
void pop( ); //get the top value
};
Define push outside the Stack. In your definition take care of overflow condition. Function push has
to invoke err_rep to report over flow.
(c) Use a stack to evaluate the following postfix expression and show the content of the stack after
execution of each operation. Don’t write any code. Assume as if you are using push and pop member
functions of the stack. 3
AB–CD+E*+ (whereA =5, B=3, C=5, D=4 and E=2)

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


(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 C0 when the location of A[10][5] is 2000. 3
(e) Considering the following key set : 42, 29, 74, 11, 65, 58, use bubble sort to sort the data in ascending
order and indicate the sequences of steps required. 3
Ans. (a) Queue. A queue is similar to a checkout line on the bus stand. The first person on line is served first,
and the person can enter the line only at the end.
Stack. A stack is a list with the restriction that new node can be added to a stack and removed from
a stack only at the top.
(b) The function is :
void Stack :: push(int x)
{
if (top>4)
{
err_rep(0);
}
else
{
stk[top]=x;
top++;
}
}
(c) AB-CD + E*+
Input A = 5 B = 3 C = 5 D = 4 E = 2
(1) Push (5)
5
(2) Push (3)
5 3
(3) –
8 Pop (3)
Pop (5)
Push (5–3)
(4) Push (5)
2 5
(5) Push (4)
2 5 4
(6) +
8 9 Pop (5)
Pop (4)
Push (5+4)
(7) Push (2)
2 9 2
(8) *
2 18 Pop (9)
Pop (2)
Push (9 * 2)

Examination Paper 5
(9) +
20 Pop (18)
Pop (2)
Push (18+2)
(d) A[I][J] = B+W((I–L1)+M(J–L2))
B = C0
A[10][5] = C0 +1((10–1) + 20(5–1))
2000 = C0 +1(9+20 x 4)
2000 = C0 +89
C0 = 2000–89 = 1911
(e) Using bubble sort, the sequence of steps are :
1st iteration :
42 Swap 29 29
29 42 No 42
74 74 change 74 Swap
11 11 11
65 65 65
58 58 58
29 29 29
42 42 42
11 11 11
74 Swap 65 65
65 74 Swap 58
58 58 74
2nd iteration :
29 No 29 29 29
42 change 42 Swap 11 11
11 11 42 No 42
65 65 65 change 65 Swap
58 58 58 58
74 74 74 74
3rd iteration :
29 29 Swap 11
11 11 29
42 42 42
58 58 58
65 No 65 65
74 change 74 74
4. (a) What is the difference between get( ) and read( ) ? 1

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


(b) Write a C++ program, which reads one line at a time from the disk file TEST.TXT and displays it to a
monitor. Your program has to read all the contents of the file. Assume the length of the line not to
exceed 80 characters. You have to include all the header files if required. 4
Ans. (a) The read function is used to read block of data from the disk while the get function is used to read a
character from the disk.
(b) The program is :
#include<iostream.h>
#include<stdlib.h>
ifstream in_file;
main( )
{
char in_char;
char line[80];
in_file.open("TEST.TXT",ios::in);
if(!in_file)
{
cerr << "\n\n File does not exist";
exit(0);
}
while(in_file.getline(line,80))
{
cout << line << endl;
}
in_file.close( );
return 0;
}
5. (a) What is relation ? Define the relational data model. 2
Given the following Lab relations : Write SQL command for questions (b) to (h).
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
No ItemName CostPerItem Quantity DateofPurchase Warranty Operational
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
1 Computer 60000 9 21/05/96 2 7
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
2 Printer 15000 3 21/05/97 4 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
3 Scanner 18000 1 29/08/98 3 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
4 Camera 21000 2 13/06/96 1 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
5 Hub 8000 1 31/10/99 2 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
6 UPS 5000 5 21/05/96 1 4
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
7 Plotter 25000 2 11/1/2000 2 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
(b) To select the ItemName purchased after 31/10/97. 1
(c) To list the ItemName, which are within the Warranty period till present date. 1
(d) To list the ItemName in ascending order of the date of purchase where quantity is more than 3. 1
(e) To display ItemName, CostPerItem, and Quantity whose Warranty is over. 1
(f) To count the number of items whose cost is more than 10000. 1
(g) To insert a new record in the Lab table with the following data : 1
8, “VCR”, 10000, 2, {2/2/2000}, 1, 2.
(h) Give the output of the following SQL command : 2
(i) SELECT MIN(DISTINCT Quantity) FROM LAB
(ii) SELECT MIN(Warranty) FROM LAB WHERE Quantity = 2
(iii) SELECT SUM(CostPerItem) FROM LAB WHERE Quantity >2

Examination Paper 7
(iv) SELECT AVG(CostPerItem) FROM LAB WHERE DateofPurchase < {1/1/99}
Ans. (a) Relation. A relation is two-dimensional table.
Relational data model. In this model data is stored in conceptual tables in which rows are instances
and columns are fields. E.F.Codd of the IBM proposed the relational model.
(b) SELECT itemname FROM lab WHERE dateofpurchase > {31/10/97}
(c) SELECT itemname, costperitem, quantity FROM lab WHERE date( ) - dateofpurchase < warranty
(d) SELECT itemname FROM lab ORDER BY dateofpurchase WHERE quantity > 3
(e) SELECT itemname, costperitem, quantity FROM lab WHERE date( ) - dateofpurchase > warranty
(f) SELECT COUNT(*) FROM lab WHERE costperitem > 10000
(g) INSERT INTO lab VALUES(8, “VCR”, 10000, 2, {2/2/2000}, 1, 2)
(h) (i) 1 (ii) 1 (iii) 80000 (iv) 23800.00
6. (a) State the associative law and verify the law using truth table. 2
(b) Prove XY + YZ + YZ' = Y, algebraically. 2
(c) Obtain the simplified form of a Boolean expression using Karnaugh map. 1
F(x, y, z) = Σ(2, 3, 6, 7)
(d) Give truth table of Full Adder. Draw a logic circuit for Full Adder. 2
(e) Represent the Boolean expression X(Y'+Z) with the help of NOR gate only. 1
(f) Given the following truth table, write the sum of products form of the function F(x,y,z) 2
x y z F
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
Ans. (a) The associative law states that :
(i) X + (Y + Z) = (X + Y) +Z
(ii) X.(Y.Z) = (X.Y).Z
The truth tables are :
(i) X Y Z Y+Z X+Y X+(Y+Z) (X+Y)+Z
0 0 0 0 0 0 0
0 0 1 1 0 1 1
0 1 0 1 1 1 1
0 1 1 1 1 1 1
1 0 0 0 1 1 1
1 0 1 1 1 1 1
1 1 0 1 1 1 1
1 1 1 1 1 1 1
Hence proved.
8 Together with ® Computer Science (C++) – XII
(ii) X Y Z Y.Z X.Y X.(Y.Z) (X.Y).Z
0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 1 1 1 0 0 0
1 0 0 0 0 0 0
1 0 1 0 0 0 0
1 1 0 0 1 0 0
1 1 1 1 1 1 0
Hence proved.
(b) L.H.S = XY + YZ + YZ' = XY + Y(Z+Z') [ X + X' = 1]
= XY + Y = Y(X + 1) = Y [ X + 1 = 1]
(c) F(x, y, z) = Σ(2, 3, 6, 7)
yz
x 00 01 11 10
0 1 1
1 1 1
F=Y
(d) The truth table of Full Adder is :

x y z sum carry
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
The logic circuit of Full Adder is :
x
y sum = x + y + z
z

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

Examination Paper 9
(e) X(Y'+Z)
Take the double complement.
= [X(Y'+Z)]''
= [X'+(Y'+Z)']'
X'
i.e., Xy

F y
Y'
Yy

Z y (Y'+Z)'

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


7. (a) Compare coaxial and optical fiber cable. 1
(b) Write the following abbreviations in their full form : 1
LAN, OSI
(c) What is the purpose of Telnet ? 2
(d) Write two advantages and disadvantages of the following topologies in network : 1
(i) Star
(ii) Tree
Ans. (a) Coaxial cable. It consists of a solid wire core surrounded by one or more foil or braided wire shields,
each separated from the other by some kind of plastic insulator. It is mostly used in the cable wires.
Optical fiber cable. It consists of thin strands of glass or glass-line material which are so connected
that they carry light from source at one end to destination at the other end. The main advantage of
this cable is their complete immunity to noise. But this cable is very expensive as compared to the
coaxial cable.
(b) LAN – LocalArea Network
OSI – Open Systems Interconnection.
(c) Telnet is an Internet facility that facilitates remote login.
(d) (i) Advantages of STAR topology
1. One Device per connection
2. Easy to access
Disadvantages of STAR topology
1. Long cable length
2. Central node dependency
(ii) Advantages of TREE topology
1. Easy to extend
2. Fault isolation is easy
Disadvantages of TREE topology
1. Dependent on the root computer
2. Complex access protocols

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

You might also like