Documente Academic
Documente Profesional
Documente Cultură
[Delhi]
Maximum Marks : 70
Note.
Duration : 3 Hours
2
2
2
#include <iostream.h>
void main( )
{
int x;
cin << x;
for (int y=0; y<10; y++);
cout >> x+y;
}
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=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
(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
last
array of character
60
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
Phone
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;}
};
Examination Paper
(c)
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. Dont write any code. Assume as if you are using push and pop member
functions of the stack.
3
ABCD+E*+ (whereA =5, B=3, C=5, D=4 and E=2)
(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++;
}
}
Examination Paper
(9) +
20
Pop (18)
Pop (2)
Push (18+2)
(d) A[I][J] = B+W((IL1)+M(JL2))
B = C0
A[10][5] = C0 +1((101) + 20(51))
2000 = C0 +1(9+20 x 4)
2000 = C0 +89
C0 = 200089 = 1911
(e) Using bubble sort, the sequence of steps are :
1st iteration :
42
29
Swap
29
42
No
74
74
change
11
11
65
65
58
58
29
29
42
42
11
11
74
65
Swap
65
74
Swap
58
58
2nd iteration :
No
29
29
change
Swap
42
42
11
11
65
65
58
58
74
74
3rd iteration :
29
29
Swap
11
11
42
42
58
58
No
65
65
change
74
74
4. (a) What is the difference between get( ) and read( ) ?
29
42
74
11
65
58
29
42
11
65
58
74
29
11
42
65
58
74
Swap
No
change
29
11
42
65
58
74
Swap
11
29
42
58
65
74
1
(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;
}
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
No ItemName
CostPerItem Quantity DateofPurchase Warranty Operational
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
1
Computer
60000
9
21/05/96
2
7
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
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
7
Plotter
25000
2
11/1/2000
2
2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
(b)
(c)
(d)
(e)
(f)
(g)
1
1
1
1
1
1
Examination Paper
Y+Z
X+Y
X+(Y+Z)
(X+Y)+Z
Hence proved.
(ii)
Y.Z
X.Y
X.(Y.Z)
(X.Y).Z
Hence proved.
(b) L.H.S = XY + YZ + YZ' = XY + Y(Z+Z')
= XY + Y = Y(X + 1) = Y
(c) F(x, y, z) = (2, 3, 6, 7)
yz
x
00
01
0
1
F=Y
(d) The truth table of Full Adder is :
[ X + X' = 1]
[ X + 1 = 1]
11
1
10
1
sum
carry
sum = x + y + z
carry = x . y + x . z + z . y
Examination Paper
(e) X(Y'+Z)
Take the double complement.
= [X(Y'+Z)]''
= [X'+(Y'+Z)']'
i.e.,
Xy
Yy
Z
X'
F
Y'
(Y'+Z)'