Examination Papers, 2000: (Comptt.)
Examination Papers, 2000: (Comptt.)
Examination Papers, 2000: (Comptt.)
[Comptt.]
Maximum Marks : 70
Note.
Duration : 3 Hours
1. (a) Illustrate with the help of an example the concept of overloading a function name.
(b) Name the header file, to which the following built-in functions belong :
(i) strcat()
(ii) islower()
(iii) log10()
(iv) gets()
(c) Will the following program execute successfully ? if not, state the reason(s).
2
2
2
#include<iostream.h>
void main
{
int x = 20;
do
{
switch (x%3==0)
cout >> 2*x+1 >> endl;
else
cout >> 2*x-1 >> endl;
x-=2;
}
while x>0;
}
#include <iostream.h>
void display(double d) {
cout << "Real : " << d << endl;
}
void display(int i) {
cout << "Integer : " << i << endl;
}
void display(char Ch) {
cout << "Character : " << Ch << endl;
}
void display(char Ch[]) {
cout << "String : " << Ch << endl;
}
void main() {
double F = 3.1416;
display(A);
display(F);
display("String");
display(45);
}
#include <iostream.h>
int max(int &x, int &y, int &z) {
if (x > y && y > z) {
y++;
Examination Paper
z++;
return x;
} else
if (y > x)
return y;
else
return z;
}
void main() {
int a = 10, b = 13, c = 8;
a = max(a, b, c);
cout << a << b << c << endl;
b = max(a, b, c);
cout << ++a << ++b << ++c << endl;
c = max(a, b, c);
cout << a++ << ++b << ++c << endl;
}
(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 2 x4 x6 x 8 x10
x2n
+ + + + + ..... + upto N terms
1! 2! 3! 4! 5!
n!
Ans. (a) In C++ you can declare different function with the same name. This property is called function
overloading. Function overloading implements polymorphism.
// Program using function overloading to calculate the area of rectangle, area of triangle
// using Heros 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";
cin >> choice1;
if (choice1 == 1) {
cout << "\nEnter the three sides of triangle : ";
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;
}
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);
}
Examination Paper
}
return(sum1);
}
(i) Write the names of member functions, which are accessible from the objects of class GAMMA.
(ii) Write names of data members, which are accessible from the member functions of class BETA.
(iii) Name the base class and derived class of class BETA.
(iv) Name the private member functions of class GAMMA.
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 return no value.
Destructor 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 the other function is that the functions can
return a value but the constructor and destructor does not return any value.
(c)
3. (a)
(b)
(c)
(d)
(i) getdata();
showdata();
(ii) m and n.
(iii) The base class is ALPHA and the derived class is GAMMA.
(iv) There is no private member functions of class GAMMA.
Write a C++ function to sort an array of integer using insertion sort. The function should have two
parameters: name of the array and number elements in the array.
3
P is one-dimensional array of integers arranged in ascending order. Write a C++ function to efficiently
search for a data VAL from P. If VAL is present in the array then the function should return value 1 and
0 otherwise.
3
X[1..16] [1..10] is a two dimensional array. The first element of the array is stored at location 100. Each
element of array occupies 6 bytes. Find the memory location of X[2][4] when (i) array is stored row
wise and (ii) array is stored column wise.
3
Evaluate the following postfix expression showing the status of stack after execution of each step :
10, 40, +, 8, 2, +, *, 10, -.
2
Examination Paper
(e) Give the necessary declaration for linked representation of a queue containing integers. Write a C++
function to remove an element from the queue.
4
Ans. (a) // Function to implement the insertion short
void Insert_sort(int arr[], int N) {
int x, i, j, T;
for (i = 1; i < N; i++) {
T = arr[i]; // Extracts the first element of the unsorted part
j = i - 1;
while ((T < arr[j]) && (j >= 0)) {
arr[j+1] = arr[j];
j = j - 1;
}
arr[j+1] = T;
for (x = 0; x < N; x++)
// Displays the output after every insertion
cout << arr[x] << " ";
cout << \n;
}
cout << "\nThe sorted list is ... \n";
for (i = 0; i < N; i++)
cout << arr[i] << endl;
}
(b) // Function to search a value VAL and return either 1 or 0 accordingly
int binary_search(int P[], int N, int VAL) {
int i, flag=0, first=0, last, pos=1, mid;
last = N-1;
while (first<=lat) && *flag == 0)) {
mid = (first+last)/2;
if (P[mid] == VAL)
{
pos = pos + mid;
flag
= 1;
}
else
if (P[mid] < VAL)
first = mid + 1;
else
last = mid - 1;
}
if (flag == 1)
return (1);
else
return (0);
}
(c) Given :
To find Row Major order
The formula is applied :
X[I][J] = B +w(n(I-L1) + (J-L2))
X[2][4] = 100+6*(10*(2-1) + (4-1))
= 100 + 6*(10+3)
= 100 + 6 *13
= 100 + 78
= 178
Stack Status
1.
2.
3.
10
10, 40
4.
5.
6.
7.
8.
9.
Push 10
Push 40
Pop 40, Pop 10
Calculate 40+10 = 50
Push 50
Push 8
Push 2
Pop 2, Pop 8
Calculate 2 + 8 = 10
Push 10
Pop 10, Pop 50
Calculate 10 * 50= 500
Push 500
Push 10
Pop 10, Pop 500
Calculate 500 10 = 490
Push 490
50
50, 8
50, 8, 2
50, 10
500
500, 10
490
4. (a) Name two member functions common to the class ifstream and ofstream.
Examination Paper
class bank {
int accno;
char name[20];
float balance;
public:
void input() {
cin >> accno >> name >> balance;
}
void display() {
cout << accno << " " << name << balance << endl;
}
float getbalance() {
return balance;
}
};
fstream bankfile;
bank.oepn("BANK.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++) {
bnk.input();
bankfile,write((char *)&bnk, sizeof(bank));
}
bankfile.close();
}
void data_show() {
bank bnk; // Declares the bank object for read operation
fstream bankfile;
bankfile.open("BANK.DAT", ios::in|ios::binary);
bankfile.seekg(0, ios::beg);
if (!bankfil)
cout << "File does not exists";
while (bankfile) {
bankfile.read((char *)&bnk, sizeof(bank)); // Reads the record one-by-one
if (balance > 250000) // Checks the condition
bnk.show(); // Display the output through the member function
if (bankfile.eof()) // If there is no record, it terminates the loop
exit(0);
}
bankfile.close();
}
5. (a) Give an example of a relation which is not in second normal form along with justification.
2
Write SQL commands for (b) to (e) and write the outputs for (f) and (g) on the basis of table
EMPLOYEE :
TABLE : EMPLOYEE
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
SNO
NAME
BASIC
DEPARTMENT
DATOFAPP
AGE SEX
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1
KARAN
8000
PERSONNEL
27/03/97
35
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
2
DIVAKAR
9500
COMPUTER
20/01/98
34
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
3
DIVYA
7300
ACCOUNTS
19/02/97
34
F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
4
ARUN
8350
PERSONNEL
01/01/95
33
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
5
SABINA
9500
ACCOUNTS
12/01/96
36
F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
6
JOHN
7400
FINANCE
24/02/97
36
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
7
ROBERT
8250
PERSONNEL
20/02/97
39
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
8
RUBINA
9450
MAINTENANCE 22/02/98
37
F
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
9
VIKAS
7500
COMPUTER
13/01/94
41
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
10
MOHAN
9300
MAINTENANCE 19/02/98
37
M
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
(b) List the names of the employees who are more than 34 years old sorted by NAME.
1
(c) Display a report, listing NAME, BASIC, DEPARTMENT and annual salary. Annual salary equals
BASIC X 12.
1
Examination Paper
(d) To count the number of employees who are either working in PERSONNEL or COMPUTER department.
1
(e) To inset a new row in the EMPLOYEE table :
1
11, VIJAY, 9300, FINANCE, {13/07/98}, 35, M
(f) Give the output of the following SQL statement based on table EMPLOYEE :
2
(i) Select SUM(BASIC) from EMPLOYEE where DEPARTMENT = PERSONNEL;
(ii) SelectAVG(BASIC) from EMPLOYEE where SEX = F;
(iii) Select MAX(BASIC) from EMPLOYEE where DATOFAPP > {22/02/97};
(iv) Select COUNT(DISTINCT DEPARTMENT) from EMPLOYEE;
(g) Assume that there is one more table INCHARGE in the database as shown below :
2
TABLE : INCHARGE
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
DEPT
HEAD
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
PERSONNEL
RAHUL
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
COMPUTER
SATYAM
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
ACCOUNTS
NATH
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
FINANCE
GANESH
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
MAINTENANCE
JACOB
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
TNo# TName
TTopic
TDept
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T01
Mr. Nayak
DBMS
Comp. Science
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T01
Mr. Nayak
LAN
Comp. Science
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T01
Mr. Nayak
Multimedia
Comp. Science
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T02
Mr. Govind
Algebra
Mathematics
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T02
Mr. Govind
3-D
Mathematics
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T02
Mr. Govind
Calculus
Mathematics
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T04
Ms. Meeta
Physical
Chemistry
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
T04
Ms. Meeta
Organic
Chemistry
1234567890123456789012345678901212345678901234567890123456789012123456789
1234567890123456789012345678901212345678901234567890123456789012123456789
(b)
(c)
(d)
(e)
(f)
The reason is that number of data values is repeated, which takes lots of space and data redundancy.
The database management system conflicts the file to operate.
SELECT NAME FROM EMPLOYEEWHEREAGE > 34 ORDER BY NAME;
SELECT NAME, BASIC, DEPARTMENT, BASIC*12 FROM EMPLOYEE;
SELECT COUNT(*) FROM EMPLOYEE
WHERE DEPARTMENT = PERSONNEL OR DEPARTMENT = COMPUTER;
INSERT INTO EMPLOYEE values (11, VIJAY, 9300, FINANCE,{13/07/98}, 35,M);
(i) 24600
(ii) 8750
(iii) 9500
(iv) 5
(g)
Q.6. (a)
(b)
(c)
(d)
(e)
(f)
NAME
HEAD
KARAN
RAHUL
ARUN
RAHUL
ROBERT
RAHUL
DIVAKAR
SATYAM
VIKAS
SATYAM
DIVYA
NATH
SABINA
NATH
JOHN
GANESH
RUBINA
JACOB
MOHAN
JACOB
State DeMorgans Laws. Verify one of them using truth tables.
2
Prove A.B + AC = (A+C).(A+B).(B+C) algebraically.
2
Obtain a simplified form for the Boolean expression :
F(a, b, c, d) = (4, 5, 6, 7, 9, 11, 12, 13, 14, 15) using Karnaugh map method.
3
Draw the truth table for a Full-adder.
1
Draw the circuit diagram for the Boolean function F(A, B, C) = (A + B)(B + C) using NOR gates only.
1
Express in the Product of Sums form, the Boolean function F(A, B, C), the truth table for which is
given below :
1
A
X.Y
X.Y
X+Y
(b) (A+C)(A+B)(B+C)
= (AA + AB +AC + BC) (B+C)
= (AAB + AAC + ABB + ABC + ABC + ACC + B.BC + BCC
= AB + ABC + ABC + AC + BC + BC
Examination Paper
11
= AB[1+C] +AC[B+1] + BC
= AB + AC + BC = R.H.S.
(c) F(a, b, c, d) = (4, 5, 6, 7, 9, 11, 12, 13, 14, 15)
cd
ab
00
01
00
01
11
10
11
10
1
1
1
1
F = b + ad
(d) The truth table for Full-adder is :
x
sum
carry
(e) (A + B) (B + C) is :
A
B
(A+B)(B+C)
B
C
(f)
7. (a)
(b)
(c)
(d)
Ans. (a)
(b)
Examination Paper
13