Sunteți pe pagina 1din 13

Examination Papers, 2000

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

1. (a) Illustrate the use of this pointer with the help of an example. 2
(b) Name the header file, to which following built- in function belong : 2
(i) strcpy() (ii) isdigit() (iii) log() (iv) puts()
(c) Will the following program execute successfully ? If not, state the reason(s). 2
#include<iostream.h>
void main()
{
int x, sum = 0;
cin<<n;
for (x=1, x<100, x+=2)
if x % 2= =0
sum+=x;
cout<<"SUM=">>sum;
}
(d) Give the output of the following program segment(Assume all required header files are included in
the program) : 2
char *s = "GOODLUCK";
for (int x = 0;x<strlen(s)–1 ; x>=0; x––)
{
for ( int y=0; y<=x; y++) cout<<s[y];
cout<<endl;
}
(e) Write the output of the following program : 3
#include<iostream.h>
int a=3;
void demo(int x, int y, int &z)
{
a += x+y;
z = a+y;
y += x;
cout<<x<<y<<z<<endl;
}
void main()
{
int a=2, b=5;
demo(: :a, a, b);
cout<<: : a <<a<<b<<endl;
demo(: : a , a, b );
}
(f) Write a function sum() in C++ with two arguments, double x and int n. The function should return
a value of type double and it should find the sum of the following series : 4
1 + x/1! + x3/2! + x5/3! + x7/4! + x9/5! + … + x2n-1/n!

Examination Paper 1
Ans. (a) While manipulating objects for user programs, C++ maintains an internal pointer called this, to point
to the current object being operated upon. Whenever a member function of an object is called, the
compiler places the address of the object in pointer this before invoking the function. For example :
class xyz {
int a;
public:
void read();
{
cin>>a;
}
void display()
{
cout<<"\n a = "<<this->a;
}
};
In the above class xyz, a pointer this has been used to print the value of an even though the pointer
has not been declared anywhere.
(b) (i) strcpy() : string.h
(ii) isdigit() : ctype.h
(iii) log() : math.h
(iv) puts() : stdio.h
(c) The correct program is :
# include<iostream.h>
main()
{
int x,sum = 0;
int n;
cin>>n;
for (x = 1; x < 100;x+=2)
if( x%2 == 0)
sum += x;
cout << "SUM = " << sum;
}
Correction 1 : Undefined symbol ‘n’
Correction 2 : Illegal structure operation cin<<n
Correction 3 : for statement missing ( for x = 1, x<100;x+=2)
Correction 4 : If statement missing if x%2 == 0
Correction 5 : Illegal structure operation cout>> “SUM = ” >>sum;
(d) The output is :
GOODLUCK
GOODLUC
GOODLU
GOODL
GOOD
GOO
GO
G
(e) The output of the given program is :
3510
8210
81020

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


(f) The function is :
int fact(int num)
{
double prod=1;
int i=1;
while(i<=num)
{
prod=prod*i;
i++;
}
return(prod);
}
double sum(double x, int n)
{
double s;
s = 1;
double t=0;
int i,j = 1;
for(i=1;i<n;i++)
{
t = pow(x,j);
s = s + t / (fact(i));
j = j + 2;
}
return(s);
}
2. (a) What is the use of a constructor function in a class ? Give a suitable example of a constructor
function in a class. 2
(b) Define a class report with the following specification : 4
Private members :
adno 4 digit admission number
name 20 characters
marks an array of 5 floating point values
average average marks obtained
getavg() to compute the average obtained in five subjects
Public members :
readinfo() function to accept values for adno, name, marks, and invoke the function getavg().
displayinfo() function to display all data members on the screen you should give function definitions.
(c) Consider the following and answer the questions given below : 4
class A
{
void anyval();
protected :
int x, y;
public :
void getvalA();
void putvalA();
};
class B : protected A
{
int a, b;
protected :
int c, d;

Examination Paper 3
void getvalB;
public :
void putvalB( );
};
class C : public B
{
int P;
protected :
int q;
void getval( );
public :
void showval( );
};
(i) Name all the member functions, which are accessible by the objects of class C.
(ii) Name all the protected members of class B.
(iii) Name the base class and derived class of class B.
(iv) Name the data members, which are accessible from member functions of class C.
Ans. (a) Constructor function is required in classes to create the object. It is used to initialize the data
members of the class. For example :
# include<iostream.h>
class xyz
{
int a,b;
public:
void read();
xyz() //Constructor
{
a = 0;
b = 0;
}
};
(b) The class is :
class report
{
int adno;
char name[20];
float marks[5];
float average;
float getavg( )
{
return ((marks[0] + marks[1] + marks[2] + marks[3] + marks[4])/5);
}
public :
void read_info( );
void displayinfo( );
};
void report :: read_info( )
{
clrscr( );
cout << "Enter the student no. : ";
cin >> adno;
cout << "Enter the student name : ";
gets(name);
cout << "Enter marks in five subject : ";

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


for (int I =0;I<5;I++)
cin >> marks[I];
average = getavg( );
}
void report :: displayinfo( )
{
clrscr();
cout << "Student No. : " << adno << endl
cout << "Student Name : " << name << endl;
for(int I =0;I<5;I++)
cout << "Marks in " << (I+1) << " subject " << marks[I] << endl;
cout << "Average : "<<average<<endl;
}
(c) (i) The member functions, which are accessible by the objects of class C are putval() and showval().
(ii) Protected member of class B : c, d, getvalB(), x, y
(iii) Base class : class A
Derived class : class C
(iv) The data members are : x, y, c, d, p, q.
3. (a) Suppose X, Y, Z are arrays of integers of size M,N and M+N respectively. The numbers in array X and
Y appear in descending order. Write a user defined function in C++ to produce third array Z by
merging arrays X and Y in descending order. 4
(b) An array DATA[1..10][1..10] requires 8 bytes of storage. If the base address of array DATA is 1500,
determine the location of DATA [4][5], when the array DATA is stored
(i) Row Wise (ii) Column wise. 3
(c) What is the pre-condition for applying binary algorithm ? 1
(d) Differentiate between a LIFO list and FIFO list. 1
(e) Evaluate the following postfix expression using a stack. Show the contents of stack after execution
of each operation : 2
TRUE, FALSE, TRUE, FALSE, NOT, OR,TRUE, OR, OR, AND
(f) Give the necessary declarations of a queue containing integers. Write a user defined function in C++
to delete an integer from the queue. The queue is to be implemented as a linked structure. 4
Ans. (a) // Function to manipulation of two arrays X and Y for a merging in third array Z with
// descending order.
const M = 10;
const N = 10;
void merge()
{
clrscr();
int X[M];
int Y[N];
int Z[M+N];
int i,j,k;
cout << "\n\tEnter the first array in descending order\n";
for(i=0;i<M;i++)
{
cout << "\t";
cin >> X[i];
}
cout << "\n\tEnter the second array in descending order\n";
for(i=0;i<N;i++)
{
cout << "\t";

Examination Paper 5
cin>>Y[i];
}
i=0,j=0,k=0;
// Merging the first and second array
while((i<M)&&(j<N))
{
if(X[i]<Y[j])
{
Z[k]=Y[j];
j+=1;
k+=1;
}
else
{
Z[k]=X[i];
i+=1;
k+=1;
}
}
while(i<M)
{
Z[k]=X[i];
i+=1;
k+=1;
}
while(j<N)
{
Z[k]=Y[j];
j+=1;
k+=1;
}
clrscr();
cout << "\n\tThe merged arrays are ";
for(k=0;k<(M+N);k++)
cout<<“\n”<<Z[k];
}
(b) Given :
Base = 1500
W = 8 bytes
N = 10
M = 10
I=4
J=5
To find Row Major Order
The formula is applied :
VAL[I][J]= B +((I-1)* N+(J-1))*W
= 1500+((4-1)* 10 + (5-1))* 8
= 1500 + (34)*8
= 1500 + 272
= 1772 (Ans.)
To find Column Major Order
The formula is applied :
VAL[I][J] = B +((J-1) * M +(I-1)) * W

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


= 1500 +((4-1) + 10 * (5-1)) *8
= 1500 +(43) * 8
= 1500 + 344
= 1844
(c) The precondition for the binary search is that the array should be sorted in advance.
(d) The LIFO stands for Last In First Out. In this data structure, the elements inserted in the last is
deleted first. E.g stack.
The FIFO stands for First In First Out. In this data structure, the element inserted first will delete first,
e.g; queue.
(e) In the given expression true and false are operand and AND, NOT and OR are operator.
(i) true
true
(ii) false
true false
(iii) true
true false true
(iv) false
true false true false
(v) NOT
NOT is operator
POP one operand
NOT false = true
PUSH true on stack
true false true true
(vi) OR
OR is operator
POP TWO operand
Evaluate : true OR true = true
PUSH true on stack
true false true
(vii) true
true false true true
(viii) OR
OR is operator
POP TWO operand
Evaluate : true OR true = true
PUSH true on stack
true false true
(ix) OR
OR is operator
POP TWO operand
Evaluate : true OR false = true
PUSH true on stack
true true
(x) AND
OR is operator
POP TWO operand

Examination Paper 7
Evaluate : true AND true = true
PUSH true on stack
true
(f) // Declares a queue structure
struct node
{
int data;
node *link;
};
// Function body for delete an integer from the queue
node *del_Q(node *front, int &val) {
node *temp;
clrscr();
if (front == NULL) {
cout << "Queue Empty ";
val = -1;
}
else
{
temp = front;
front = front->link;
val = temp->data;
temp->link = NULL;
delete temp;
}
return (front);
}
4. (a) Name the stream classes supported by C++ for file input and output. 1
(b) Consider the following class declaration : 4
class employee
{
int code;
char name [20];
float salary;
public :
void input( ) {cin>>code>>name>>salary;}
void show( ) {cout<<code<<name<<salary<<endl;}
float retsal( ) {return salary;}
};
Give function definitions to do the following :
(i) Write the objects of employee to a binary file.
(ii) Read the objects of employee from a binary file and display all the objects on the screen where
salary is between Rs. 10,000 and Rs. 20,000.
Ans. (a) The stream classes are fstream, ofstream, ifstream.
(b) // Program to demonstrate the file operation
# include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <process.h>
class employee // Class declaration
{
int code; // Private data members

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


char name[20];
float salary;
public : // Public member functions
void input() { cin>>code>>name>>salary; }
void show() { cout << code<<name<<salary<<endl; }
float retsal() { return salary; }
};
// General functioin to operate the class member function
void data_read();
void data_show();
int main()
{
data_read();
data_show();
return 0;
}
void data_read()
{
employee emp; // Declares the employee object
fstream empfile;
empfile.oepn("EMP.dat", ios::app|ios::out|ios::binary); // Creates the data file
int n, i;
clrscr();
cout << "Enter how many records U want to enter ";
cin >> n;
for (i=0; i<n; i++)
{
emp.input();
empfile,write((char *)&emp, sizeof(employee));
}
empfile.close();
}
void data_show()
{
employee emp; // Declares the employee object for read operation
float tsalary = 0.0 // A temporary salary
fstream empfile;
empfile.open("EMP.dat", ios::in|ios::binary);
empfile.seekg(0, ios::beg);
if (!empfile)
cout << "File does not exists";
while (empfile)
{
empfile.read((char *)&emp, sizeof(employee)); // Reads the record one-by-one
tsalary = emp.retsal(); // Transfer the salary into tsalary
if (tsalary >= 10000 && tsalary <= 20000) // Checks the condition
emp.show(); // Display the output through the member function
if (empfile.eof()) // If there is no record, it terminates the loop
exit(0);
}
empfile.close();
}
5. (a) Differentiate between SQL commands DROP TABLE and DROP VIEW. Define Second Normal Form.
2

Examination Paper 9
Write SQL commands for (b) to (f) and write the outputs for (g) on the basis of table GRADUATE :
Table : GRADUATE
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
SNO NAME STIPEND SUBJECT AVERAGE DIV
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
1 KARAN 400 PHYSICS 68 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
2 DIVAKAR 450 COMPUTER SC 68 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
3 DIVYA 300 CHEMISTRY 62 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
4 ARUN 350 PHYSICS 63 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
5 SABINA 500 MATHEMATICS 70 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
6 JOHN 400 CHEMISTRY 55 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
7 ROBERT 250 PHYSICS 64 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
8 RUBINA 450 MATHEMATICS 68 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
9 VIKAS 500 COMPUTER SC 62 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
10 MOHAN 300 MATHEMATIC 57 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345

(b) List the names of those students who have obtained Div 1 sorted by NAME. 1
(c) Display the report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month. 1
(d) To count the number of students who are either PHYSICS or COMPUTER SC graduates. 1
(e) To insert a new row in the GRADUATE table : 1
11, “KAJOL”, 300, “COMPUTER SC “, 75, 1
(f) Give the output of following SQL statement based on table GRADUATE : 2
(i) Select MIN(AVERAGE ) from GRADUATE where SUBJECT= “PHYSICS”;
(ii) Select SUM(STIPEND) from GRADUATE where DIV = 2;
(iii) SelectAVG(STIPEND) fromGRADUATE whereAVERAGE >= 65;
(iv) Select COUNT(DISTINCT SUBJECT) from GRADUATE;
(g) Assume that there is one more table GUIDE in the database as shown below : 2
Table : GUIDE
MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH
What will be the output of the following query :
SELECT NAME, ADVISOR
FROM GRADUATE, GUIDE
WHERE SUBJECT = MAINAREA;
Ans. (a) DROP TABLE DROP VIEW
1. This command drops a table from a 1. This command drops a view (Virtual table with no
database physically. physical data)
2. The condition for dropping a table is 2. Deletion of rows is not necessary.
that it must be an Empty table.

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


Second Normal Form: A table is said to be in 2NF if it is in 1N and each non-key attribute is functionally
dependent on the entire key.
(b) SELECT NAME FROM GRADUATE WHERE DIV = 1 ORDER BY NAME;
(c) SELECT NAME, STIPEND, SUBJECT , STIPEND *12 FROM GRADUTE;
(d) SELECT COUNT(*) FORM GRADUATE
where (SUBJECT = “PHYSICS” OR SUBJECT = “COMPUTER SC”);
(e) INSERT INTO GRADUATE VALUES (11, “KAJOL”, 300, “COMPUTER SC”,75,1);
(f) (i) 63 (ii) 1000 (iii) 450 (iv) 4
(g) NAME ADVISOR
KARAN VINOD
DIVAKAR ALOK
DIVYA RAJAN
ARUN VINOD
SABINA MAHESH
JOHN RAJAN
ROBERT VINOD
RUBINA MAHESH
VIKAS ALOK
MOHAN MAHESH
6. (a) State DeMorgan’s Laws. Verify them using truth table. 2
(b) Prove (A+B). (A'+C) = (A+B+C). (A+B + C'). (A'+B+C). (A'+B'+C)algebraically. 2
(c) Obtain simplified from for a Boolean expression 3
F(X, Y, Z, W) = Σ(0, 1, 4, 5, 7, 8, 9, 12, 13, 15) using K Map method.
(d) Give the truth table for a Full – adder. 1
(e) Draw the circuit diagram for the Boolean function F(X,Y,Z) = (X'+Y)(Y'+Z) using NOR gates only.1
(f) Express in the POS form, the Boolean function F(A,B,C), the truth table for which is given below :1
A B C F
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
Ans. (a) DeMorgan’s Law : This is the most powerful law of Boolean algebra. This states that :
(i) (A + B)' = A'.B'
(ii) (A.B)' = A' + B'

A B A.B (A.B)' A' B' A' + B'


0 0 1 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0

Examination Paper 11
(b) L.H.S = (A + B)(A' + C)
= (A + B + C.C')(A' + C + B.B') [X.X' = 0]
= (A + B + C)(A + B + C')(A' +C + B)(A' + C + B')
= (A + B + C)(A + B + C')(A' + B + C)(A' + B' + C)
(c) F(X, Y, Z, W) = S(0, 1, 4, 5, 7, 9, 12, 13, 15)
ZW
XY 00 01 11 10
00 1 1
01 1 1 1
11 1 1 1
10 1 1

F = Z' + ZW
(d) The truth table for a Full-adder :
A B C 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
(e) Circuit diagram for the Boolean function F(X, Y, Z) = (X' + Y)(Y' + Z) using NOR gates as :

X' (X' + Y)
Y
(X' + Y)(Y'+Z)

Y’

Z (Y' + Z)

(f) (A + B + C)(A + B' + C)(A' + B + C)(A' + B' + C)


7. (a) What are Repeaters ? 1
(b) Name the device used to connect a computer to an analog telephone line. 1
(c) Briefly mention two advantages and two disadvantages of Star topology in network. 2
(d) What is the difference between MAN and WAN ? 1
Ans. (a) Sometimes the signals on the Internet are become weaker before reaching the destination node.
Repeater is used to regenerate data and voice signals when they become weaker before reaching
destination node. Repeater read the incoming signals and amplifies it and transmit to another segment
of the network.

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


(b) MODEM
(c) Advantages of Star Topology :
(i) Ease of service - The star topology has a number of concentration point i.e., at the central node
or at intermediate wiring closets. These provide easy occurs for service or re-configuration of
the network.
(ii) One device per connection : In star topology, failure of a single connection typically involves
disconnecting one node from an other.
Disadvantages of Star Topology :
(i) Long cable length : Because each node in star topology is directly connected to the center, the
star topology requires a large quantity of cable.
(ii) Central node dependency : If the central node fails the network get failed.
(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 upperlimit in WAN.
(ii) WAN operate at much higher speed than MAN.
(iii) MAN provide means for internetworking of local networks.

Examination Paper 13

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