Академический Документы
Профессиональный Документы
Культура Документы
[Delhi]
Maximum Marks : 70 Duration : 3 Hours
Note. All the questions are compulsory.
Programming Language : C++
1. (a) What is the difference between call by value and call by reference in a user defined function in
C++ ? Give an example to illustrate the same. 2
(b) Name the header file, to which the following built-in functions belong : 1
(i) strcpy () (ii) gets( )
(c) Rewrite the following program after removing all the syntax error(s), if any . 2
#include (iostream.h)
void main( )
{
int X[ ]={60, 50, 30, 40}, Y; Count=4;
cin>>Y;
for ( I = Count–1; I>=0; I––)
switch (I)
{
case 0 :
case 2 : cout<<Y*X[I]<endl; break;
case 1 :
case 3 : cout>>Y+X[I];
}
}
(d) Give the output of the following program : 3
#include <iostream.h>
struct Point
{
int X,Y;
};
void Show(Point P)
{
cout<<P.X<< ‘ : ’<<P.Y<<endl;
}
void main( )
{
Point U = {20, 10}, V, W;
V = U;
V.X +=20;
W = V;
U.Y+=10;
U.X+=5;
W.X – = 5;
Show(U);
Show(V);
Show(W);
}
(e) Write the output of the following program : 3
#include <iostream.h>
int Calc (int U)
Examination Paper 1
{
if (U%2= =0)
return U+10;
else
return U*2;
}
void Pattern (char M, int B=2)
{
for(int CNT=0;CNT<B;CNT++)
cout<<Calc(CNT)<<M;
cout<<endl;
}
void main( )
{
Pattern(‘*’);
Pattern(‘#’,4);
Pattern(‘@’,3);
}
(f) Write a C++ function SUMFUN( ) having two parameters X (of type double) and n(of type integer)
with a result type as double to find the sum of the series given below : 4
x2 x3 xn
x+ + +... +
3! 5! (2n – 1)!
Ans. (a) In call by value method, the called function creates its own copy of argument values and uses them.
Any changes, that are made, occur on the called function’s copy of values and are not reflected back
to the calling function. For example, in the example given below the values of a and b remain the same
even after calling the function swap :
void swap(int x,int y)
{
int t;
t = x;
x = y;
y = z;
}
main()
{
int a=5;
int b = 7;
swap(a,b);
cout<<a<<","<<b;
}
In call by reference method, in place of passing a value to the function being called a reference to the
original value is passed. Any changes, that occur, take place on the original values and are reflected
to the data. For example, in the example given below the values of a and b get changed after calling
the function swap :
void swap(int &x,int &y)
{
int t;
t = x;
x = y;
y = z;
}
main()
Examination Paper 3
— Title 20 characters
— Duration float
— Noofepisodes integer
public member function of class Serial
— A constructor function to initialise Duration as 30 and Noofepisodes as 10.
— NewSerial( ) function to accept values for Serialcode and Title
— Otherentries( ) function to assign the values of Duration and Noofepisodes with the help of
corresponding values passed as parameters to this function.
— Dispdata( ) function to display all the data members on the screen.
(c) Consider the following and answer the questions given below : 4
class University
{
int NOC; // Number of Colleges
protected :
char Uname[25]; // University Name
public :
University( );
char State[25];
void EnterData( );
void DisplayData( );
};
class College : public University
{
int NOD; // Number of Departments
char Cname[25]; // College Name
protected:
void Affiliation( );
public :
College( );
void Enrol(int,int);
void Show( );
};
class Department : public College
{
char Dname[25]; // Department
int Nof; // No of faculty members
public :
Department();
void Display();
void Input();
};
(i) Which class’s constructor will be called first at the time of declaration of an object of class
Department ?
(ii) How many bytes does an object belonging to class Department require ?
(iii) Name the member function(s), which are accessed from the object(s) of class Department.
(iv) Name the data member(s), which are accessible from the object(s) of class College.
Ans. (a) The polymorphism contains three words as : poly means many or multiple; morph means to change
from one thing to another; and ism means the process of something. Function overloading implements
polymorphism.
// Program using function overloading to calculate the area of rectangle,
// area of triangle using Hero’s formula and area of circle.
#include <iostream.h>
#include <conio.h>
Examination Paper 5
(b) The class is as :
class Serial
{
private:
int Serialcode
char Title[25];
float Duration;
int Noofepisodes;
public:
Serial(){ Duration = 30; Noofepisodes = 10;}
void Newserial () { cin>>Serialcode; cin>>Title;}
void Otherentries (int x, int y){ Duration =x; Noofepisodes = y; }
void Dispdata() { cout<<Serialcode<<Title<<Duration<<Noofepisodes; }
};
(c) (i) Constructor of University class
(ii) The Department require 106 bytes
(iii) void Display(), void Input(), void Enrol(int,int), void Show(), void EnterData(), void
DisplayData().
(iv) char state[25]
3. (a) Assume an array S containing elements of structure Student is required to be arranged in descending
order of Marks. Write a C++ function to arrange the same with the help of bubble sort. The array and
its size is required to be passed as parameters to the function. Definition of structure Student is as
follows : 4
struct Student
{
int Rollno;
char Name[25];
float Marks;
};
(b) An array V[15][30] is stored in the memory with each element requiring 8 bytes of storage. If the base
address of V is 5300, find out memory locations of X[8][12] and V[12][2], if the array is stored along
the row. 3
(c) Write the user-defined function in C++ to display those elements of a two dimensional array M[5][5]
which are divisible by 10. Assume the content of the array is already present and the function
prototype is as follows : 2
void Display10(int M[5][5]);
(d) Evaluate the following postfix expression using a stack and show the contents of stack after execution
of each operation : 2
120, 45, 20,+, 25, 15, –, +, *
(e) Consider the following portion of a program, which implements passengers Queue for a bus. Write
the definition of function Insert (whose prototype is shown below); to insert a new node in the queue
with required information : 4
struct NODE
{
int Ticketno;
char PName[20]; //Passenger Name
NODE * NEXT;
};
class Queueofbus
{
NODE *Rear, *Front;
Examination Paper 7
Input 45
120 45
Input 20
120 45 20
Input +
120 65 Pop(20) + Pop(45)
Push(65)
Input 25
120 65 25
Input 15
120 65 25 15
Input –
120 65 10 Pop(25) – Pop(15)
Push(10)
Input +
120 75 Pop(10) + Pop(65)
Push(75)
Input *
9000 Pop(75) * Pop(120)
Push(9000)
(e) // Function to insert passenger in a queue
void Queueofbus::insert()
{
NODE *temp;
cout<< "Enter the details ";
cin>>temp–>Ticketno;
gets(temp–>PName);
temp–>Next = NULL;
if (rear == NULL)
{
rear = temp;
front = rear;
}
else
{
rear –> Next =temp;
rear = temp;
}
}
4. (a) Write a user defined function in C++ to read the content from a text file STORY.TXT, count and
display the number of alphabets present in it. 2
(b) Assuming a binary file JOKES.DAT is containing objects belonging to a class JOKE(as defined
below). Write a user defined function in C++ to add more objects belonging to class JOKE at the
bottom of it. 3
class JOKE
{
int Jokeid; // Joke Identification number
char Type[5]; // Joke Type
Examination Paper 9
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
6 Donald Baby cot 24/02/02 6500 15
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
7 Royal Finish Office Table 20/02/02 18000 30
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
8 Royal tiger Sofa 22/02/02 31000 30
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
9 Econo sitting Sofa 13/12/01 9500 25
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
10 Eating Paradise Dining Table 19/02/02 11500 25
12345678901234567890123456789012123456789012345678901234567890121234567890123456789012345678901212345
Table :ARRIVALS
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
11 Wood Comfort Double Bed 23/03/03 25000 25
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
12 Old Fox Sofa 20/02/03 17000 20
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
13 Micky Baby cot 21/02/03 7500 15
1234567890123456789012345678901212345678901234567890123456789012123456789012345678901234567890121234
(b) To show all information about the Baby cots from the FURNITURE table. 1
(c) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table. 1
(d) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from the
FURNITURE table in descending order of ITEMNAME. 1
(e) To display ITEMNAME and DATEOFSTOCK of those items, in which the DISCOUNT percentage is
more than 25 from FURNITURE table. 1
(f) To count the number of items, whose TYPE is “Sofa” from FURNITURE table. 1
(g) To insert a new row in the ARRIVALS table with the following data : 1
14, “Velvet touch”, “Double bed”, {25/03/03},25000, 30
(h) Give the output of following SQL statement : 2
NOTE : Outputs of the below mentioned queries should be based on original data given in both the
tables, i.e., without considering the insertion done in (g) part of this question :
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE,ARRIVALS;
(iii) Select AVG(DISCOUNT) from FURNITURE where TYPE = “Baby cot”;
(iii) Select SUM(PRICE) from FURNITURE where DATEOFSTOCK<{12/02/02};
Ans. (a) Normalisation is a process of data analysis used for grouping data elements in a record. While
dealing with database there may be unnecessary repetition of data, which can pose problems in
storing, and retrieving the data. The unnecessary repetition of data is called redundancy. Normalisation
is the process of analysing data. So, the redundancy gets reduced.
Primary key : It is also called as key field and uniquely identifies a particular record in a file.
(b) SELECT * from FURNITURE where Type = “Baby cot”;
(c) SELECT ITEMNAME from FURNITURE where price>15000;
(d) SELECT ITEMNAME, TYPE from FURNITURE where DATEOFSTOCK<{22/01/02}
order by ITEMNAME DESC;
(e) SELECT ITEMNAME , DATEOFSTOCK from FURNITURE where discount>25;
(f) SELECT count(TYPE) from FURNITURE where TYPE = “Sofa”;
(g) INSERT INTO ARRIVALS values (14, “Velvet touch”, “Double Bed”,{25/03/03},25000,30);
(h) (i) 5 (ii) 30,25 (iii) 15 (iv) 66500
6. (a) State Absorption Laws. Verify one of the Absorption Laws using a truth table. 2
(b) Verify X.Y' + Y'.Z = X.Y'.Z + X.Y'Z' + X'Y'.Z algebraically. 1
(c) Write the dual of the Boolean expression A + B'.C. 1
Examination Paper 11
(e) The logic circuit for a Half Adder is :
x sum = x + y
y
carry = x . y