Академический Документы
Профессиональный Документы
Культура Документы
[All India]
Maximum Marks : 70
Note.
Duration : 3 Hours
1. (a) Illustrate the use of this pointer with the help of an example.
(b) Name the header file, to which following built- in function belong :
(i) strcpy()
(ii) isdigit()
(iii) log()
(iv) puts()
(c) Will the following program execute successfully ? If not, state the reason(s).
2
2
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;
}
#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
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;
}
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 number
name
20 characters
marks
an array of 5 floating point values
average
average marks obtained
getavg()
to compute the average obtained in five subjects
Public 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 :
4
class A
{
void anyval();
protected :
int x, y;
public :
void getvalA();
void putvalA();
};
class B : protected A
{
int a, b;
protected :
int c, d;
Examination Paper
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;
}
};
(c)
3. (a)
(b)
(c)
(d)
(e)
(f)
(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.
Suppose X, Y, Z are arrays of integers of size M,N and M+N respectively. The numbers in array X and
Y appear in descending order. Write a user defined function in C++ to produce third array Z by
merging arrays X and Y in descending order.
4
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
What is the pre-condition for applying binary algorithm ?
1
Differentiate between a LIFO list and FIFO list.
1
Evaluate the following postfix expression using a stack. Show the contents of stack after execution
of each operation :
2
TRUE, FALSE, TRUE, FALSE, NOT, OR,TRUE, OR, OR, AND
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";
Examination Paper
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
4. (a) Name the stream classes supported by C++ for file input and output.
(b) Consider the following class declaration :
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;}
};
1
4
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 function
void data_read();
void data_show();
int main()
{
data_read();
data_show();
return 0;
}
void data_read()
{
employee emp; // Declares the employee object
fstream empfile;
empfile.oepn("EMP.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++)
{
emp.input();
empfile,write((char *)&emp, sizeof(employee));
}
empfile.close();
}
void data_show()
{
employee emp; // Declares the employee object for read operation
float tsalary = 0.0 // A temporary salary
fstream 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-one
tsalary = emp.retsal(); // Transfer the salary into tsalary
if (tsalary >= 10000 && tsalary <= 20000) // Checks the condition
emp.show(); // Display the output through the member function
if (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
Examination Paper
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
2
DIVAKAR 450
COMPUTER SC
68
1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
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
8
RUBINA
450
MATHEMATICS
68
1
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
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
Second Normal Form: A table is said to be in 2NF if it is in 1N and each non-key attribute is functionally
dependent 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
VINOD
DIVAKAR
ALOK
DIVYA
RAJAN
ARUN
VINOD
SABINA
MAHESH
JOHN
RAJAN
ROBERT
VINOD
RUBINA
MAHESH
VIKAS
ALOK
MOHAN
MAHESH
6. (a) State DeMorgans 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
F
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
0
1
1
1
1
Ans. (a) DeMorgans Law : This is the most powerful law of Boolean algebra. This states that :
(i) (A + B)' = A'.B'
(ii) (A.B)' = A' + B'
A
A.B
(A.B)'
A'
B'
A' + B'
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
10
1
1
F = Z' + ZW
(d) The truth table for a Full-adder :
A
SUM
CARRY
(e) Circuit diagram for the Boolean function F(X, Y, Z) = (X' + Y)(Y' + Z) using NOR gates as :
X'
(X' + Y)
(X' + Y)(Y'+Z)
Y
Z
(f)
7. (a)
(b)
(c)
(d)
Ans. (a)
(Y' + Z)
(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 node
or at intermediate wiring closets. These provide easy occurs for service or re-configuration of
the network.
(ii) One device per connection : In star topology, failure of a single connection typically involves
disconnecting 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.
Examination Paper
13