ai2000.pdf
TRANSCRIPT
![Page 1: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/1.jpg)
Examination Paper 1
Examination Papers, 2000[All India]
Maximum Marks : 70 Duration : 3 Hours
Note. All the questions are compulsory.Programming Language : C++
1. (a) Illustrate the use of this pointer with the help of an example. 2(b) Name the header file, to which following built- in function belong : 2
(i) strcpy() (ii) isdigit() (iii) log() (iv) puts()(c) Will the following program execute successfully ? If not, state the reason(s). 2
#include<iostream.h>void main(){
int x, sum = 0;cin<<n;for (x=1, x<100, x+=2)
if x % 2= =0sum+=x;
cout<<"SUM=">>sum;}
(d) Give the output of the following program segment(Assume all required header files are included inthe program) : 2char *s = "GOODLUCK";for (int x = 0;x<strlen(s)–1 ; x>=0; x––){
for ( int y=0; y<=x; y++) cout<<s[y];cout<<endl;
}(e) Write the output of the following program : 3
#include<iostream.h>int a=3;void demo(int x, int y, int &z){
a += x+y;z = a+y;y += x;cout<<x<<y<<z<<endl;
}void main(){
int a=2, b=5;demo(: :a, a, b);cout<<: : a <<a<<b<<endl;demo(: : a , a, b );
}(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 : 41 + x/1! + x3/2! + x5/3! + x7/4! + x9/5! + … + x2n-1/n!
![Page 2: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/2.jpg)
2 Together with ®®®®® Computer Science (C++) – XII
Ans. (a) While manipulating objects for user programs, C++ maintains an internal pointer called this, to pointto the current object being operated upon. Whenever a member function of an object is called, thecompiler places the address of the object in pointer this before invoking the function. For example :class xyz {
int a;public:
void read();{
cin>>a;}void display(){
cout<<"\n a = "<<this->a;}
};In the above class xyz, a pointer this has been used to print the value of an even though the pointerhas not been declared anywhere.
(b) (i) strcpy() : string.h(ii) isdigit() : ctype.h
(iii) log() : math.h(iv) puts() : stdio.h
(c) The correct program is :# include<iostream.h>main(){
int x,sum = 0;int n;cin>>n;for (x = 1; x < 100;x+=2)
if( x%2 == 0)sum += x;
cout << "SUM = " << sum;}Correction 1 : Undefined symbol ‘n’Correction 2 : Illegal structure operation cin<<nCorrection 3 : for statement missing ( for x = 1, x<100;x+=2)Correction 4 : If statement missing if x%2 == 0Correction 5 : Illegal structure operation cout>> “SUM = ” >>sum;
(d) The output is :GOODLUCKGOODLUCGOODLUGOODLGOODGOOGOG
(e) The output of the given program is :3510821081020
![Page 3: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/3.jpg)
Examination Paper 3
(f) The function is :int fact(int num){
double prod=1;int i=1;while(i<=num){
prod=prod*i;i++;
}return(prod);
}double sum(double x, int n){
double s;s = 1;double t=0;int i,j = 1;for(i=1;i<n;i++){
t = pow(x,j);s = s + t / (fact(i));j = j + 2;
}return(s);
}2. (a) What is the use of a constructor function in a class ? Give a suitable example of a constructor
function in a class. 2(b) Define a class report with the following specification : 4
Private members :adno 4 digit admission numbername 20 charactersmarks an array of 5 floating point valuesaverage average marks obtainedgetavg() to compute the average obtained in five subjectsPublic members :readinfo() function to accept values for adno, name, marks, and invoke the function getavg().displayinfo() function to display all data members on the screen you should give function definitions.
(c) Consider the following and answer the questions given below : 4class A{
void anyval();protected :
int x, y;public :
void getvalA();void putvalA();
};class B : protected A{
int a, b;protected :
int c, d;
![Page 4: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/4.jpg)
4 Together with ®®®®® Computer Science (C++) – XII
void getvalB;public :
void putvalB( );};class C : public B{
int P;protected :
int q;void getval( );
public :void showval( );
};(i) Name all the member functions, which are accessible by the objects of class C.
(ii) Name all the protected members of class B.(iii) Name the base class and derived class of class B.(iv) Name the data members, which are accessible from member functions of class C.
Ans. (a) Constructor function is required in classes to create the object. It is used to initialize the datamembers of the class. For example :# include<iostream.h>class xyz{
int a,b;public:
void read();xyz() //Constructor{
a = 0;b = 0;
}};
(b) The class is :class report{
int adno;char name[20];float marks[5];float average;float getavg( ){
return ((marks[0] + marks[1] + marks[2] + marks[3] + marks[4])/5);}public :
void read_info( );void displayinfo( );
};void report :: read_info( )
{clrscr( );cout << "Enter the student no. : ";cin >> adno;cout << "Enter the student name : ";gets(name);cout << "Enter marks in five subject : ";
![Page 5: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/5.jpg)
Examination Paper 5
for (int I =0;I<5;I++)cin >> marks[I];
average = getavg( );}void report :: displayinfo( ){
clrscr();cout << "Student No. : " << adno << endlcout << "Student Name : " << name << endl;for(int I =0;I<5;I++)
cout << "Marks in " << (I+1) << " subject " << marks[I] << endl;cout << "Average : "<<average<<endl;
}(c) (i) The member functions, which are accessible by the objects of class C are putval() and showval().
(ii) Protected member of class B : c, d, getvalB(), x, y(iii) Base class : class A
Derived class : class C(iv) The data members are : x, y, c, d, p, q.
3. (a) Suppose X, Y, Z are arrays of integers of size M,N and M+N respectively. The numbers in array X andY appear in descending order. Write a user defined function in C++ to produce third array Z bymerging arrays X and Y in descending order. 4
(b) An array DATA[1..10][1..10] requires 8 bytes of storage. If the base address of array DATA is 1500,determine the location of DATA [4][5], when the array DATA is stored
(i) Row Wise (ii) Column wise. 3(c) What is the pre-condition for applying binary algorithm ? 1(d) Differentiate between a LIFO list and FIFO list. 1(e) Evaluate the following postfix expression using a stack. Show the contents of stack after execution
of each operation : 2TRUE, FALSE, TRUE, FALSE, NOT, OR, TRUE, OR, OR, AND
(f) Give the necessary declarations of a queue containing integers. Write a user defined function in C++to delete an integer from the queue. The queue is to be implemented as a linked structure. 4
Ans. (a) // Function to manipulation of two arrays X and Y for a merging in third array Z with// descending order.const M = 10;const N = 10;void merge(){
clrscr();int X[M];int Y[N];int Z[M+N];int i,j,k;cout << "\n\tEnter the first array in descending order\n";for(i=0;i<M;i++){
cout << "\t";cin >> X[i];
}cout << "\n\tEnter the second array in descending order\n";for(i=0;i<N;i++){
cout << "\t";
![Page 6: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/6.jpg)
6 Together with ®®®®® Computer Science (C++) – XII
cin>>Y[i];}i=0,j=0,k=0;// Merging the first and second arraywhile((i<M)&&(j<N)){
if(X[i]<Y[j]){
Z[k]=Y[j];j+=1;k+=1;
}else{
Z[k]=X[i];i+=1;k+=1;
}}while(i<M){
Z[k]=X[i];i+=1;k+=1;
}while(j<N){
Z[k]=Y[j];j+=1;k+=1;
}clrscr();cout << "\n\tThe merged arrays are ";for(k=0;k<(M+N);k++)
cout<<“\n”<<Z[k];}
(b) Given :Base = 1500W = 8 bytesN = 10M = 10I = 4J = 5To find Row Major OrderThe formula is applied :VAL[I][J]= B +((I-1)* N+(J-1))*W
= 1500+((4-1)* 10 + (5-1))* 8= 1500 + (34)*8= 1500 + 272= 1772 (Ans.)
To find Column Major OrderThe formula is applied :VAL[I][J] = B +((J-1) * M +(I-1)) * W
![Page 7: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/7.jpg)
Examination Paper 7
= 1500 +((4-1) + 10 * (5-1)) *8= 1500 +(43) * 8= 1500 + 344= 1844
(c) The precondition for the binary search is that the array should be sorted in advance.(d) The LIFO stands for Last In First Out. In this data structure, the elements inserted in the last is
deleted first. E.g stack.The FIFO stands for First In First Out. In this data structure, the element inserted first will delete first,e.g; queue.
(e) In the given expression true and false are operand and AND, NOT and OR are operator.(i) true
true(ii) false
true false(iii) true
true false true(iv) false
true false true false(v) NOT
NOT is operatorPOP one operandNOT false = truePUSH true on stacktrue false true true
(vi) OROR is operatorPOP TWO operandEvaluate : true OR true = truePUSH true on stacktrue false true
(vii) truetrue false true true
(viii) OROR is operatorPOP TWO operandEvaluate : true OR true = truePUSH true on stacktrue false true
(ix) OROR is operatorPOP TWO operandEvaluate : true OR false = truePUSH true on stacktrue true
(x) ANDOR is operatorPOP TWO operand
![Page 8: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/8.jpg)
8 Together with ®®®®® Computer Science (C++) – XII
Evaluate : true AND true = truePUSH true on stacktrue
(f) // Declares a queue structurestruct node{
int data;node *link;
};// Function body for delete an integer from the queuenode *del_Q(node *front, int &val) {
node *temp;clrscr();if (front == NULL) {
cout << "Queue Empty ";val = -1;
}else{
temp = front;front = front->link;val = temp->data;temp->link = NULL;delete temp;
}return (front);
}4. (a) Name the stream classes supported by C++ for file input and output. 1
(b) Consider the following class declaration : 4class employee{
int code;char name [20];float salary;public :
void input( ) {cin>>code>>name>>salary;}void show( ) {cout<<code<<name<<salary<<endl;}float retsal( ) {return salary;}
};Give function definitions to do the following :
(i) Write the objects of employee to a binary file.(ii) Read the objects of employee from a binary file and display all the objects on the screen where
salary is between Rs. 10,000 and Rs. 20,000.Ans. (a) The stream classes are fstream, ofstream, ifstream.
(b) // Program to demonstrate the file operation# include <fstream.h>#include <conio.h>#include <string.h>#include <stdio.h>#include <process.h>class employee // Class declaration{
int code; // Private data members
![Page 9: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/9.jpg)
Examination Paper 9
char name[20];float salary;public : // Public member functions
void input() { cin>>code>>name>>salary; }void show() { cout << code<<name<<salary<<endl; }float retsal() { return salary; }
};// General functioin to operate the class member functionvoid data_read();void data_show();int main(){
data_read();data_show();return 0;
}void data_read(){
employee emp; // Declares the employee objectfstream empfile;empfile.oepn("EMP.dat", ios::app|ios::out|ios::binary); // Creates the data fileint n, i;clrscr();cout << "Enter how many records U want to enter ";cin >> n;for (i=0; i<n; i++){
emp.input();empfile,write((char *)&emp, sizeof(employee));
}empfile.close();
}void data_show(){
employee emp; // Declares the employee object for read operationfloat tsalary = 0.0 // A temporary salaryfstream empfile;empfile.open("EMP.dat", ios::in|ios::binary);empfile.seekg(0, ios::beg);if (!empfile)
cout << "File does not exists";while (empfile){
empfile.read((char *)&emp, sizeof(employee)); // Reads the record one-by-onetsalary = emp.retsal(); // Transfer the salary into tsalaryif (tsalary >= 10000 && tsalary <= 20000) // Checks the condition
emp.show(); // Display the output through the member functionif (empfile.eof()) // If there is no record, it terminates the loop
exit(0);}empfile.close();
}5. (a) Differentiate between SQL commands DROP TABLE and DROP VIEW. Define Second Normal Form.
2
![Page 10: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/10.jpg)
10 Together with ®®®®® Computer Science (C++) – XII
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345123456789012345678901234567890121234567890123456789012345678901212345678901234567890123456789012123451234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234512345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
Write SQL commands for (b) to (f) and write the outputs for (g) on the basis of table GRADUATE :Table : GRADUATE
SNO NAME STIPEND SUBJECT AVERAGE DIV1 KARAN 400 PHYSICS 68 12 DIVAKAR 450 COMPUTER SC 68 13 DIVYA 300 CHEMISTRY 62 24 ARUN 350 PHYSICS 63 15 SABINA 500 MATHEMATICS 70 16 JOHN 400 CHEMISTRY 55 27 ROBERT 250 PHYSICS 64 18 RUBINA 450 MATHEMATICS 68 19 VIKAS 500 COMPUTER SC 62 110 MOHAN 300 MATHEMATIC 57 2
(b) List the names of those students who have obtained Div 1 sorted by NAME. 1(c) Display the report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month. 1(d) To count the number of students who are either PHYSICS or COMPUTER SC graduates. 1(e) To insert a new row in the GRADUATE table : 1
11, “KAJOL”, 300, “COMPUTER SC “, 75, 1(f) Give the output of following SQL statement based on table GRADUATE : 2
(i) Select MIN(AVERAGE ) from GRADUATE where SUBJECT= “PHYSICS”;(ii) Select SUM(STIPEND) from GRADUATE where DIV = 2;
(iii) Select AVG(STIPEND) fromGRADUATE where AVERAGE >= 65;(iv) Select COUNT(DISTINCT SUBJECT) from GRADUATE;
(g) Assume that there is one more table GUIDE in the database as shown below : 2Table : GUIDE
MAINAREA ADVISORPHYSICS VINODCOMPUTER SC ALOKCHEMISTRY RAJANMATHEMATICS MAHESH
What will be the output of the following query :SELECT NAME, ADVISORFROM GRADUATE, GUIDEWHERE SUBJECT = MAINAREA;
Ans. (a) DROP TABLE DROP VIEW1. This command drops a table from a 1. This command drops a view (Virtual table with no
database physically. physical data)2. The condition for dropping a table is 2. Deletion of rows is not necessary.
that it must be an Empty table.
![Page 11: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/11.jpg)
Examination Paper 11
Second Normal Form: A table is said to be in 2NF if it is in 1N and each non-key attribute is functionallydependent on the entire key.
(b) SELECT NAME FROM GRADUATE WHERE DIV = 1 ORDER BY NAME;(c) SELECT NAME, STIPEND, SUBJECT , STIPEND *12 FROM GRADUTE;(d) SELECT COUNT(*) FORM GRADUATE
where (SUBJECT = “PHYSICS” OR SUBJECT = “COMPUTER SC”);(e) INSERT INTO GRADUATE VALUES (11, “KAJOL”, 300, “COMPUTER SC”,75,1);(f) (i) 63 (ii) 1000 (iii) 450 (iv) 4(g) NAME ADVISOR
KARAN VINODDIVAKAR ALOKDIVYA RAJANARUN VINODSABINA MAHESHJOHN RAJANROBERT VINODRUBINA MAHESHVIKAS ALOKMOHAN MAHESH
6. (a) State DeMorgan’s Laws. Verify them using truth table. 2(b) Prove (A+B). (A'+C) = (A+B+C). (A+B + C'). (A'+B+C). (A'+B'+C)algebraically. 2(c) Obtain simplified from for a Boolean expression 3
F(X, Y, Z, W) = Σ(0, 1, 4, 5, 7, 8, 9, 12, 13, 15) using K Map method.(d) Give the truth table for a Full – adder. 1(e) Draw the circuit diagram for the Boolean function F(X,Y,Z) = (X'+Y)(Y'+Z) using NOR gates only.1(f) Express in the POS form, the Boolean function F(A,B,C), the truth table for which is given below :1
A B C F0 0 0 00 0 1 10 1 0 00 1 1 11 0 0 01 0 1 11 1 0 01 1 1 1
Ans. (a) DeMorgan’s Law : This is the most powerful law of Boolean algebra. This states that :(i) (A + B)' = A'.B'
(ii) (A.B)' = A' + B'
A B A.B (A.B)' A' B' A' + B'0 0 1 1 1 1 10 1 0 1 1 0 11 0 0 1 0 1 11 1 1 0 0 0 0
![Page 12: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/12.jpg)
12 Together with ®®®®® Computer Science (C++) – XII
(b) L.H.S = (A + B)(A' + C)= (A + B + C.C')(A' + C + B.B') [X.X' = 0]= (A + B + C)(A + B + C')(A' +C + B)(A' + C + B')= (A + B + C)(A + B + C')(A' + B + C)(A' + B' + C)
(c) F(X, Y, Z, W) = S(0, 1, 4, 5, 7, 9, 12, 13, 15)
F = Z' + ZW(d) The truth table for a Full-adder :
A B C SUM CARRY0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1
(e) Circuit diagram for the Boolean function F(X, Y, Z) = (X' + Y)(Y' + Z) using NOR gates as :
(f) (A + B + C)(A + B' + C)(A' + B + C)(A' + B' + C)7. (a) What are Repeaters ? 1
(b) Name the device used to connect a computer to an analog telephone line. 1(c) Briefly mention two advantages and two disadvantages of Star topology in network. 2(d) What is the difference between MAN and WAN ? 1
Ans. (a) Sometimes the signals on the Internet are become weaker before reaching the destination node.Repeater is used to regenerate data and voice signals when they become weaker before reachingdestination node. Repeater read the incoming signals and amplifies it and transmit to another segmentof the network.
00 0100
XYZW
11 10
01
11
10
1
11
11
11
111
X'
Y’
(X' + Y)(Y'+Z)Y
Z
(X' + Y)
(Y' + Z)
![Page 13: AI2000.pdf](https://reader036.vdocuments.us/reader036/viewer/2022080913/563dbb13550346aa9aaa0a1a/html5/thumbnails/13.jpg)
Examination Paper 13
(b) MODEM(c) Advantages of Star Topology :
(i) Ease of service - The star topology has a number of concentration point i.e., at the central nodeor at intermediate wiring closets. These provide easy occurs for service or re-configuration ofthe network.
(ii) One device per connection : In star topology, failure of a single connection typically involvesdisconnecting one node from an other.
Disadvantages of Star Topology :(i) Long cable length : Because each node in star topology is directly connected to the center, the
star topology requires a large quantity of cable.(ii) Central node dependency : If the central node fails the network get failed.
(d) The difference between WAN and MAN are :(i) In MAN the distance between the nodes is limited, i.e., up to one small city or town. But there
is no upperlimit in WAN.(ii) WAN operate at much higher speed than MAN.
(iii) MAN provide means for internetworking of local networks.