Sei sulla pagina 1di 10

Examination Papers, 1999

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

1. (a) Why main function is special ? Give two reasons. 2


(b) Name the header files of C++ to which the following functions belong : 2
(i) strcat (ii) scanf (iii) getchar (iv) clrscr
(c) Find syntax error(s), if any, in the following programs : 2
#include<iostream.h>
main()
{
int x[5], *y, z[5];
for (i = 0; i < 5; i++)
{
x[i] = i;
z[i] = i+3;
y=z
x = y;
}
}
(d) Give the output of the following program : 2
void main() {
char *p = "Difficult";
char c;
c =++ *p++;
printf(“%c”, c);
}
(e) Write the output of he following program : 3
#include <iostream.h>
static int i = 100;
void abc() {
static int i = 8;
cout << "first=" <<i;
}
main() {
static int i = 2;
abc();
cout << "second=" << i << endl;
}
(f) Write a C++ function that converts a 2-digit octal number into binary number and prints the binary
equivalent. 4
Ans. (a) (i) Whenever a C++ program is executed, only the main() is executed. The execution of a program
starts and ends at main() .
(ii) The main() is the driver function of the program. If it is not included in the program, no
execution can take place.
(b) (i) string.h (ii) stdio.h (iii) stdio.h (iv) conio.h
(c) #include <iostream.h>

Examination Paper 1
main()
{ int x[5], *y, z[5], i; // Error 1
for (i = 0; i< 5; i++) // Error 2
{ x[i] = i;
z[i] = i+3;
y = z;
x = y; // Error 3
}
}
Error 1 : Semicolon missing (;)
Error 2 : Declaration syntax error, i is not declared and for statement does not closed
Error 3 : lvalue required
(d) The output is : E
(e) The output is : First = 8 second = 2
(f) // Function to convert a 2-digit octal number into binary number
void octal_to_binary(int octal) {
long binary = 0;
int decimal;
int X[10];
int d1, d2, b12, b2, q, r;
// Convert the number into decimal
d1 = octal;
int i = 0;
while (d1 >= 10) {
q = d1 / 10;
r = d1 % 10;
X[i] = q;
d1 = r;
if (d1 <= 10)
{
i++;
X[i] = r;
}
else
i++;
}
int j = i;
char *strn = “ “;
char *tstrn= “ “;
// Steps to convert the array numbers into a whole integer
// For example, suppose the octal number is 14
// then, its decimal is X[1] = 4 and X[2] = 1
// so, the number will be 41 by the following steps :
for (i = j; i >= 0; i—) {
strn = (itoa(X[i], strn,10));
tstrn = strcat(tstrn, strn);
}
// Then again the string character converted into decimal number
decimal = atoi(tstrn);
// Convert the number into decimal
d1 = decimal;
i = 0;
while (d1 >= 2) {
q = d1 / 2;

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


r = d1 % 2;
X[i] = r; // Stores the remainder in array
d1 = q;
if (d1 < 2) {
i++;
X[i] = d1; // Stores the last remainder in array X
}
else
i++;
}
j = i;
cout << "\nThe binary equivalent of octal number ";
for (i = j; i >= 0; i --) {
cout << X[i] << “ “;
}
}
2. (a) What do you understand by visibility modes in class derivations ? What are these modes ? 2
(b) Define a class Teacher with the following specifications : 4
private members :
name 20 characters
subject 10 characters
Basic, DA, HRA float
Salary float
Calculate() function computes the salary and returns it. Salary is sum of Basic, DA, and HRA.
public members :
Readdata() function accepts the data values and invoke the Calculate function.
Displaydata() function prints the data on the screen.
(c) Consider the following declarations and answer the questions given below : 4
class vehicle {
int wheels;
protected:
int passenger;
public:
void inputdata(int, int);
void outputdata();
};
class heavy_vehicle : protected vehicle {
int diesel_petrol;
protected:
int load;
public:
void readdata(int, int);
void writedata();
};
class bus : private heavy_vehicle {
char make[20];
public:
void fetchdata(char);
void displaydata();
};
(i) Name the base class and derived class of the class heavy_vehicle.
(ii) Name the data member(s) that can be accessed from function displaydata.
(iii) Name the data member(s) that can be accessed by an object of bus class.

Examination Paper 3
(iv) Is the member function outputdata accessible to the objects of heavy_vehicle class ?
Ans. (a) A visibility mode specifies whether the features of the base class are privately derived, protectedly
derived or publicly derived. The default visibility mode is private. There are three visibility modes:
(i) A member (either data member or member function) declared in a private: section of a class can
only be accessed by member functions and of that class.
(ii) A member (either data member or member function) declared in a protected section of a class
can only be accessed by member functions and of that class, and by member functions and of
derived classes.
(iii) A member (either data member or member function) declared in a public: section of a class can
be accessed by anyone.
(b) // Class and function declaration of teacher class
class Teacher {
char Name[20];
char Subject[10];
float Basic, DA, HRA;
float Salary;
float Calculate() {
return (Basic + DA + HRA);
}
public :
void Readdata() {
cout << "Enter teacher name : ";
gets(Name);
cout << "Enter subject : ";
gets(Subject);
cout << "Enter basic salary : ";
cin >> Basic;
cout << "Enter DA : ";
cin >> DA;
cout << "Enter HRA : ";
cin >> HRA;
Salary = Calculate();
}
void Dispdata() {
cout << "Teacher name : " << Name<<endl;
cout << "Subject is : " << Subject << endl;
cout << "Basic Salary : " << Basic<<endl;
cout << "DA is : " << DA<<endl;
cout << "HRA is : " << HRA << endl;
cout << "Netpay is : " << Salary<<endl;
}
};
(c) (i) Base class : vehicle
(ii) make and load
Derived class : heavy_vehicle
(iii) readdata(), writedata()
(iv) No
3. (a) Suppose an one dimensional array AR containing integers is arranged in ascending order. Write a
user defined function in C++ to search for one integer from AR with the help of binary search method,
returning an integer 0 to show absence of the number and integer 1 to show presence of the number
in the array. The function should have three parameters : 4
(i) and array AR

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


(ii) the number to be searched and
(iii) the number of elements N in the array.
(b) An array A[10][20] is stored in the memory with each element requiring 2 bytes of storage. If the base
address of array in the memory is 400, determine the location of A[8][13] when the array is stored as
(i) Row major (ii) Column major. 3
(c) Write a User defined function in C++ to display the multiplication of row element of two dimensional
array A[4][6] containing integer. 2
(d) Evaluate the following postfix expression using a stack and show the contents of the stack after
execution of each operation :
5, 11, -, 6, 8, +, 12, *, /. 2
(e) Give the necessary declaration of a linked list implemented queue containing float type elements.
Also write a user defined function in C++ to delete a float type number from the queue. 4
Ans. (a) // This function search an element in an array using binary search.
int binary(int AR[10], int data ,int n) {
int i, flag = 0, first = 0, last, pos = 1, mid;
last = n - 1;
while ((first <= last) && (flag == 0)) {
mid = (first + last) / 2;
if (AR[mid] == data) {
pos = pos + mid;
flag = 1;
}
else
if (AR[mid] < data)
first = mid + 1;
else
last = mid - 1;
}
if (flag == 1)
return(1);
else
return(0);
}
(b) B = 400
w=2
(i) Row major order
n = 20
A[8][13] = 400 + 2 * (20( 8 - 1) + (13 - 1))
= 400 + 2 * (20 * 7 + 12)
= 400 + 2 * (140 + 12)
= 400 + 2 * (152)
= 400 + 304 = 704
(ii) Column major order
m = 10
A[8][13] = 400 + 2 * (( 8 - 1) + 10 * (13 - 1))
= 400 + 2 * (7 + 10 * 12)
= 400 + 2 * (7 + 120)
= 400 + 2 * 127
= 400 + 254
= 654

Examination Paper 5
(c) // Function to calculate the multiplication of row elements
void Row_mult(int A[4][6]) {
int mult, i, j;
for (i=0; i<4; i++) {
mult = 1;
for (j = 0; j<6; j++)
mult = mult * A[i][j];
cout << "Multiplication of row : " << i+1 << " is : " << mult << endl;
}
}
(d) The stack operation is :
Scanned elements Operation Stack
5 PUSH 5 5
11 PUSH 11 5, 11
- POP 11
POP 5
Calculate 5-11=-6
PUSH –6 -6
6 PUSH 6 -6, 6
8 PUSH 8 -6, 6, 8
+ POP 8
POP 6
Calculate 6+8=14
PUSH 14 -6, 14
12 PUSH 12 -6, 14, 12
* POP 12
POP 14
Calculate 14*12=168
PUSH 168 -6, 168
/ POP 168
POP –6
Calculate –6/168 = -1/28
PUSH –1/28 -1/28
∴Ans = -1/28
(e) // Declares a queue structure
struct node {
float data;
node *link;
};
// Function body for delete queue elements
node *del_Q(node *front, float &val) {
node *temp;
clrscr();
if (front == NULL) {
cout << “Queue Empty “;
val = -1;
} else {
temp = front;
front = front->link;
val = temp->data;

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


temp->link = NULL;
delete temp;
}
return (front);
}
4. (a) Differentiate between function read() and write(). 1
(b) Assume the class FLOPPYBOX, write functions in C++ to perform the following : 4
(i) Write the object of FLOPPYBOX on to a binary file.
(ii) Read the objects of FLOPPYBOX from the binary file and display on the screen
class FLOPPYBOX {
int size;
char name[10];
public:
void getdata() {
cin >> size;
gets(name);
}
void showdata() {
cout << size << " " << name << endl;
}
}
Ans. (a) The read() function is used to read block of data from the file while the write() function is used to write
the block of data on the file.
(b) (i) // Function to write the object of class to the binary file
void create(FLOPPYBOX floppy) {
ofstream afile;
afile.open("Floppy.dat", ios::out | ios :: binary);
if (!afile) {
cout << " \n Unable to open the file ";
exit(1);
}
floppy.getdata();
afile.write((char *)&floppy, sizeof(floppy));
afile.close();
}
(ii) // Function to read the object of class from the
// binary file
void read_file() {
ifstream afile;
afile.open("Floppy.dat", ios::in | ios :: binary);
if (!afile) {
cout << " \n File does not exists ";
exit(1);
}
FLOPPYBOX floppy;
while(afile) {
afile.read((char *) &floppy, sizeof(floppy));
floppy.showdata();
}
afile.close();
}
5. (a) What is normalization ? Define second normal form. 2

Examination Paper 7
Write SQL commands for (b) to (g) and write output for (f) on the basis of Teacher relation given
below :
TABLE :TEACHER
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
No. Name Age Department Date_of_join Salary Sex
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1. Jugal 34 Computer 10/01/97 12000 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
2. Sharmila 31 History 24/03/98 20000 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
3. Sandeep 32 Maths 12/12/96 30000 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
4. Sangeeta 35 History 01/07/99 40000 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
5. Rakesh 42 Maths 05/09/97 25000 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
6. Shyam 50 History 27/06/98 30000 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
7. Shiv Om 44 Computer 25/02/97 21000 M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
8 Shalakha 33 Maths 31/07/97 20000 F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
(b)To show all information about the teacher of History department. 1
(c)To list the names of female teachers who are in Maths department. 1
(d)To list the names of all teachers with their date of joining in ascending order. 1
(e)To display teacher’s Name, Salary, Age for male teachers only. 1
(f)To cout the number of teacher’s with age < 23. 1
(g)To insert a new row in the TEACHER table with the following data :
9, “Raja”, 26, “Computer”, {13/05/95}, 23000, “M” 1
(h) Give the output of the following SQL statement : 2
(i) Select COUNT(distinct department) from TEACHER;
(ii) Select MAX(Age) from TEACHER where SEX = “F”;
(iii) Select AVG(Salary) fromTEACHER where SEX = “M”;
(iv) Select SUM(Salary) from TEACHER where Date_of_join < {12/07/96};
Ans. (a) Normalization is a process of data analysis used for grouping data elements in a record. While
dealing with databases there may be unnecessary repetition of data, which can pose problems in
storing, and retrieving of data. The unnecessary repetition of data is called redundancy. Second
normal form :A table is said to be in 2NF if it is in first normal form and each non-key attribute depends
on the entire key.
(b) SELECT * FROM TEACHER WHERE department = “History” ;
(c) SELECT name FROM TEACHER WHERE department = “Math” and SEX = “F” ;
(d) SELECT name FROM TEACHER
ORDER BY dateofjoin;
(e) SELECT name, salary, age FROM TEACHER
WHERE sex = “F” ;
(f) SELECT COUNT(*) FROM TEACHERWHEREAGE < 23;
(g) INSERT INTO TEACHER
VALUES (9, “Raja”, 26, “Computer”, {13/05/95}, 2300, “M”) ;
(h) (i) 3 (ii) 35 (iii) 23600 (iv) 0
6. (a) State the distributive law. Verify the law using truth table. 2
(b) Prove x+x’y = x+y algebraically. 2
(c) Write the dual of the Boolean expression (x+y).(x’+y’). 1
(d) Minimise F(w, x, y, z) using Karnaugh map.
F(w,x,y,z) = Σ(0, 4, 8, 12) 2

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


(e) Draw logic circuit for half adder. 1
(f) Represent the Boolean expression (x+y)(y+z)(z+x) with the help of NOR gates only. 1
(g) Write sum of product form of the function F(x,y,z). The truth table representation for the function F
is given below : 1
x y z F
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
Ans. (a) The distributive laws states
(i) 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

X Y Z Y+Z XY XZ X(Y+Z) XY+XZ


0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 1 0 1 1 0 1 1
1 1 1 1 1 1 1 1
Both the columns X(Y+Z) and XY+YZ are identical, hence proved.
(b) R.H.S = x + y = x + y[x + x’] [ x + x’ = 1]
= x + xy + x’y = x[1 + y] + x’y
= x + x’y = L.H.S [ 1 + X = 1]
(c) x.y + x’.y’
(d) YZ
WX 00 01 11 10
00 1
01 1
11 1
10 1
F = Y’Z’

Examination Paper 9
(e) The logic circuit for a half adder is :
x sum = x + y
y

carry = x . y

(f) The Boolean expression (x+y)(y+z)(z+x) using NOR gate is :


x x+y
y

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

z z+x
x
(g) F(x,y,z) = x’yz’+ xy’z’ + xyz’ + xyz
7. (a) What is a bridge ? 1
(b) What is the purpose of using FTP ? 1
(c) Give two advantages and two disadvantages of following network topologies : 2
(i) Star (ii) Tree
(d) What is the difference between WAN and MAN ? 1
Ans. (a) A bridge device filters data traffic at a network boundary. Bridges reduce the amount of traffic on a
LAN by dividing it into two segments.
(b) FTP is the protocol or set of rules, which enables files to be transferred between computers. FTP is
a powerful tool which allows files to be transferred from “computerA” to “computer B”, or vice versa.
(c) (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.
(d) The difference between WAN and MAN are :
(i) In MAN the distance between the nodes is limited i.e; up to one small city or town. But there is
no upper limit in WAN.
(ii) WAN operate at much higher speed than MAN.

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

Potrebbero piacerti anche