Sunteți pe pagina 1din 10

Examination Papers, 2001

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

1. (a) Encapsulation is one of the major properties of OOP. How is it implemented in C++ ? 2
(b) Name the header file to be included for the use of following built-in functions.
(i) frexp() (ii) toupper() 1
(c) Identify the syntax error(s), if any (giving reason for error) :
class ABC
{
int x = 10;
float y;
ABC( ) {y = 5; }
~ABC() { }
};
void main()
{
ABC a1, a2;
} 2
(d) Give the output of the following program (Assume all required header files are included in the
program) :
void main()
{
int array[] = {2, 3, 4, 5};
int *arptr = array;
int value = *arptr; cout << value << '\n';
value = *arptr++; cout << value << '\n';
value = *arptr; cout << value << '\n';
value = *++arptr; cout << value << '\n';
} 2
(e) Give the output of the following program :
#include <iostream.h>
int global = 10;
void func(int &x, int y)
{ x = x – y; y = x * 10;
cout << x << ‘,’ << y << '\n';
}
void main()
{
int global = 7;
func(::global, global);
cout << global << ',' << ::global << '\n';
func(global, ::global);
cout << global << ',' << ::global << '\n';
} 3
(f) Write a function named SUMFUN(), with arguments n and N, which returns the sum of the following
series : x2 x3 x4 x5 x6 xn 4
1– + – + – +.....+
2 3 4 5 6 N
Examination Paper 1
Ans. (a) OOP encapsulates data (attributes) and functions (behaviour) into packages called objects; the data
and functions of an object are intimately tied together. Objects have the property of information
hiding.
(b) (i) math.h (ii) ctype.h
(c) The errors are :
class ABC
{
int x = 10; // Error 1
float y;
ABC( ) {y = 5; }
~ABC() { }
};
void main()
{
ABC a1, a2; // Error 2
}
Error 1 : Cannot initialize a class member here
Error 2 : ABC::ABC() is not accessible
Destructor for ABC is not accessible
a1 is assigned a value that is never used.
(d) The output is as :
2
2
3
4
(e) The output is as :
3, 30
7, 3
4, 40
4, 3
(f) // Function to find the sum of series
float SUMFUN(int x, int N)
{
float s = 1, t = 0, t1, t2;
int i,j=1;
for(i=2;i<(N+1);i++)
{
t = pow(-1,j);
t1 = pow(x,i)/i;
t2 = t * t1;
s = s + t2;
j++;
}
return(s);
}
2. (a) Illustrate the use of “self-referential structures” with the help of an example. 4
(b) Define a class BOOK with the following specifications :
Private members of the class BOOK are
BOOK_NO integer type
BOOK_TITLE 20 characters
PRICE float (price per copy)

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


TOTAL_COST() A function to calculate the total cost for N number of copies, where N is passed to
the function as argument.
Public members of the class BOOK are
INPUT() Function to read BOOK_NO, BOOK_TITLE, PRICE
PURCHASE() Function to ask the user to input the number of copies to be purchased. It invokes
TOTAL_COST() and prints the total cost to be paid by the user.
Note : You are also required to give detailed function definitions. 5
(c) Give the output of the following program :
#include <iostream.h>
#include <string.h>
class per
{
char name[20];
float age;
public :
per(char *s, float a)
{
strcpy(name, s); age = a;
}
per &GR(per &x)
{
if (x.age >= age) return x;
else
return *this;
}
void display()
{
cout << "Name :" << name <<'\n';
cout << "Age :" << age << '\n';
}
};
void main()
{
per P1("RAMU", 27.5), P2("RAJU", 53), P3("KALU", 40);
per P('\0',0);
P = P1.GR(P3); P.display();
P = P2.GR(P3); P.display();
} 4
Ans. (a) A structure containing a member that is a pointer to the same structure type is referred to as a self-
referential structure. Self-referential structures are useful for forming lined data structures such as
linked lists, queues, stacks and trees. For example,
Time timeObject, timeArray[10], *typePtr;
&timeRef = timeObject;
declares timeObject to be a variable of type Time, timeArray to be an array with 10 elements of type
Time, timePtr to be a pointer to a Time object and timeRef to be a reference to a Time object that
initialized with timeObject.
(b) // A class BOOK with data members and member functions
class BOOK
{
int BOOK_NO;
char BOOK_TITLE[20];
float PRICE;
float TOTAL_COST(int N);

Examination Paper 3
public:
void INPUT();
void PURCHASE();
};
float BOOK::TOTAL_COST(int N)
{
return(PRICE*N);
}
void BOOK::INPUT()
{
cout<<"Enter the book number ";
cin>>BOOK_NO;
cout<<"Enter the book title ";
gets(BOOK_TITLE);
cout<<"Enter the price of the book ";
cin>>PRICE;
}
void BOOK::PURCHASE()
{
int N;
cout << "Input the number of copies to be purchased ";
cin>>N;
cout<<"The Total cost to be paid is "<<TOTAL_COST(N);
}
(c) The output is as :
Name :KALU
Age :40
Name :RAJU
Age :53
3. (a) Given two arrays of integers A and B of sizes M and N respectively. Write a function named MIX()
which will produce a third array named C, such that the following sequence is followed.
(1) All even numbers of A from left to right are copied into C from left to right.
(2) All odd numbers of A from left to right are copied into C from right to left.
(3) All even numbers of B from left to right are copied into C from left to right.
(4) All odd numbers of B from left to right are copied into C from right to left.
A, B and C are passed as arguments to MIX().
e.g., A is {3, 2, 1, 7, 6, 3} and B is {9, 3, 5, 6, 2, 8, 10}
the resultant array C is {2, 6, 6, 2, 8, 10, 5, 3, 9, 3, 7, 1, 3} 4
(b) An array X[7][20] is stored in memory with each element requiring 2 bytes of storage. If the base
address of the array is 2000, calculate the location of X[3][5] when the array X is stored in Column
major order. 2
Note : X[7][20] means valid row indices are 0 to 6 and valid column indices are 0 to 19.
(c) Write a user defined function named Upper_half() which takes a two dimensional array A, with sizeN
rows and N columns as argument and print the upper half of the array. 3
e.g.,
2 3 1 5 0 2 3 1 5 0
7 1 5 3 1 1 5 3 1
If A is 2 5 7 8 1 The output will be 7 8 1
0 1 5 0 1 0 1
3 4 9 1 5 5

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


(d) Convert the expression (TRUE && FALSE) ||! (FALSE || TRUE) to postfix expression. Show the
contents of the stack at every step. 2
(e) Each node of a STACK contains the following information, in addition to pointer field :
(i) Roll number of the student
(ii) Age of the student
Give the structure of node for the linked stack in question.
TOP is a pointer points to the topmost node of the STACK. Write the following functions:
(i) PUSH() – To push a node into the stack, which is allocated dynamically
(ii) POP() – To remove a node from the stack, and release the memory 4
Ans. (a) // Function MIX() produces a third array
void MIX(int A[],int B[],int C[],int m,int n)
{
int l = 0;
int r = (m+n–1);
for(int i=0;i<m;i++)
{
if ((A[i] % 2)== 0)
{
C[l]=A[i];
l++;
}
else
{
C[r] = A[i];
r––;
}
}
for( i=0;i<n;i++)
{
if ((B[i] % 2) == 0)
{
C[l] = B[i];
l++;
}
else
{
C[r] = B[i];
r––;
}
}
}
(b) Here, w = 2
B = 2000
m=7
X[I][J] = B + w((I-L1) + m(J–L2))
= 2000 + 2((3-0) + 7(5–0))
= 2000 + 2(3+(7*5))
= 2000 + 2 (3 + 35)
= 2000 + 2 * 38
= 2000 + 76
= 2076

Examination Paper 5
(c) // Function Upper_half() which produces the upper half of an array.
void Upper_half(int A[10][10],int n)
{
int k = 0, j, row = 8, col = 1;
for(int i=0;i<n;i++)
{
col = i+1;
row++;
for( j=i;j<n;j++)
{
gotoxy(col,row);
cout<<A[i][j]<< " ";
col++;
}
}
}
(d) The stack operation is :
Operation Stack Status Output
( (
TRUE ( TRUE
&& (&&
FALSE (&& TRUE FALSE
) – TRUE FALSE &&
| | TRUE FALSE &&
! || ! TRUE FALSE &&
( || ! ( TRUE FALSE &&
FALSE || ! ( TRUE FALSE && FALSE
| || ! ( || TRUE FALSE && FALSE
TRUE || ! ( || TRUE FALSE && FALSE TRUE
) || ! TRUE FALSE && FALSETRUE ||
| TRUE FALSE && FALSETRUE || !
Empty stack TRUE FALSE && FALSETRUE || ! ||
(e) // The structure, PUSH() and POP() function of the stack.
// Declares a stack structure
struct node
{
int roll;
int age;
node *link;
};
// Function body for add stack elements
node *push(node *top, int val,int tage)
{
node *temp;
temp = new node;
temp->roll = val;
temp->age = tage;
temp->link = NULL;
if(top ==NULL)
top = temp;
else

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


{
temp->link = top;
top = temp;
}
return(top);
}
// Function body for delete stack elements
node *pop(node *top)
{
node *temp;
int tage, val,
clrscr();
if (top == NULL )
{
cout<<"Stack Empty ";
}
else
{
temp = top;
top = top->link;
val = temp->roll;
tage = temp->age;
temp->link = NULL;
cout<<“\n\tPopped Roll Number is “<<temp->roll;
cout<<“\n\tPopped Age is “<<temp->age;
delete temp;
}
return (top);
}
4. (a) Distinguish between Serial files and Sequential files. 1
(b) Consider the class declaration
class BUS
{
int bus_no;
char destination[20];
float distance;
public :
void Read(); // To read an object from the keyboard
void Write(); // To write an object into a file,
void Show(); // To display the file contents on the monitor
};
Complete the member functions definitions. 4
Ans. (a) Serial file. There is no significance of key field. Records are stored in the order of their arrival.
Sequential file. The key field plays an important role in sequential file. Records are stored in a
specific order of key field.
(b) // The complete member function definitions are :
void BUS::Read()
{
cout << "Enter the value of the flight number ";
cin >> bus_no;
cout << "Enter the value of the destination ";
gets(destination);
cout << "Enter the value of the distance ";
cin >> distance;
}

Examination Paper 7
void BUS :: Write(BUS F)
{
fstream Ffile;
Ffile.open("Bus.dat",ios::app);
Ffile.write((char *)&F,sizeof(BUS));
Ffile.close();
}
void BUS::Show()
{
cout << "\n Flight No : "<<bus_no;
cout << "\n Destination : "<<destination;
cout << "\n Distance : "<<distance;
}
5. (a) What are DDL and DML ? 2
(b) Write SQL commands for (i) to (vii) on the basis of the table STUDENT
Table : STUDENT
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
Student No. Class Name GAME Grade SUPW Grade
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
10 7 Sameer Cricket B Photography A
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
11 8 Sujit Tennis A Gardening C
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
12 7 Kamal Swimming B Photography B
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
13 7 Veena Tennis C Cooking A
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
14 9 Archana Basketball A Literature A
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
15 10 Arpit Cricket A Gardening C
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
(i) Display the names of the students who are getting grade ‘C’ in either GAME or SUPW. 1
(ii) Display the number of students getting grade ‘A’ in Cricket. 1
(iii) Display the different games offered in the school. 1
(iv) Display the SUPW taken up by the students, whose name starts with ‘A’. 1
(v) Add a new column named ‘Marks’. 1
(vi) Assign a value 200 for Marks for all those who are getting grade ‘B’ or above in GAME. 1
(vii) Arrange the whole table in the alphabetical order of SUPW. 1
(c) If R1 is a relation with 5 rows and R2 is a relation with 3 rows, how many rows will the Cartesian
product of R1 and R2 have ? 1
Ans. (a) DDL. DDL is the part of SQL. It stands for data definition language. It provides statements for
creation and deletion of the database. For example, CREATE TABLE, ALTER TABLE.
DML. DML is also the part of the SQL. It stands for data manipulation language. It provides statements
for manipulating the database. It includes commands to insert, delete and modify tuples in the
database. For example, INSERT INTO, DELETE FROM, UPDATE.
(b) (i) SELECT name FROM student WHERE grade = ‘C’ OR grade1 = ‘C’
(ii) SELECT COUNT(grade) FROM student WHERE grade = ‘A’AND game = ‘Cricket’
(iii) SELECT DISTINCT game FROM student
(iv) SELECT supw FROM student WHERE name LIKE ‘A%’
(v) ALTER TABLE studentADD (marks NUMBER(3))
(vi) UPDATE student SET marks = 200 WHERE grade IN (‘A’, ‘B’)
(vii) SELECT * FROM student ORDER BY supw
(c) 15
6. (a) State and verify Involution law. 2

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


(b) Prove algebraically 2
X.Y + X'.Z +Y.Z = X.Y + X'.Z
(c) If F(a, b, c, d) = Σ(0, 2, 4, 5, 7, 8, 10, 12, 13, 15), obtain the simplified form using K-Map. 2
(d) Represent NOT using only NOR gate(s). 1
(e) Given the following circuit
y
y
What is the output if
(i) both inputs are FALSE 1
(ii) one is FALSE and the other is TRUE 2
(f) Draw a circuit of a Half Adder using only NAND gates. 2
Ans. (a) This law states that (X')' = X
If X = 1 then If X = 0 then
X' = 0 X' = 1
(X')' = 1 = X (X')' = 0 = X
(b) L.H.S = X.Y + X'.Z +Y.Z
= X.Y + Y'.Z + (X + X') Y.Z
= X.Y + X'.Z + X.Y.Z + X'.Y.Z
= (X.Y + X.Y.Z) + (X’.Z + X’.Y.Z)
= X.Y + Y'.Z
(c) The Karnaugh map for F(a, b, c, d) = Σ(0, 2, 4, 5, 7, 8, 10, 12, 13, 15) is :
cd
ab 00 01 11 10
00 1 1
01 1 1 1
11 1 1 1
10 1 1
F (a, b, c, d) = c'd' + bd + b'cd'
(d) The representation of NOT using only NOR gate(s) is :
x
x

(e) (i) When both intputs are FALSE :


FALSE y TRUE FALSE
FALSE y
(ii) When both intputs are FALSE :

FALSE y FALSE TRUE


TRUE y
Q.7. (a) What are routers ? 1
(b) What are backbone networks ? 1
(c) Name two switching circuits and explain any one. 2
(d) Mention one difference between Circular and Star topologies in networking. 1

Examination Paper 9
Ans. (a) On Internet it is not necessary that all the packets will follow the same path from source to destination.
A special machine called router tries to load balance between various paths that exist on networks.
(b) When we connect number of LANs to from one WAN the network, which is used as a backbone to
connect the LANs is called backbone network.
(c) The two switching circuits are : Circuit switching and Message switching.
Circuit Switching : In this technique, first complete physical connection between two computers is
established and then data is transmitted from the source computer to the destination computer.
(d) The circular topology has :
Short cable length. In circular topology less connections will be needed which increase network
reliability. The amount of cable needed in this topology is comparable to bus and small relative to star
topologies.
The star topology has : One Device per connection and Long cable length.

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

S-ar putea să vă placă și