ai1998

10
Examination Paper 1 Examination Papers, 1998 [All India] Maximum Marks : 70 Duration : 3 Hours Note. 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 : 2 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); (e) Write the output of the following program : 3 #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; }

Upload: ajay-rana

Post on 25-Dec-2015

218 views

Category:

Documents


0 download

DESCRIPTION

past year comp paper

TRANSCRIPT

Page 1: AI1998

Examination Paper 1

Examination Papers, 1998[All India]

Maximum Marks : 70 Duration : 3 Hours

Note. 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 == Ycout << Y+X;

elsecout >> Y;

}(d) Give the output of the following program : 2

char *NAME = "CoMPutER";for (int x = 0; x < strlen(NAME); x++)

if (islower(NAME[x]))NAME[x] = toupper(NAME[x]);

elseif (isupper(NAME[x]))

if (x%2==0)NAME[x] = tolower(NAME[x]);

elseNAME[x] = NAME[x-1];

puts(NAME);(e) Write the output of the following program : 3

#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;

}

Page 2: AI1998

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

(f) Write a C ++ function having two value parameters U and n with result type float to find the sum ofseries 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> //Correction - 1void main(){

int X,Y;cin>>X;for (Y=0; Y<10; Y++) // Correction - 2If ( X == Y ) // Correction - 3

cout<<Y+X;else

cout<< Y; // Correction - 4}Correction 1 : () bracket cannot be used with #includeCorrection 2 : In place of , symbol ; should be used and y should be YCorrection 3 : () bracket was missing with ifCorrection 4 : ‘<<’ should be used with cout

(d) The output is : cOmmUTer(e) The output is as :

190 280 100280 10290 570 10570 10

(f) // Function to find the sum of series of float typefloat sum_series(float U, float n){

float sum = 1.0, temp;for (int i = 1; i <= n; i++) // Starting series value is 1{

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;

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

functions different from other member functions ? 2

Page 3: AI1998

Examination Paper 3

(b) Define a class employee with the following specifications : 4private members of class employeeempno integerename 20 charactersbasic, hra, da floatnetpay floatcalculate() A function to calculate basic + hra + da with float return typepublic member function of class employeehavedata() function to accept values for empno, sname, basic, hra, da and invokecalculate() 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 ofyour class is declared. The name of the constructor is same as that of class and it returns novalue.This function is the opposite of the constructor in the sense that it is invoked when an objectceases to exit. It also has a same name as that of class but with a prefix ‘~’. The difference betweenthe constructor, destructor and other functions is that the functions can return a value but theconstructor and destructor do not return any value.

(b) // Class and function declaration of employee classclass employee{

int empno;char ename[20];

Page 4: AI1998

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

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) (i) Base class : WORLDDerived class : STATE

(ii) M.(iii) DISPLAY(), INDATA() and OUTDATA()(iv) No

3. (a) Suppose an array ARR containing float is arranged in ascending order. Write a user defined functionin C++ to search for one float from ARR with the help of binary search method. The function shouldreturn an integer 0 to show absence of the number and integer 1 to showpresence of the number inthe array. The function should have the parameters as (i) an array ARR (ii) the number DATA to besearched (iii) number of elements N. 4

(b) An array S[10][15] is stored in the memory with each element requiring 4 bytes of storage. If the baseaddress 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.(c) 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(d) Evaluate the following postfix expression using a stack and show the contents of stack after execution

of each operation : 2100, 40, 8, +, 20, 10, –, +, *

(e) Give the necessary declaration of a linked implemented stack containing float type numbers; alsowrite a user defined function in C++ to push a number from this stack. 4

Page 5: AI1998

Examination Paper 5

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;

elselast = 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 = 10Number of Columns = C = 15Size of data = W = 4Base address = B = S[0][0] = 1000Location of S[8][9] = X

(i) When S is stored by Row MajorX = 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 MajorX = 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 arrayvoid 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++)

Page 6: AI1998

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

{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 PUSH 100 10040 PUSH 40 100, 408 PUSH 8 100, 40, 8+ POP 8

POP 40Calculate 40 + 8 = 48PUSH 48 100, 48

20 PUSH 20 100, 48, 2010 PUSH 10 100, 48, 20, 10– POP 10

POP 20Calculate 20 – 10 = 10PUSH 10 100, 48, 10

+ POP 10POP 48Calculate 48 + 10 = 58PUSH 58 100, 58

* POP 58POP 100Calculate 58 * 100 = 5800PUSH 5800 5800

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

struct node{

float data;node *link;

};// Function body for add stack elementsnode *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;

}

Page 7: AI1998

Examination Paper 7

return(top);}

4. (a) Differentiate between ifstream class and ofstream class. 2(b) Assuming the class STOCK , write functions in C++ to perform following : 4

(i) Write the objects of STOCK to a binary file.(ii) Read the objects of STOCK from binary file and display them on screen.

class STOCK{

int ITNO;char ITEM[10];public :

void GETIT( ) {cin>>ITNO;gets(ITEM);}void SHOWIT( ){cout<<ITNO<< " "<<ITEM<<endl;}

};

Ans. (a) ifstream ofstream

(i) This class is derived from istream class (i) This class is derived from ostream class(ii) It associates an input buffer with a file (ii) It associates an output buffer with a file

(iii) It is used to read data from a file. (iii) It is used to write data onto a file.

(b) (i) // Function to write the object of class to the binary filevoid 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. 2

Page 8: AI1998

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

12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123412345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212341234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234

Write the SQL commands for (b) to (g ) and write the outputs for (h) on the basis of the tableHOSPITAL :

TABLE : HOSPITAL

No. Name Age Department Dateofadm Charges Sex1 Sandeep 65 Surgery 23/02/98 300 M2 Ravina 24 Orthopaedic 20/01/98 200 F3 Karan 45 Orthopaedic 19/02/98 200 M4 Tarun 12 Surgery 01/01/98 300 M5 Zubin 36 ENT 12/01/98 250 M6 Ketaki 16 ENT 24/02/98 300 F7 Ankita 29 Cardiology 20/02/98 800 F8 Zareen 45 Gynaecology 22/02/98 300 F9 Kush 19 Cardiology 13/01/98 800 M10 Shailya 31 Nuclear Medicine 19/02/98 400 M

(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 Patient’s 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. Whiledealing with database there may be unnecessary repetition of data, which can pose problems instoring, and retrieving the data. The unnecessary repetition of data is called redundancy. Normalizationis 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 eachentry 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 attributedepends 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 everynon-key attribute depends non-transitively on the primary key.

(b) SELECT * FROM HOSPITALWHERE department = “Cardiology”;

(c) SELECT name FROM HOSPITALWHERE department = “Orthopaedic” and SEX = “F”;

(d) SELECT name FROM HOSPITALORDER BY dateofadm;

(e) SELECT name, charges, age FROM HOSPITAL WHERE SEX = “M”;

Page 9: AI1998

Examination Paper 9

(f) SELECT COUNT(*) FROM HOSPITALWHERE 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 V W H0 0 0 10 0 1 10 1 0 00 1 1 01 0 0 11 0 1 11 1 0 01 1 1 0

Ans. (a) Absorption law states that(i) X + X.Y = X

(ii) X(X+Y) = XTruth Table

X Y X.Y X+X.Y0 0 0 00 1 0 01 0 0 11 1 1 1

(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

Page 10: AI1998

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

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

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

(f) The Boolean expression X + YZ' using NAND gate is :

(g) G(U,V,W) = (U+V'+W) . (U+V'+W') . (U'+V'+W) . (U'+V'+W')7. (a) What are repeaters ? 1

(b) What is the purpose of using a MODEM ? 1(c) Write the two advantages and two disadvantages of the following topologies in network : 2

(i) Bus Topology(ii) Star Topology.

(d) What is the difference between LAN and Internet ? 1Ans. (a) 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.(b) The modem is used to convert digital data into analog form and vice versa.(c) (i) Advantages of BUS topology

1. Short cable length2. Easy to extend.Disadvantages of BUS topology1. Fault diagnosis is difficult2. Nodes must be intelligent to select the data send.

(ii) Advantages of STAR topology1. One Device per connection2. Easy to access.Disadvantages of STAR topology1. Long cable length2. Central node dependency

(d) LAN is confined to one or nearby building but Internet has no specific geographical area. Internet isthe collection of different LANs. It is the example of WAN.

x+yz'

x

zy

x

y

x sum = x + y

carry = x . y

00 0100

xyzw

11 10

01

11

10

111

1

11

1111

x z