Documente Academic
Documente Profesional
Documente Cultură
[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= =0
sum+=x;
cout<<"SUM=">>sum;
}
(d) Give the output of the following program segment(Assume all required header files are included in
the program) : 2
char *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 : 4
1 + x/1! + x3/2! + x5/3! + x7/4! + x9/5! + … + x2n-1/n!
Examination Paper 1
Ans. (a) While manipulating objects for user programs, C++ maintains an internal pointer called this, to point
to the current object being operated upon. Whenever a member function of an object is called, the
compiler 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 pointer
has 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<<n
Correction 3 : for statement missing ( for x = 1, x<100;x+=2)
Correction 4 : If statement missing if x%2 == 0
Correction 5 : Illegal structure operation cout>> “SUM = ” >>sum;
(d) The output is :
GOODLUCK
GOODLUC
GOODLU
GOODL
GOOD
GOO
GO
G
(e) The output of the given program is :
3510
8210
81020
Examination Paper 3
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 data
members 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 : ";
Examination Paper 5
cin>>Y[i];
}
i=0,j=0,k=0;
// Merging the first and second array
while((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 = 1500
W = 8 bytes
N = 10
M = 10
I=4
J=5
To find Row Major Order
The 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 Order
The formula is applied :
VAL[I][J] = B +((J-1) * M +(I-1)) * W
Examination Paper 7
Evaluate : true AND true = true
PUSH true on stack
true
(f) // Declares a queue structure
struct node
{
int data;
node *link;
};
// Function body for delete an integer from the queue
node *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 : 4
class 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
Examination Paper 9
Write SQL commands for (b) to (f) and write the outputs for (g) on the basis of table GRADUATE :
Table : GRADUATE
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
SNO NAME STIPEND SUBJECT AVERAGE DIV
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
1 KARAN 400 PHYSICS 68 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
2 DIVAKAR 450 COMPUTER SC 68 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
3 DIVYA 300 CHEMISTRY 62 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
4 ARUN 350 PHYSICS 63 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
5 SABINA 500 MATHEMATICS 70 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
6 JOHN 400 CHEMISTRY 55 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
7 ROBERT 250 PHYSICS 64 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
8 RUBINA 450 MATHEMATICS 68 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
9 VIKAS 500 COMPUTER SC 62 1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
10 MOHAN 300 MATHEMATIC 57 2
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
(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) SelectAVG(STIPEND) fromGRADUATE whereAVERAGE >= 65;
(iv) Select COUNT(DISTINCT SUBJECT) from GRADUATE;
(g) Assume that there is one more table GUIDE in the database as shown below : 2
Table : GUIDE
MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH
What will be the output of the following query :
SELECT NAME, ADVISOR
FROM GRADUATE, GUIDE
WHERE SUBJECT = MAINAREA;
Ans. (a) DROP TABLE DROP VIEW
1. 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.
Examination Paper 11
(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)
ZW
XY 00 01 11 10
00 1 1
01 1 1 1
11 1 1 1
10 1 1
F = Z' + ZW
(d) The truth table for a Full-adder :
A B C SUM CARRY
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
(e) Circuit diagram for the Boolean function F(X, Y, Z) = (X' + Y)(Y' + Z) using NOR gates as :
X' (X' + Y)
Y
(X' + Y)(Y'+Z)
Y’
Z (Y' + Z)
Examination Paper 13