Examination Papers, 2003: (Comptt.)
Examination Papers, 2003: (Comptt.)
Examination Papers, 2003: (Comptt.)
[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
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 : ";
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)
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) {
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’
carry = x . y