0% found this document useful (0 votes)
214 views10 pages

Examination Papers, 1998: (All India)

The document contains an examination paper for Computer Science (C++) - XII with questions ranging from 2-4 marks covering topics such as object oriented programming, classes and objects, arrays, functions, file handling and SQL. The paper tests knowledge of C++ concepts like constructors, destructors, inheritance, function overloading as well as ability to write programs involving arrays, stacks and file handling. It also includes questions to write SQL queries and understand outputs based on a given table.

Uploaded by

maruthinmdc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views10 pages

Examination Papers, 1998: (All India)

The document contains an examination paper for Computer Science (C++) - XII with questions ranging from 2-4 marks covering topics such as object oriented programming, classes and objects, arrays, functions, file handling and SQL. The paper tests knowledge of C++ concepts like constructors, destructors, inheritance, function overloading as well as ability to write programs involving arrays, stacks and file handling. It also includes questions to write SQL queries and understand outputs based on a given table.

Uploaded by

maruthinmdc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Examination Papers, 1998

[All India]

Maximum Marks : 70
Note.

Duration : 3 Hours

All the questions are compulsory.


Programming Language : C++

1. (a) Write two major differences between Object Oriented Programming and Procedural Programming. 2
(b) Name the header files, to which following built-in functions belong to :
2
(i) isalnum()
(ii) gets()
(iii) fabs()
(iv) strlen()
(c) Find the syntax error(s), if any, in the following program :
2
#include (iostream.h)
void main( )
{
int X, Y;
cin >> X;
for (Y = 0; y < 10, Y++)
If X == Y
cout << Y+X;
else
cout >> Y;
}

(d) Give the output of the following program :

(e) Write the output of the following program :

char *NAME = "CoMPutER";


for (int x = 0; x < strlen(NAME); x++)
if (islower(NAME[x]))
NAME[x] = toupper(NAME[x]);
else
if (isupper(NAME[x]))
if (x%2==0)
NAME[x] = tolower(NAME[x]);
else
NAME[x] = NAME[x-1];
puts(NAME);
#include<iostream.h>
void Execute(int &B, int C = 100)
{
int TEMP = B+C;
B += TEMP;
if(C != 200)
cout << TEMP << B << C << endl;
}
void main ( )
{
int M = 90, N = 10;
Execute(M);
cout << M << N << endl;
Execute(M, N);
cout << M << N << endl;
}

Examination Paper

(f) Write a C ++ function having two value parameters U and n with result type float to find the sum of
series given below :
4
1 U + !U2 1/3! U3 + ! U4 +..... ..+.....
Ans. (a) Procedural Programming :
(i) The emphasis is on doing things rather than data.
(ii) It is based on the sequence of instructions.
Object Oriented Programming :
(i) It emphasises on the data.
(ii) It is based on the principle of data hiding, abstraction, inheritance and polymorphism.
(b) (i) ctype.h
(ii) stdio.h
(iii) math.h
(iv) string.h
(c) The correct program is :
#include <iostream.h>
void main()
{
int X,Y;
cin>>X;
for (Y=0; Y<10; Y++)
If ( X == Y )
cout<<Y+X;
else
cout<< Y;
}

//Correction - 1

// Correction - 2
// Correction - 3
// Correction - 4

Correction 1 : () bracket cannot be used with #include


Correction 2 : In place of , symbol ; should be used and y should be Y
Correction 3 : () bracket was missing with if
Correction 4 : << should be used with cout
(d) The output is : cOmpUTer
(e) The output is as :
190 280 100
280 10
290 570 10
570 10
(f) // Function to find the sum of series of float type
float sum_series(float U, float n)
{
float sum = 1.0, temp;
for (int i = 1; i <= n; i++)
{
P = pow(1, i);
temp = (U, i);
F = 1;
for (int j = 1; j <= i; j++)
F = F * i;
sum += (P * temp) / F;
}
return sum;
}

// Starting series value is 1

2. (a) What do you understand by constructor and destructor functions used in classes ? How are these
functions different from other member functions ?
2

2 Together with Computer Science (C++) XII

(b) Define a class employee with the following specifications :


private members of class employee
empno
integer
ename
20 characters
basic, hra, da
float
netpay
float
calculate()
A function to calculate basic + hra + da with float return type
public member function of class employee
havedata()
function to accept values for empno, sname, basic, hra, da and invoke
calculate()
to calculate netpay.
dispdata()
function to display all the data members on the screen.
(c) Consider the following declarations and answer the questions given below :

class WORLD
{
int H;
protected :
int S;
public :
void INPUT(int);
void OUTPUT();
};
class COUNTRY : private WORLD
{
int T;
protected :
int U;
public :
void INDATA( int, int)
void OUTDATA();
};
class STATE : public COUNTRY
{
int M;
public :
void DISPLAY (void);
};

(i) Name the base class and derived class of the class COUNTRY.
(ii) Name the data member(s) that can be accessed from function DISPLAY().
(iii) Name the member function(s), which can be accessed from the objects of class STATE.
(iv) Is the member function OUTPUT() accessible by the objects of the class COUNTRY ?
Ans. (a) A constructor is a special initialization function that is called automatically whenever an instance of
your class is declared. The name of the constructor is same as that of class and it returns no
value.This function is the opposite of the constructor in the sense that it is invoked when an object
ceases to exit. It also has a same name as that of class but with a prefix ~. The difference between
the constructor, destructor and other functions is that the functions can return a value but the
constructor and destructor do not return any value.
(b) // Class and function declaration of employee class
class employee
{
int empno;
char ename[20];

Examination Paper

float
basic, da, hra;
float
netpay;
float
calculate()
{
return (basic + da + hra);
}
public :
void havedata()
{
cout << "Enter employee no. : ";
cin >> empno;
cout << "Enter name : ";
cin >> ename;
cout << "Enter basic salary : ";
cin >> basic;
cout << "Enter DA : ";
cin >> da;
cout << "Enter HRA : ";
cin >> hra;
netpay = calculate();
}
void dispdata()
{
cout << "Employee no is : " << empno<<endl;
cout << "Name is : " << ename << endl;
cout << "Basic Salary : " << basic<<endl;
cout << "DA is : " << da<<endl;
cout << "HRA is : " << hra << endl;
cout << "Netpay is : " << netpay<<endl;
}
};

(c)

3. (a)

(b)
(c)
(d)
(e)

(i) Base class : WORLD


Derived class : STATE
(ii) M.
(iii) DISPLAY(), INDATA() and OUTDATA()
(iv) No
Suppose an array ARR containing float is arranged in ascending order. Write a user defined function
in C++ to search for one float from ARR with the help of binary search method. The function should
return an integer 0 to show absence of the number and integer 1 to showpresence of the number in
the array. The function should have the parameters as (i) an array ARR (ii) the number DATA to be
searched (iii) number of elements N.
4
An array S[10][15] is stored in the memory with each element requiring 4 bytes of storage. If the base
address of S is 1000, determine the location of S[8][9] when the array is S stored by
3
(i) Row major
(ii) Column major.
Write a user-defined function in C++ to display the sum of row elements of a two dimensional array
R[5][6] containing integers.
2
Evaluate the following postfix expression using a stack and show the contents of stack after execution
of each operation :
2
100, 40, 8, +, 20, 10, , +, *
Give the necessary declaration of a linked implemented stack containing float type numbers; also
write a user defined function in C++ to push a number from this stack.
4

4 Together with Computer Science (C++) XII

Ans. (a) // This function search an element in an array using binary search.
int binary(float ARR[10], float 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 (ARR[mid] == data)
{
pos = pos + mid;
flag = 1;
}
else
if (ARR[mid] < data)
first = mid + 1;
else
last = mid 1;
}
if (flag == 1)
return(1);
else
return(0);
}

(b) Let us assume that the Base index number is [0][0].


Number of Rows = R = 10
Number of Columns = C = 15
Size of data = W = 4
Base address = B = S[0][0] = 1000
Location of S[8][9] = X
(i) When S is stored by Row Major
X = B + W * [ 8 * C + 9]
= 1000 + 4 * [8 * 15 + 9]
= 1000 + 4 * [120 + 9]
= 1000 + 4 * 129
= 1516
(ii) When S is stored by Column Major
X = B + W * [8 + 9 * R]
= 1000 + 4 * [8 + 9 * 10]
= 1000 + 4 * [8 + 90]
= 1000 + 4 * 98
= 1000 + 392
= 1392
(c) // Function to find the sum of row elements of a two dimensional array
void calculate(int R[5][6])
{
int i, j, sum;
sum=0;
for(i=0; i<5; i++)
{
sum=0;
for(j=0; j<6; J++)

Examination Paper

sum = sum + R[i][j];


}
cout << "\n\t sum of " << (i+1) << " row is " << sum;

(d) The stack operation is :


Scanned elements

Operation

Stack

100
40
8
+

PUSH 100
PUSH 40
PUSH 8
POP 8
POP 40
Calculate 40 + 8 = 48
PUSH 48
PUSH 20
PUSH 10
POP 10
POP 20
Calculate 20 10 = 10
PUSH 10
POP 10
POP 48
Calculate 48 + 10 = 58
PUSH 58
POP 58
POP 100
Calculate 58 * 100 = 5800
PUSH 5800

100
100, 40
100, 40, 8

20
10

Ans = 5800
(e) // Declares a stack structure

struct node
{
float data;
node *link;
};
// Function body for add stack elements
node *push(node *top, float val)
{
node *temp;
temp = new node;
temp->data = val;
temp->link = NULL;
if(top ==NULL)
top = temp;
else
{
temp->link = top;
top = temp;
}

6 Together with Computer Science (C++) XII

100, 48
100, 48, 20
100, 48, 20, 10

100, 48, 10

100, 58

5800

return(top);
}

4. (a) Differentiate between ifstream class and ofstream class.


(b) Assuming the class STOCK , write functions in C++ to perform following :
(i) Write the objects of STOCK to a binary file.
(ii) Read the objects of STOCK from binary file and display them on screen.

2
4

class STOCK
{
int ITNO;
char ITEM[10];
public :
void GETIT( ) {cin>>ITNO;gets(ITEM);}
void SHOWIT( ){cout<<ITNO<< " "<<ITEM<<endl;}
};

Ans. (a)

ifstream
(i) This class is derived from istream class
(ii) It associates an input buffer with a file
(iii) It is used to read data from a file.

(b)

ofstream
(i) This class is derived from ostream class
(ii) It associates an output buffer with a file
(iii) It is used to write data onto a file.

(i) // Function to write the object of class to the binary file

void create(STOCK s)
{
ofstream afile;
afile.open("stock.dat", ios::out | ios :: binary);
if (!afile)
{
cout << "\n Unable to open the file ";
exit(1);
}
s.GETIT();
afile.write((char *)&s,sizeof(s));
afile.close();
}
(ii) // Function to read the object of class from the binary file
void read_file()
{
ifstream afile;
afile.open("stock.dat", ios::in | ios :: binary);
if (!afile)
{
cout << "\n File does not exist ";
exit(1);
}
STOCK s;
while(afile)
{
afile.read((char *) &s, sizeof(s));
s.SHOWIT();
}
afile.close();
}

5. (a) What is the need for normalisation ? Define first, second and third normal forms.

Examination Paper

Write the SQL commands for (b) to (g ) and write the outputs for (h) on the basis of the table
HOSPITAL :
TABLE : HOSPITAL
No.

Name

Age

Department

Dateofadm

Charges

Sex

Sandeep

65

Surgery

23/02/98

300

Ravina

24

Orthopaedic

20/01/98

200

Karan

45

Orthopaedic

19/02/98

200

Tarun

12

Surgery

01/01/98

300

Zubin

36

ENT

12/01/98

250

Ketaki

16

ENT

24/02/98

300

Ankita

29

Cardiology

20/02/98

800

Zareen

45

Gynaecology

22/02/98

300

Kush

19

Cardiology

13/01/98

800

10

Shailya

31

Nuclear Medicine

19/02/98

400

(b) To show all information about the patients of cardiology department.


1
(c) To list the name of female patients who are in orthopaedic department.
1
(d) To list names of all patients with their date of admission in ascending order.
1
(e) The display Patients Name, charges, age for male patients only.
1
(f) To count the number of patients with age>20.
1
(g ) To insert a new row in the HOSPITAL table with the following data :
1
11, Mustafa, 37, ENT, {25/02/98}, 250, M
(h) Give the output of following SQL statements :
2
(i) Select COUNT (DISTINCT Charges) from HOSPITAL;
(ii) Select MIN (Age) from HOSPITAL where Sex = M;
(iii) Select SUM(Charges) from HOSPITAL where Sex = F;
(iv) Select AVG (Charges) from HOSPITAL where Dateofadm < {12/02/98};
Ans. (a) Normalization is a process of data analysis used for grouping data elements in a record. While
dealing with database there may be unnecessary repetition of data, which can pose problems in
storing, and retrieving the data. The unnecessary repetition of data is called redundancy. Normalization
is the process of analyzing data. So, the redundancy gets reduced.
First Normal Form : A table is said to be in first normal form if no two rows are identical and each
entry is single value.
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.
Third Normal Form : A table is said to be in third normal form if it is in second normal form and every
non-key attribute depends non-transitively on the primary key.
(b) SELECT * FROM HOSPITAL
WHERE department = Cardiology;
(c) SELECT name FROM HOSPITAL
WHERE department = Orthopaedic and SEX = F;
(d) SELECT name FROM HOSPITAL
ORDER BY dateofadm;
(e) SELECT name, charges, age FROM HOSPITAL WHERE SEX = M;

8 Together with Computer Science (C++) XII

(f) SELECT COUNT(*) FROM HOSPITAL


WHERE age > 20;
(g) INSERT INTO HOSPITAL VALUES (11, Mustafa, 37, ENT, {25/02/98}, 250, M);
(h) (i) 5
(ii) 12
(iii) 1600
(iv) 387.50
6. (a) State Absorption Laws. Verify one of the Absorption Laws using a truth table.
2
(b) Prove X + Y'Z = (X + Y' + Z')(X + Y' + Z)(X + Y + Z) algebraically.
2
(c) Write the dual of the Boolean expression (UV + W)(V' + U).
1
(d) Obtain a simplified form for a Boolean expression :
2
F(x, y, z, w) = (0, 1, 3, 5, 7, 9, 10, 11, 13, 15) using Karnaugh map.
(e) Draw logic circuit for half adder.
1
(f) Represent the Boolean expression X + YZ' with the help of NAND gate only.
1
(g) Write the Product of sum form of the function G(U, V, W). Truth table representation of G is as
follows:
1
U

Ans. (a) Absorption law states that


(i) X + X.Y = X
(ii) X(X+Y) = X
Truth Table
X

X.Y

X+X.Y

(b) L.H.S

= X + Y'Z = (X+Y').(X+Z)
[ by distributive law]
= (X+Y'+Z'.Z) (X+Y'.Y+Z)
[ because Z'Z = Y'.Y = 0 & 0+A = A]
= (X+Y'+Z')(X+Y'+Z)(X+Y'+Z)(X+Y+Z) [by distributive law]
= (X+Y'+Z')(X+Y'+Z)(X+Y+Z)
[(X+Y'+Z).(X+Y'+Z) = (X+Y'+Z). by idempotent law]
= R. H. S.
proved.
(c) Dual is (U+V).W + V'U

Examination Paper

(d) The Karnaugh map of the given expression is :


zw
xy
00
01
11
10
00
1
1
1
01
1
1
11

10

F = x'y'z' +w + xy'z
(e) The logic circuit for a half adder is :
sum = x + y

x
y

carry = x . y
(f) The Boolean expression X + YZ' using NAND gate is :
x

x
x + yz'

y
z
(g)
7. (a)
(b)
(c)
(d)
Ans. (a)
(b)
(c)

(d)

yz

G(U,V,W) = (U+V'+W) . (U+V'+W') . (U'+V'+W) . (U'+V'+W')


What are repeaters ?
1
What is the purpose of using a MODEM ?
1
Write the two advantages and two disadvantages of the following topologies in network :
2
(i) Bus Topology
(ii) Star Topology.
What is the difference between LAN and Internet ?
1
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.
The modem is used to convert digital data into analog form and vice versa.
(i) Advantages of BUS topology
1. Short cable length
2. Easy to extend.
Disadvantages of BUS topology
1. Fault diagnosis is difficult
2. Nodes must be intelligent to select the data send.
(ii) 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
LAN is confined to one or nearby building but Internet has no specific geographical area. Internet is
the collection of different LANs. It is the example of WAN.

10 Together with Computer Science (C++) XII

You might also like