You are on page 1of 11

Examination Papers, 2003

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

1. (a) What is the difference between global variable and local variable ? Explain with the help of a suitable
example. 2
(b) Name the header file, to which the following built-in functions belong : 1
(i) log() (ii) strcmp()
(c) Find syntax error(s), if any, in the following program : 2
include <iostream.h>
struct Group
{
int X1, X2;
}
void main()
{
G1, G2, Group;
cin>>G1.X1<<G2.X2;
G2=G1;
cout<<G2.X2<<G2.X1<<endl;
2+=G1.X1;
cout<<G1.X1<<G1.X2<<endl;
}
(d) Give the output of the following program segment : 3
char *Text[2] = {“Two”, “six”};
for (int C=0;C<2;C++) {
for (int D=0; D<strlen(Text[0]); D++)
if (islower(Text[C][D]))
cout<<(char)toupper(Text[C][D]);
else
if (isupper(Text[C][D]) && (D%2 ==0))
cout<<(char)tolower(Text[C][D]);
else
cout<<Text[C][D];
cout<<D<<endl;
}
(e) Write the output of the following program : 3
#include <iostream.h>
void Numvalue(int &A, int B=25) {
int TEMP=A-B;
A+=TEMP;
if (B==25)
cout<<A<<TEMP<<endl;
}
void main() {
int X=100, Y=200;
Numvalue(X);
cout<<X<<Y<<endl;
Numvalue(Y,X);

Examination Paper 1
cout<<X<<Y<<endl;
}
(f) Write a C++ function having two parameters V and n with a result type as float to find the sum of the
series given below : 4
1 1 1
V + V – V + V + – V + …..+ V1 1
2! 3! 4! 5! n!
Ans. (a) Local variables. The variables which are declare inside any function are called local variable. Local
variables declared static retain their value when the function in which they are declared is exited.
Local variables declared at the beginning of a function have block scope as do function parameters,
which are considered local variables by the function.
Global variables. The variables which are declared globally ( before main() ) are called global variables.
Global variables are created by placing variable declarations outside any function definition and
they retain their values throughout the execution of the program.
For Example;
int a = 10; // Global variable
main( )
{
int x=20; // Local variable
cout<<x;
cout<< a;
}
(b) (i) math.h (ii) string.h
(c) The errors are :
#include <iostream.h> // Error 1. Declaration syntax error
struct Group
{
int X1, X2;
}; // Error 2. Too many type declaration
void main()
{
Group G1, G2; // Error 3. Undefined symbol G1
cin>>G1.X1>>G2.X2; // Error 4.
G2=G1;
cout<<G2.X2<<G2.X1<<endl;
G1.X1+=2; // Error 5.
cout<<G1.X1<<G1.X2<<endl;
}
// Error 1. include should be declared as #include
// Error 2. struct declaration should end with semicolon
// Error 3. Structure declaration error
// Error 4. Illegal structure operation: it should be cin >>
// Error 5. LValue required
(d) The output is :
tWO3
SIX3
(e) The output is :
17575
175200
175225

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


(f) The function is :
// Function to find the sum of series of float type
#include <iostream.h>
#include <conio.h>
#include <math.h>
float sum_series(float V, int n) {
float sum = V, temp, fact = 1, div;
for (int i = 2; i < n; i++) // Starting series value is 2
{
fact = 1;
for (int j=1; j<=i; j++)
fact = fact * j;
div = (float)1/fact * V;
if ((i%2) == 0)
sum += div;
else
sum -= div;
}
return sum;
}
void main() {
clrscr();
float A, sum = 0;
int x;
cout << "Enter the value for V : ";
cin >> A;
cout << "Enter the value for n : ";
cin >> x;
sum = sum_series(A, x);
cout << "The sum of series is : " << sum;
}
2. (a) What do you understand by polymorphism in object oriented programming ? Illustrate the same with
the help of a suitable example. 2
(b) Define a class PUBLISHER in C++ with the following specifications : 4
private members of class PUBLISHER
- IDNumber long
- Title 40 character
- Author 40 character
- Price, StockQty double
- StockValue double
- Valcal() A function to find Price * StockQtu with double as return type
- Duration float
- Noofepisodes integer
public member function of class PUBLISHER
- A constructor function to initialise Price, StockQty and StockValue as 0
- Enter( ) function to input IDNumber, Title ad Aughor
- TakeStock( ) function to increment StockQty by N (where N is passed as argument to this
function) and call the function Valcal() to update the StockValue
- Sale( ) function to decrease the StockQty by N (where N is sale quantity passed to this function
as argument) and also call the function Valcal() to update the StockValue.
- Outdata() function to display all the data members on the screen

Examination Paper 3
(c) Consider the following and answer the questions given below : 4
class CEO {
double Turnover;
protected :
int Noofcomp;
public :
CEO( );
void INPUT( );
void OUTPUT( );
};
class Director : public CEO {
int Noofemp;
public :
Director( );
void INDATA();
void OUTDATA( );
protected:
float Funda;
};
class Manager : public Director {
float Expense;
public :
Manager();
void DISPLAY(void);
};
(i) Which constructor will be called first at the time of declaration of an object of class Manager?
(ii) How many bytes will an object belonging to class Manager require ?
(iii) Name the member function(s), which are directly accessible from the object(s) of class Manager.
(iv) Is the member function OUTPUT() accessible by the objects of the class Director ?
Ans. (a) The polymorphism contains three words as : poly means many or multiple; morph means to change
from one thing to another; and ism means the process of something. Function overloading implements
polymorphism.
// Program using function overloading to calculate the area of rectangle,
// area of triangle using Hero’s formula and area of circle.
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <math.h>
float area(float a, float b , float c);
float area(float l, float w);
float area(float r);
void main() {
char ch;
float len, wid, n1, n2, n3, ar;
float radius;
int choice1;
clrscr();
cout << "\n1. For area of triangle ";
cout << "\n2. For area of rectangle ";
cout << "\n3. For area of circle ";
cout << "\nEnter your choice ";
cin >> choice1;
if (choice1 == 1) {
cout << "\nEnter the three sides of triangle : ";

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


cin >> n1 >> n2 >> n3;
ar = area(n1, n2, n3);
cout << "\nArea of triangle is: "< < ar;
}
if (choice1 == 2) {
cout << "\nEnter the length : ";
cin >> len;
cout << "\nEnter the width : ";
cin >> wid;
cout<< "\nArea of rectangle is : " << area(len, wid);
}
if (choice1 == 3) {
cout<<"\nEnter the radius : ";
cin>>radius;
cout<<"\n Area of circle : " <<area(radius);
}
}
float area(float a, float b , float c) {
float s;
float a1;
s = (a + b + c) / 2;
a1 = sqrt(s * (s–a) * (s–b) * (s–c));
return(a1);
}
float area(float l, float w) {
return(l*w);
}
float area( float radius) {
return(3.14 * radius * radius);
}
(b) The class is as :
class PUBLISHER {
private:
long IDNumber;
char Title[40];
char Author[40];
double Price, StockQty, StockValue;
void Valcal() {
StockValue = Price * StockQty;
}
public:
PUBLISHER() {
Price = 0;
StockQty = 0;
StockValue = 0;
void Enter() {
cin>>IDNumber;
cin>>Title;
cin>>Author;
}
void TakeStock(int N) {
StockQty = StockQty + N;
Valcal();
}
void Sale(int N) {

Examination Paper 5
StockQty = StockQty - N;
Valcal();
}
void Outdata() {
cout<<IDNumber<<Title<<Author<<Price<<StockQty<<StockValue;
}
};
(c) (i) CEO()
(ii) 16
(iii) DISPLAY(), INDATA(), OUTDATA(), INPUT(), OUTPUT()
(iv) Yes
3. (a) A one dimensional array POINTS containing long type data arranged in ascending order. Write a
user defined function in C++ to search for a number from POINTSwith the help of binary search
method. The function should return an integer –1 to show absence of the number and integer 1 to
show presence of the number in the array. The function should have three parameters as (1) an array
POINTS, (2) the number SDATAto be searched, (3) number of elements N. 4
(b) An array X[20][10] is stored in the memory with each element requiring 8 bytes of storage. If the base
address of X is 6000, determine the locations of X[16][6], when the array X is stored along Column.
3
(c) Write the user-defined function in C++ to display the sum of each row elements of a two dimensional
array P[2][4] containing integers. 2
(d) Evaluate the following postfix expression using a stack and show the contents of stack after execution
of each operation : 2
True, False, OR, True, AND, False, True, OR, AND
(e) Give the necessary declaration of a linked implemented stack containing double type of numbers.
Also write a user defined function in C++ to delete a number from the stack. 2
Ans. (a) // Binary search method to search data in a sorted list
int binary_search(long POINTS, int SDATA, int N) {
int first = 0, last, mid = 0, find = 0;
first = 0;
find = 0;
last = NUM - 1;
// Binary search procedure
while ((first <= last) && (find == 0)) {
mid = (first + last) / 2;
if (POINTS[mid] == SDATA)
find = mid;
else
if (POINTS[mid] < SDATA)
first = mid + 1;
else
last = mid - 1;
}
if (find > 0)
return -1;
else
return 1;
}
(b) Solution B = 6000, w = 8, L1 = L2 = 0, n = 10 and m = 20
Address T[I][J] = B + w(m ( J – L2) + ( I – L1))
Location T[16][6] = 6000 + 8(20(6 – 0 ) + (16 –0))
= 6000 + 8(20(6) + 16)

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


= 6000 + 8(120 + 16)
= 6000 + 8 (136)
= 6000 + 1088 = 7088
(c) The function is :
//Sum of Row elements
void row_sum(float ARR[2][4]) {
int i, j, rsum = 0;
for (i = 0; i < 2; i++) {
rsum = 0;
for (j = 0; j < 4; j++) {
rsum = rsum + ARR[i][j];
}
cout << "\n\t sum of " <<(i+1)<< "row is " << rsum;
}
}
(d) The operation is:
Elements Scanned Stack
True True
False True, False
OR Pop True, False
True OR False = True
True True, True
AND Pop True, True
True AND True = True
True
False True, False

True True, False, True


OR Pop False, True
False OR True = True
True, True
AND Pop True, True
True AND True = True
∴Result = True
(e) // Declares a stack structure
struct node {
double data;
node *link;
};
// function body for delete stack elements
node *pop(node *top,int &val) {
node *temp;
clrscr();
if (top == null ) {
cout<<"stack empty ";
val = –1;
} else {
temp = top;
top = top–>link;
val = temp–>data;

Examination Paper 7
temp–>link = null;
delete temp;
}
return (top);
}
4. (a) Differentiate between function getline() and read() member functions in C++. 1
(b) Assume the given definition of class HOTELDATA, write functions in C++ to perform the following:
4
(i) Checkins() function to allow user to enter the data of customers (objects of class HOTELDATA)
and write them to a binary file “ASOK.DAT”.
(ii) Count() function to count the number of customers (number of objects of class HOTELDATA)
present in the hotel (i.e., stored in the binary file “ASOK.DAT”).
class HOTELDATA {
int ROOM;
char NAME[19];
int Duration;
public:
void ENTER() {cin>>ROOM;gets(NAME); cin>>Duration;)
void DISPLAY() {
cout<<ROOM<" " <<NAME << " " < Duration << endl;
}
};
Ans. (a) The getline() function is used with input streams, and reads characters into buffer until either:
· num – 1 characters have been read,
· a newline is encountered,
· or, optionally, until the character delim is read. The delim character is not put into buffer.
The format of getline() function is :
device.getline(char_var, integer, “terminating_char”);
For example,
char line[20];
cout << “Enter a line terminated by . (dot) ”;
cin.getline(line, 20, ‘.’);
cout << line;
The read() function is used to read block of data from the file.
(b) (i) // Function to write the object of class to the binary file
void Checkins(HOTELDATA hot) {
ofstream afile;
afile.open("ASOK.DAT", ios::out | ios :: binary);
if (!afile) {
cout <<" \n Unable to open the file ";
exit(1);
}
hot.ENTER();
afile.write((char *)&hot, sizeof(hot));
afile.close();
}
(ii) // Function to read the object of class from the binary file
void Count() {
int ctr=0;
ifstream afile;
afile.open("ASOK.DAT", ios::in | ios :: binary);
if (!afile) {

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


cout << "\n File does not exists ";
exit(1);
}
HOTELDATA hot;
while(afile) {
ctr++;
afile.read((char *) &hot, sizeof(hot));
hot.DISPLAY();
}
afile.close();
cout<<"Number of customers present in the hotel " << ctr;
}
5. (a) Define the given terms in respect of Relational Database : Cardinality of a Table and Degree of a
Table. 1
(b) What do you understand by primary key ? 1
NOTE: Write SQL commands for (c) to (I) and write the outputs for (j) on the basis of table COLLEGE
Table : COLLEGE
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
No Name Age Department DateofJoin Basic Sex
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
1 Shalaz 45 Biology 13/02/88 10500 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
2 Sameera 54 Biology 10/01/90 9500 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
3 Yagyen 43 Physics 27/02/98 8500 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
4 Pratyush 34 Chemistry 11/01/93 7500 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
5 Aren 51 Mathematics 22/01/91 8500 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
6 Reeta 27 Chemistry 14/02/94 9000 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
7 Urvashi 29 Biology 10/02/93 8500 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
8 Teena 35 Mathematics 02/02/89 10500 F
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
9 Viren 49 Mathematics 03/01/88 9000 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
10 Prakash 22 Physics 17/02/92 8000 M
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901
(c) To change the Basic salary to 10500 of all those teachers from COLLEGE, who joined the COLLEGE
after 01/02/89 and are above the age of 50. 1
(d) To display Name, Age and Basic of all those from COLLEGE, who belong to Physics and Chemistry
department only. 1
(e) To display all the department names from COLLEGE, with no duplication. 1
(f) To list names of all teachers from COLLEGE with their date of joining in ascending order within their
Basic salaries in ascending order. 1
(g) To display maximum salary amongst the female teachers and also amongst the male teachers from
COLLEGE. (Give a single command). 1
(h) To insert a new row in the table COLLEGE with the following data : 1
15, “ATIN”, 27, “Physics”, {15/05/02}, 8500, “M”
(i) To delete a row from table COLLEGE, in which NAME is “VIREN”. 1
(j) Give the output of the following SQL statement : 1
(i) Select COUNT(Name) from COLLEGE;
(ii) Select MIN(Basic) from COLLEGE whereAge>40;
Ans. (a) Cardinality of a table is total number of rows.
Degree of a table is total number of attributes.

Examination Paper 9
(b) The attribute (column) or set of attributes (columns) which is used to identify a tuple/row uniquely
are known as primary key.
(c) Update COLLEGE
Set Basic = 10500
Where DateofJoin > {01/02/89} AND Age > 50;
(d) Select Name,Age, Basic From COLLEGE
Where Department = “Physics” AND Department = “Chemistry”;
(e) Select Distinct Department From COLLEGE;
(f) Select Name From COLLEGE Order By DateofJoin, Order By Basic;
(g) Select Max(Basic) from COLLEGE
Group By Sex
Having Sex = “F” OR Sex = “M”;
(h) Insert into COLLEGE Values(15, “ATIN”, 27 “Physics”, {15/05/02}, 8500, “M”);
(i) Delete From COLLEGE Where Name = “VIREN”;
(j) (i) 10 (ii) 8500
6. (a) State De Morgan Laws of Boolean algebra. Verify one of the De Morgan Laws using a truth table.2
(b) Prove X’.Y’ + Y.Z = X’.Y’Z’ +X’Y’Z + X’.Y.Z +X.Y.Z algebraically. 2
(c) What is the significance of the duality principle of Boolean Algebra. 1
(d) Obtain a simplified form for a Boolean expression 2
F(A, B, C, D) = Σ(1, 2, 4, 6, 8, 11, 13, 14, 15) using Karnaugh Map. 2
(e) Draw the logic circuit for a half-adder using NOR gates only. 2
(f) Write the Sum of Product form of the function H(X, Y, Z), whose truth table representation is as
follows : 1

X Y Z H
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 1
1 1 1 0
Ans. (a) DeMorgan’s Law state that
(i) (A + B)’ = A’B’
(ii) (AB)’ = A’ + B’

A B (A+B)’ A’B’ (AB)’ A’+B’


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

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


(b) L.H.S. = X’Y’Z’ + X’Y’Z + X’YZ + XYZ
= X’Y’(Z’Z) + YZ(X’+X)
X’Y’ + YZ [A+A’=1]
(c) Duality principle. Most of the laws of Boolean algebra are listed in pairs and designated by part (a)
and (b). One part may be obtained from the other if ‘ +’ is interchanged with ‘.’ and 0 is interchanged
with 1. This property of Boolean algebra is known as duality principle.
For example, X + X.Y = X
And its dual will be X.( X + Y ) = X. Both of them are known as absorption law.
(d) CD
AB 00 01 11 10
00 1 1
01 1 1
11 1 1 1
10 1 1
F = ABD + ABC + ACB + ACD’ + A’B’D’ + A’B’C’D + ABC’D’
(e) The logic circuit for a full adder is :
x sum = x + y
y

carry = x . y

(f) H = X’Y’Z + X’YZ + XY’Z + XYZ’


7. (a) What is a gateway ? 1
(b) Expand term TCP/IP. 1
(c) Write the one advantage and one disadvantage of the following topologies in network : 2
(i) Star Topology
(ii) Bus Topology
(d) What is the purpose of using FTP ? Name one of the search engine. 1
Ans. (a) The special machine, which allows different electronic networks to talk to Internet that uses TCP/IP,
is called gateway.
(b) TCP/IP stands for Transmission Control Protocol/Internet Protocol.
(c) (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
(d) FTP is standard tool on the Internet for transferring copies of files. FTP can be used to copy any file
from one Internet host to other. Altavista.
Examination Paper 11

You might also like