Old Questions and Answers
Old Questions and Answers
CLASS – XII
[email protected] [email protected]
PGT-ITof JNV West Godavari
Dear Faculty/Children,
Phone: 9490236965
9949001361
Yours ….
Ever….Dear….
Faculty & Friend
M.Ravi Kiran
Chap 9: Arrays
Ans) iomanip.h
iostream.h
Ans)#include<iostream.h>
void Jumpto(int N1,int N2=20); //Prototype missing
void main( )
{
int First = 10, Second = 20; //Data type missing
Jumpto(First,Second); //Comma to come instead of ;
Jumpto(Second);
}
void Jumpto(int N1, int N2)
{
N1=N1+N2;
cout<<N1<<N2; //Output operator << required
}
When I=0
Since Text[0] is ‘M’, Upper Case Letter,
(isupper(Text[I]) will becomes true.
So Text[I] =Text[I]+1
So Text[0]=Text[0]+1
Text[0] =77(ASCII Value of M) + 1 = 78 =N(78 is ASCII Value
of N)
Now the String Text[ ] =
When I=1
Since Text[1] is ‘i’, Which is a character, but which is not Upper
case,
else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[1]=Text[1+1]
=Text[2]
Ie ‘n’ will be stored in place of ‘i’
Now the String Text[ ] =
When I=2
Since Text[2] is ‘n’, Which is a character, but which is not Upper
case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[2]=Text[2+1]
=Text[3]
Ie ‘d’ will be stored in place of ‘n’
Now the String Text[ ] =
When I=3
When I=4
Since Text[4] is ‘@’, Since which is not an alphabet,
(!isalpha(Text[I])) will becomes true.
Ie if(!isalpha(Text[I]))
Text[I]=’*’;
Ie Text[4]=’*’
Ie ‘*’ will be stored in place of ‘@’
Now the String Text[ ] =
When I=5
Since Text[5] is ‘W’, Upper Case Letter,
(isupper(Text[I]) will becomes true.
So Text[I] =Text[I]+1
So Text[5]=Text[5]+1
Text[5] =87(ASCII Value of W) + 1 = 88 =X(88 is ASCII Value
of X)
Now the String Text[ ] =
When I=6
Since Text[6] is ‘o’, Which is a character, but which is not Upper
case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[6]=Text[6+1]
=Text[7]
Ie ‘r’ will be stored in place of ‘o’
Now the String Text[ ] =
When I=7
Since Text[7] is ‘r’, Which is a character, but which is not Upper
case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[7]=Text[7+1]
=Text[8]
Ie ‘k’ will be stored in place of ‘r’
Prepared By: PGT-IT, JNV West Godavari 6 9 490236965,[email protected]
Now the String Text[ ] =
When I=8
Since Text[8] is ‘k’, Which is a character, but which is not Upper
case, else part will be executed.
Ie Text[I]=Text[I+1]
Here Text[8]=Text[8+1]
=Text[9]
Ie ‘!’ will be stored in place of ‘k’
Now the String Text[ ] =
When I=9
Since Text[9] is ‘!’, Since which is not an alphabet,
(!isalpha(Text[I])) will becomes true.
Ie if(!isalpha(Text[I]))
Text[I]=’*’;
Ie Text[9]=’*’
Ie ‘*’ will be stored in place of ‘!’
Now the String Text[ ] =
Output: Nnd@*Xrk!*
e) Find the output of the following program: 2
#include<iostream.h>
void main( )
{
int U=10,V=20;
for(int I=1;I<=2;I++)
{
cout<<”[1]”<<U++<<”&”<<V – 5 <<endl;
cout<<”[2]”<<++V<<”&”<<U + 2 <<endl;
}
}
Ans:
Output:
[1]10&15
[2]21&13
[1]11&16
[2]22&14
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize( );
char City[ ][10]={“DEL”,”CHN”,”KOL”,”BOM”,”BNG”};
int Fly;
for(int I=0; I<3;I++)
{
Fly=random(2) + 1;
cout<<City[Fly]<<”:”;
}
}
Outputs:
City[1] is “CHN”
City[2] is “KOL”
1.b) Name the header files that shall be needed for the following
code: 1
void main( )
{
char word[]=”Exam”;
cout<<setw(20)<<word;
}
Ans: iostream.h
iomanip.h
Prepared By: PGT-IT, JNV West Godavari 8 9 490236965,[email protected]
1.c) Rewrite the following program after removing the syntax
error(s) if any. Underline each correction. 2
#include<iostream.h>
void main( )
{
One=10,Two=20;
Callme(One;Two);
Callme(Two);
}
void Callme(int Arg1,int Arg2)
{
Arg1=Arg1+Arg2;
Count<<Arg1>>Arg2;
}
Ans:
void Callme(int Arg1,int Arg2=20);
#include<iostream.h>
void main( )
{
int One=10,Two=20;
Callme(One,Two); //Given ; instead of ,
Callme(Two);
}
void Callme(int Arg1,int Arg2)
{
Arg1=Arg1+Arg2;
cout<<Arg1<<Arg2;
}
#include<iostream.h>
void main( )
{
int A=5,B=10;
for(int I=1;I<=2;I++)
{
cout<<”Line1”<<A++<<”&”<<B-2 <<endl;
cout<<”Line2”<<++B<<”&”<<A +3 <<endl;
}
}
Ans: Output:
Line15&8
Line211&9
Line16&9
Line212&10
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize( );
char Area[ ][10]={“NORTH”,”SOUTH”,”EAST”,”WEST”};
int ToGo;
for(int I=0; I<3;I++)
{
ToGo=random(2) + 1;
cout<<Area[ToGo]<<”:”;
}
}
Outputs:
Area[1] is “SOUTH”
Area[2] is “EAST”
Prepared By: PGT-IT, JNV West Godavari 10 9 490236965,[email protected]
Since I value from 0 to 2 (ie<3), 3 iterations will takes place.
So the possible output consists 3 strings separated by :, each of
them may be either “SOUTH” or “EAST”.
2007 Delhi :
1.b) Name the header file(s) that shall be needed for successful
compilation of the following C++ code. 1
void main( )
{
char String[20];
gets(String);
strcat(String,”CBSE”);
puts(String);
}
Ans) stdio.h string.h
Prepared By: PGT-IT, JNV West Godavari 11 9 490236965,[email protected]
1. c) Rewrite the following program after removing the
syntactical error(s) if any. Underline each correction. 2
#include<iostream.h>
const int Max 10;
void main()
{
int Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc];
}
Ans)
#include<iostream.h>
const int Max=10;//Constant Variable ‘Max’ must be
//initialized. Declaration Syntax Error
void main( )
{
int Numbers[Max]={20,50,10,30,40};
for(Loc=Max-1;Loc>=0;Loc--)
cout>>Numbers[Loc];
}
#include<iostream.h>
void Withdef(int HisNum=30)
{
for(int I=20;I<=HisNum;I+=5)
cout<<I<<”,”;
cout<<endl;
}
Ans: Output:
20,25,30,
20,25,30,
Number=30
Ans: Output:
(ii) 94
Ans:
2006 Delhi:
1.b) Write the names of the header files to which the following
belong: (i) gets( ) (ii) strcmp( ) (iii)abs( ) (iv)isalnum( )
Ans:
(i) gets( ) - stdio.h
(ii) strcmp( ) - string.h
(iii) abs( ) - math.h, stdlib.h,complex.h
(iv) isalnum( ) - ctype.h
Ans: Output:
5 9
9 7
7 7
7 9
f) Write definition for a function SumSequence( ) in C++ with
two arguments/ parameters – double X and int n. The function
should return a value of type double and it should perform sum
of the following series.
1/x- 3!/x2 + 5!/x3 – 7!/x4 + 9!/x5 - ------upto n terms.
Note: The symbol ! represents Factorial of a number
ie 5!= 1 X 2 X 3 X 4 X 5.
#include<iostream.h>
#include<math.h>
#include<conio.h>
double SumSequence(int x1,int n1);
void main()
{
int x;
int n;
clrscr();
cout<<"Enter the vaue of X and N";
Prepared By: PGT-IT, JNV West Godavari 21 9 490236965,[email protected]
cin>>x>>n;
cout<<”\nThe sum of the series = “<<SumSequence(x,n);
getch();
}
double SumSequence(int x1,int n1)
{
double sum=0;
int c=0;
for(int i=1;i<=(2*n1);i=i+2)
{
int f=1;
for(int j=1;j<=i;j++)
{
f=f*j;
}
c=c+1;
if(c%2==1)
{
sum=sum+f/(pow(x1,c));
}
else
{
sum=sum-f/(pow(x1,c));
}
}
return sum;
}
2003 Annual Paper:
1.a) What is the difference between global variables and local
variables? Give an example to illustrate the same. 2
Ans: The local variables are the variables defined within any
function (or block) and are hence accessible only within the
block in which they are declared. In contrast to local variables,
variables declared outside of all the functions in a program are
called global variables. These variables are defined outside of
any function, so they are accessible to all functions. These
functions perform various operations on the data. They are also
known as External Variables.
Eg: #include<iostream.h>
int a,b;
void main()
{
float f;
---;
---;
}
In the above program segment, a and b are global variables, we
can access a and b from any function. f is local variable to
function main( ), we can access f from main( ) only.
2002:
1.b)Name the header files of C++ to which the following
functions belong:2
(i)get( ) (ii)open( ) (iii)abs( ) (iv)strcat( )
Ans:
(i) get( ) - iostream.h
(ii) open( ) - fstream.h
(iii) abs( ) - math.h, stdlib.h
(iv) strcat( ) - string.h
Prepared By: PGT-IT, JNV West Godavari 24 9 490236965,[email protected]
1.c)Find the syntax error(s), if any, in the following program. 2
#include<iostream.h>
void main( )
{
int x;
cin>>x;
for( int y=0,y<10,y++)
cout<<x+y;
}
Ans: #include<iostream.h>
void main( )
{
int x;
cin>>x;
for( int y=0;y<10;y++)
cout<<x+y;
}
1.d) Write the output of the following program. 2
void main( )
{
int x=5,y=5;
cout<<x- -;
cout<<”,”;
cout<- - x;
cout<<”,”;
cout<<y- -<<”,”<<- -y;
}
Ans: Output:
5,3,4,4
1.e)Write the output of the following program. 3
#include<iostream.h>
void X(int &A,int &B)
{
A=A+B;
B=A-B;
A=A-B;
}
void main( )
{
int a=4,b=18;
X(a,b);
cout<<a<<”,”<<b;
}
Ans: Output:
18,4
f)Write a function called zero_Small() that has two integer
arguments being passed by reference and sets the smaller of the
two numbers to 0. Write the main program to access this
function. 4
Prepared By: PGT-IT, JNV West Godavari 25 9 490236965,[email protected]
#include<iostream.h>
#include<conio.h>
void zero_Small(int &A,int &B)
{ if(A<B)
A=0;
else
B=0; }
void main( )
{ clrscr();
int a,b;
cout<<”Enter any two values…”;
cin>>a>>b;
cout<<"Initial values of a and b are ";
cout<<a<<" "<<b<<endl;
zero_Small(a,b);
cout<<endl<<"The final values of a and b are ";
cout<<a<<","<<b;
cout<<endl;
cout<<"\nPress any key to continue...";
getch(); }
2001:
1.b) Name the header file to be included for the use of the
following built in functions: (i)getc( ) (ii)strcat() 1
Ans:
(i) getc( ) - stdio.h
(ii) strcat( ) - string.h
1.e) Give the output of the following program:
#include<iostream.h>
#include<conio.h>
int g=20;
void func(int &x,int y)
{
x=x-y;
y=x*10;
cout<<x<<’,’<<y<<’\n’;
}
void main( )
{
int g=7;
func(g,::g);
cout<<g<<’,’<<::g<<’\n’;
func(::g,g);
cout<<g<<’,’<<::g<<’\n’;
}
Ans: Output:
-13,-130
-13,20
33,330
-13,33
Ans: While they both serve a similar purpose, #define and const
act differently. When using #define the identifier gets replaced
by the specified value by the compiler, before the code is turned
into binary. This means that the compiler makes the
substitution when you compile the application.
Eg: #define number 100
In this case every instance of “number” will be replaced by the
actual number 100 in your code, and this means the final
compiled program will have the number 100 (in binary).
Ans: C++ allows you to define explicitly new data type names
by using the keyword typedef. Using typedef does not actually
create a new data class, rather it defines a new name for an
existing type. This can increase the portability of a program as
only the typedef statements would have to be changed. Typedef
makes your code easier to read and understand. Using typedef
can also aid in self documenting your code by allowing
descriptive names for the standard data types.
The syntax of the typedef statement is
typedef type name;
Where type is any C++ data type and name is the new name for
this type. This defines another name for the standard type of
C++. For example, you could create a new name for float values
by using the following statement:
typedef float amount;
This statement tells the compiler to recognize amount as an
alternative name for float. Now you could create float variables
using amount.
amount loan, saving, installment;
Using typedef does not replace the standard C++ data type name
with the new name, rather the new name is in addition to the
existing name. You still can create float variables using float.
Once a new name has been defined by typedef, it can be used as
a type for another typedef also.
Eg: typedef amount money;
Now, this statement tells the compiler to recognize money
as another name for amount, which itself is another name for
float. Typedef does not create any new data types rather
provides an alternative name for standard types. Reference
provides an alias name for a variable and typedef provides an
alias name for a data type.
2006 Delhi:
Eg1:
struct date
{
int dd;
int mm;
int yy;
};
struct student
{
char name[20];
int roll;
date dob;
int marks; };
Prepared By: PGT-IT, JNV West Godavari 35 9 490236965,[email protected]
The member of a nested structure is referenced from the
outermost to innermost with the help of dot operators.
student stud;
Then the members of the nested structure can be accessed as
stud.dob.mm=10;
Eg2:
struct addr
{ int houseno;
char area[26];
char city[26];
char state[26];
};
struct emp
{
int empno;
char name[26];
char design[16];
addr address;
float basic;
};
emp worker;
2006 Outside Delhi:
1.C) Rewrite the following program after removing the
syntactical error(s), if any. Underline each correction. 2
#include<iostream.h>
void main( )
{
struct movie
{
char movie_name[20];
char movie_type;
int ticket_cost=100;
}MOVIE;
gets(movie_name);
gets(movie_type);
}
Ans:#include<iostream.h>
#include<stdio.h>
void main( )
{
struct movie
{
char movie_name[20];
char movie_type;
int ticket_cost;
//Initialization of variables inside a structure is not allowed.
}MOVIE;
gets(MOVIE.movie_name);
cin>>MOVIE.movie_type;
//A single character cannot be read using gets
}
Prepared By: PGT-IT, JNV West Godavari 36 9 490236965,[email protected]
2005 Delhi:
1.d) Find the output of the following program:
#include<iostream.h>
struct MyBox
{
int Length,Breadth,Height;
};
void Dimension(MyBox M)
{
cout<<M.Length<<”x”<<M.Breadth<<”x”;
cout<<M.Height<<endl;
}
void main( )
{
MyBox B1={10,15,5},B2,B3;
++B1.Height;
Dimension(B1);
B3=B1;
++B3.Length;
B3.Breadth++;
Dimension(B3);
B2=B3;
B2.Height+=5;
B2.Length--;
Dimension(B2);
}
2005 Outside Delhi:
1.d) Find the output of the following program:
#include<iostream.h>
struct Package
{ int Length,Breadth,Height; };
void Occupies(Package M)
{
cout<<M.Length<<”x”<<M.Breadth<<”x”;
cout<<M.Height<<endl;
}
void main( )
{
Package P1={100,150,50},P2,P3;
++P1.Height;
Occupies(P1);
P3=P1;
++P3.Lengh;
P3.Breadth++;
Occupies(P3);
P2=P3;
P2.Height+=50;
P2.Length--;
Occupies(P2);
}
2006 Delhi:
Private Members:
AD_NO integer(Ranges 10 – 2000)
NAME Array of characters(String)
CLASS Character
FEES Float
Public Members:
Function Read_Data( ) to read an object of ADMISSION type.
Function Display( ) to display the details of an object.
Function Draw-Nos.( ) to choose 2 students randomly.
And display the details. Use random function to generate
admission nos. to match with AD_NO.
Ans:
class ADMISSION
{
int AD_NO;
char NAME[31];
Prepared By: PGT-IT, JNV West Godavari 45 9 490236965,[email protected]
char CLASS;
float FEES;
public:
void Read_Data( )
{
cout<<"\nEnter the Admission Number: ";
cin>>AD_NO;
cout<<"\nEnter the Student Name: ";
gets(NAME);
cout<<"\nEnter the Class: ";
cin>>CLASS;
cout<<"\nEnter the Fees: ";
cin>>FEES;
}
void Display()
{
cout<<"\nThe Admission Number of the student: "<<AD_NO;
cout<<"\nThe name of the Student: "<<NAME;
cout<<"\nThe Class of the Student: "<<CLASS;
cout<<"\nThe Fees of the Student: "<<FEES;
}
void Draw_Nos();
};
void ADMISSION::Draw_Nos( )
{ //Dear Students, a test for you. Complete this member function.
1.b) Illustrate the use of Inline function in C++ with the help of
an example. 2
Ans:
INLINE FUNCTIONS: The inline functions are a C++
enhancement designed to speed up programs. The coding of
normal functions and inline functions is similar except that
inline functions definitions start with the keyword inline.
Ans:
class HOUSING
{
int REG_NO;
char NAME[31];
char TYPE;
float COST;
public:
void Read_Data( )
{
cout<<"\nEnter the House Registration Number: ";
cin>>REG_NO;
cout<<"\nEnter the House Name: ";
gets(NAME);
cout<<"\nEnter the House Type: ";
cin>>TYPE;
cout<<"\nEnter the House Cost: ";
cin>>COST;
}
void Display()
{
cout<<"\nThe Registration Number of the House: "<<REG_NO;
cout<<"\nThe name of the House: "<<NAME;
cout<<"\nThe Type of the House: "<<TYPE;
cout<<"\nThe Cost of the House: "<<COST;
}
void Draw_Nos();
};
void HOUSING::Draw_Nos( )
{ //Dear Students, a test for you. Complete this member function.
}
Prepared By: PGT-IT, JNV West Godavari 48 9 490236965,[email protected]
2004:
2.b) Declare a class myfolder with the following specifications:
Ans:
class Student
{
int roll_no;
char name[20];
char class_st[8];
int marks[5];
float percentage;
float calculate( )
{
percentage=(marks[0]+marks[1]+marks[2]+marks[3]+marks[4])/5;
return percentage;
}
public:
void Readmarks( )
{
cout<<”\nEnter any 5 subject marks;
cin>>marks[0]>>marks[1]>>marks[2]>>marks[3]>>marks[4];
calculate( );
}
void Displaymarks( )
{
cout<<”\nThe Roll Number of the Student: “<<roll_no;
cout<<”\nThe Name of the Student: “<<name;
Prepared By: PGT-IT, JNV West Godavari 50 9 490236965,[email protected]
cout<<”\nThe class of the Student: “<<class_st;
cout<<”\n5 subject marks of the student…\n”;
cout<<marks[0]<<”\t”<<marks[1]<<”\t”<<marks[2]<<”\t”;
cout<<marks[3]<<”\t”<<marks[4]<<”\n”;
cout<<”Percentage =”<<percentage;
}
};
2001:
2.b) Declare a class to represent bank account of 10 customers
with the following data members. Name of the depositor,
account number, type of account (S for Savings and C for
Current), Balance amount. The class also contains member
functions to do the following:
(i)To initialize data members.
(ii) To deposit money
(iii)To withdraw money after checking the balance (minimum
balance is Rs.1000)
(iv) To display the data members.
[Note:You are also required to give detailed function definitions.]
class Bank
{
char name[15];
int acc_no;
char acc_type;
float bal_amount;
public:
void readData( )
{
cout<<”\nEnter the name: “;
gets(name);
cout<<”\nEnter the account number: “;
cin>>acc_no;
cout<<”\nEnter the account type: “;
cin>>acc_type;
cout<<”\nEnter the amount to deposit: “;
cin>>bal_amount;
}
void deposit( )
{
float deposit;
cout<<”\nEnter your account number: “;
cin>>acc_no;
cout<<”\nEnter the amount to deposit: “;
cin>>deposit;
bal_amount=bal_amount + deposit;
}
void withdraw( )
{
float w_amount;
Prepared By: PGT-IT, JNV West Godavari 51 9 490236965,[email protected]
cout<<”\nEnter your account number: “;
cin>>acc_no;
cout<<”\nEnter amount to withdraw”;
cin>>w_amount;
if((bal_amount-w_amount)<1000)
cout<<”\nWithdraw is not possible”;
else
{
bal_amount=bal_amount-w_amount;
cout<<”\nThe balance is “<<bal_amount-w_amount;
}
}
void display( )
{
cout<<”\nName of the depositor: “<<name;
cout<<”\nAccount Number: “<<acc_no;
cout<<”\nAccount Type: “<<acc_type;
cout<<”\nThe balance amount is “<<bal_amount;
}
};
2000 :
2.b) Define a class worker with the following specification. 4
Private member of class worker:
wname 25characters
hrwrk,wgrate float (hours worked and wagerate per hour)
totwage float(hrwrk*wgrate)
cakcwg() A function to find hrwrk*wgrate with float
return type
Public members of class worker:
In_data( ): A function to accept values for wno, wname,
hrrwrk, wgrate and invoke calcwg( ) to calculate totpay.
Out_data( ): A function to display all the data members on the
screen you should give definitions of functions.
class worker
{
char wname[25];
float hrwrk,wgrate;
float totwage;
float cakcwg( )
{
return hrwrk*wgrate;
}
public:
void In_data( )
{
cout<<”\nEnter Worker number,name,hours worked and wage rate”;
cin>>wno;
gets(wname);
cin>>hrwrk>>wgrate;
calcwg( );
}
Prepared By: PGT-IT, JNV West Godavari 52 9 490236965,[email protected]
void Out_data( )
{
cout<<”\nThe Worker Number: “<<wno;
cout<<”\nThe Name of the worker: “<<wname;
cout<<”\nNumber of hours worked by the worker: “<<hrwrk;
cout<<”\nThe Wage Rate of the Worker: “<<wgrate;
cout<<”\nThe total wages of the worker: “<<totwage;
}
1999 :
class Teacher
{
char Name[20];
char subject[10];
float Basic,DA,HRA,Salary;
float Calculate( )
{
Salary=Basic+DA+HRA;
return Salary;
}
public:
void ReadData( )
{
cout<<"\nEnter Basic, Dearness Allowance and “
cout<<” House Rent Allowance: ";
cin>>Basic>>DA>>HRA;
Calculate();
}
void DisplayData( )
{
cout<<"\nThe Basic : "<<Basic;
cout<<"\nThe Dearness Allowance: "<<DA;
cout<<"\nThe House Rent Allowance: "<<HRA;
cout<<"\nThe Salary: "<<Salary;
}
};
Prepared By: PGT-IT, JNV West Godavari 53 9 490236965,[email protected]
1998 Annual:
DELHI 2008
2.b) Answer the questions (i) and (ii) after going through the
following program: 2
#include <iostream.h>
#include<string.h>
class bazaar
{ char Type[20] ;
char product [20];
int qty ;
float price ;
bazaar() //function 1
{
strcpy (type , “Electronic”) ;
strcpy (product , “calculator”);
qty=10;
price=225;
}
public :
void Disp() //function 2
{
cout<< type <<”-”<<product<<”:” <<qty<< “@” << price << endl ;
}
};
void main ()
{
Bazaar B ; //statement 1
B. disp() ; //statement 2
}
(ii) What shall be the possible output when the program gets
executed ? (Assuming, if required _ the suggested correction(s)
are made in the program).
Ans: Possible Output:
Electronic–Calculator:10@225
private members :
GCode of type string
Prepared By: PGT-IT, JNV West Godavari 55 9 490236965,[email protected]
GType of type string
Gsize of type intiger
Gfabric of type istring
Gprice of type float
A function Assign() which calculate and the value of GPrice
as follows.
For the value of GFabric “COTTON” ,
GType GPrice(RS)
TROUSER 1300
SHIRT 1100
For GFabric other than “COTTON”, the above mentioned
GPrice gets reduced by 10%
public members:
A constructor to assign initial values of GCode,GType and
GFabric with the a word “NOT ALLOTED”and Gsize and Gprice
with 0.
2.b) Answer the questions (i) and (ii) after going through the
following program:
#include<iostream.h>
#include<string.h>
class Retail
{
char category[20];
char item[20];
int qty;
float price;
Prepared By: PGT-IT, JNV West Godavari 57 9 490236965,[email protected]
retail () //function 1
{
strcpy (category, “cerial”);
strcpy (Item, “Rice”);
qty =100 ;
price =25 ;
}
public;
void show() //function 2
{
cout << category <<”-“<< Item << “:”<<Qty<<“@”<< price<<endl;
}
};
void main()
{
Retail R; //statement 1
R. show (); //statement 2
}
(ii) What shall be the possible out put when the program gets
executed ? (Assuming, if required the suggested correction(s) are
made in the program)
Ans: Possible Output:
cerial–Rice:100@25
DELHI: 2007
Ans:
Constructor Destructor
Purpose: Is used to intitialize Purpose: Is used to destroy the
the objects of that class type objects that have been created
with a legal initial value by a constructor
Name: The name of the class Name:The name of the class
preceded by a ~.
Calling: It will be called Calling: It will be called
automatically at the time of automatically at the time of
creation of the object. destruction of an object.
Ie Implicite calling Ie Implicite calling
Return Type: No return type Return Type: No return type
not even void not even void
Private Members:
TCode of type string
No of Adults of type integer
No of Kids of type integer
Kilometers of type integer
TotalFare of type float
Public Members:
• A constructor to assign initial values as follows:
TCode with the word “NULL”
No of Adults as 0
No of Kids as 0
Kilometers as 0
TotalFare as 0
• A function AssignFare() which calculates and assigns the
value of the data member Totalfare as follows
Prepared By: PGT-IT, JNV West Godavari 61 9 490236965,[email protected]
For each Adult
Fare (Rs) For Kilometers
500 >=1000
300 <1000 & >=500
200 <500
For each Kid the above Fare will be 50% of the Fare
mentioned in the above table
For Example:
If Kilometers is 850, Noofadults =2 and NoofKids =3
Then TotalFare should be calculated as
Numof Adults *300+ NoofKids *150
i.e., 2*300+ 3 *150 =1050
• A function EnterTour() to input the values of the data
members TCode, NoofAdults, NoofKids and Kilometers ;
and invoke the AssignFare() function.
• A function ShowTour() which displays the content of all
the data members for a Tour.
Ans:
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<iostream.h>
class Tour
{
char TCode[21];
int NoofAdults,NoofKids,Kilometres;
float TotalFare;
public:
Tour( )
{ strcpy(TCode,"NULL");
NoofAdults=NoofKids=Kilometres=TotalFare=0;
}
void AssignFare( )
{if(Kilometres>=1000)
TotalFare=NoofAdults*500+NoofKids*250;
else if(Kilometres>=500)
TotalFare=NoofAdults*300+NoofKids*150;
else
TotalFare=NoofAdults*200+NoofKids*100;
}
void EnterTour( )
{
cout<<"\nEnter the Tour Code: ";
gets(TCode);
cout<<"\nEnter the Number of Adults: ";
cin>>NoofAdults;
cout<<"\nEnter the Number of Kids: ";
cin>>NoofKids;
cout<<"\nEnter the Number of Kilometres: ";
cin>>Kilometres;
AssignFare( );
}
Prepared By: PGT-IT, JNV West Godavari 62 9 490236965,[email protected]
void ShowTour( )
{
cout<<"\nThe Tour Code: "<<TCode;
cout<<"\nThe Number of Adults: "<<NoofAdults;
cout<<"\nThe Number of Kids: "<<NoofKids;
cout<<"\nThe Number of Kilometres: "<<Kilometres;
cout<<"\n\nThe Total Fare: "<<TotalFare;
}
};
void main( )
{
clrscr();
Tour T;
T.EnterTour( );
T.ShowTour( );
getch();
}
DELHI 2006
2.b) Answer the following questions (i) and (ii) after going
through the following class. 2
class Interview
{
int Month;
public:
interview(int y) {Month=y;} //constructor 1
interview(Interview&t); //constructor 2
};
Prepared By: PGT-IT, JNV West Godavari 65 9 490236965,[email protected]
(i) create an object, such that it invokes Constructor 1.
Ans: Interview A(10); //invoking constructor 1 by passing a
number.
2.b) Answer the following questions (i) and (ii) after going
through the following class. 2
class Exam
{
int Year;
public:
Exam(int y) //Constructor 1
{
Year=y;
}
Exam(Exam &t); //Constructor 2
};
Prepared By: PGT-IT, JNV West Godavari 66 9 490236965,[email protected]
(i) Create an object, such that it invokes Constructor 1
Ans: Exam E((2008);
(ii) Write complete definition for constructor 2.
Ans: Exam(Exam &t) //Copy Constructor.
{
Year=t.Year;
}
DELHI 2005
2.b) Answer the following questions (i) and (ii) after going
through the following class.
class Test
{
char Paper[20];
int Marks
public:
Test() //Function 1
{
strcpy(Paper,”Computer”);
Marks=0;
} //Function 2
Test(char P[])
{
strcpy(Paper,P);
Marks=0;
} //Function 3
Test(int M)
{
strcpy(Paper,”Computer”);
Marks=M;
}
Test(char P[],int M) //Function 4
{
strcpy(Paper,P);
Marks=M;
}
};
(i) Which feature Object Oriented Programming is demonstrated
using Function 1, Function 2, Function 3 and Function 4 in the
above class text?
Ans: Function overloading (here it is constructor overloading).
(ii)Write statements in C++ that would execute Function 2 and
Function 4 of class Text.
Ans: (let char name[20];
int X=60;
strcpy(name,”COMPUTERSCIENCE”);
are declared in the program)
(i) Test A(name); //Will execute Funciton 2
(ii) Test B(name,X); //Will execute Function 4
DELHI 2004
2.a)Given the following C++ code, answer the questions (i)and(ii)
class TestMeOut
{
public:
~TestMeOut( ) //Function 1
{
cout<<”Leaving the examination hall”<<endl;
}
TestMeOut( ) //Function 2
{
cout<<”Appearing for examination”<<endl;
}
void MyWork( )
{
cout<<”Attempting Questions”<<endl;
}
};
Prepared By: PGT-IT, JNV West Godavari 71 9 490236965,[email protected]
(i) In Object Oriented programming, what is Function
1 referred as and when does it get invoked/called?
Ans: Function 1 is called as Destructor, It will automatically
executed at the time of destruction of the object of class
TestMeOut.
(ii) In Object Oriented Programming, what is Function
2 referred as and when does it get invoked/called?
Ans: Function 2 is called as constructor (Non-parameterized
or default constructor) , it will automatically executed at the
time of creation of the object of class TestMeOut.
DELHI 2003
2.b) Define a class Play in C++ with the following specifications:
Private members of class Play
• Play code integer
• Playtime 25 character
• Duration float
• Noofscenes integer
Public member function of class bPlay
• A constructer function to initialize Duration as 45
and Noofscenes as
• Newplay() function to values for Playcode and
Playtitle.
• Moreinfor() to assign the values of assign the values
of Duration and Noofscenes with the of
corresponding values passed as parameters to this
function.
• Shoplay() function to display all the dataq members
on the screen.
Ans: #include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class Play
{ int Playcode;
char Playtitle[25];
float Duration;
int Noofscenes;
public:
Play( )
{ Duration=45;
Noofscenes=5;
}
void Newplay( )
{
cout<<"\nEnter the Play Code: ";
cin>>Playcode;
cout<<"\nEnter the Play Title: ";
gets(Playtitle);
}
Prepared By: PGT-IT, JNV West Godavari 72 9 490236965,[email protected]
void Moreinfor(float D,int N)
{ Duration = D;
Noofscenes = N;
}
void Showplay( )
{ cout<<"\nThe Play Code : "<<Playcode;
cout<<"\nThe Play Title : "<<Playtitle;
cout<<"\nThe Duration : "<<Duration;
cout<<"\nThe No of Scenes:"<<Noofscenes;
}
};
void main( )
{ clrscr( );
Play P;
P.Newplay( );
float Dur;
int NS;
cout<<"\nEnter the Duration and Number of Scenes: ";
cin>>Dur>>NS;
P.Moreinfor(Dur,NS);
P.Showplay( );
getch( );
}
DELHI 2002
2.c) Write the oputput of the following program. 4
Ans: #include<iostream.h>
class Counter
{
private:
unsigned int count;
public:
Counter()
{ count=0; }
void inc_Count()
{ count++; }
int get_Count()
{ return count; }
};
void main()
{
Counter C1,C2;
cout<<"\nC1="<<C1.get_Count();
cout<<"\nC2="<<C2.get_Count();
C1.inc_Count();
C2.inc_Count();
C2.inc_Count();
cout<<"\nC1="<<C1.get_Count();
cout<<"\nC2="<<C2.get_Count();
}
Prepared By: PGT-IT, JNV West Godavari 73 9 490236965,[email protected]
DELHI 2000
2.a) Why is destructor function required in classes? Illustrate
with the function with an example.
Ans: A destructor is a function which de-allocates/frees the
memory which was reserved by the constructor.
Eg:
class Sample
{
Int i,j;
Public:
Sample(int a, int b) //Constructor
{ i=a; j=b; }
~Sample()
{ cout<<”Destructor at work\n”; }
------
};
void main( )
{
Sample s1(3,4); //Local object s1 constructed with values 3
// and 4 using Sample ( )
-----
------
----//Automatically s1 is destructed at the end of the block
//using destructor ~Sample( )
}
DELHI 1998
void DISPLAY(void);
public:
void ENTER();
};
(i)Name the base class and derived class of the class Dept.
Ans: Base class of Dept - School
Derived class of Dept - Teacher
(ii)Name the data member(s) that can be accessed from function
OUT().
Ans: Dept::X Dept::Y
School::B
School::C
(iii)Name the private member function(s) of class Teacher.
Ans: Teacher::Display( )
(iv)Is the member function OUT() accessible the objects of Dept?
Ans: Yes. Since it is public member function.
DELHI 1999
2.a)What do you understand by visibility modes in class
derivations? What are these modes? 2
Ans: It is given in chapter 4, classes and object as two answers.
Ie Difference between private and protected, private and public.
2.c)Consider the following declarations and answer the
questions below:
class vehicle
{ int wheels;
protected:
int passenger;
void inputdata(int,int);
void outputdata();
};
class heavy_vehicle:protected vehicle
{
int diesel_petrol;
protected:
int load:
public:
void readdata(int,int);
void writedata();
};
class bus:private heavy_vehicle
{
char make[20];
public:
void fetchdata(char);
void displaydata();
};
Prepared By: PGT-IT, JNV West Godavari 89 9 490236965,[email protected]
(i)Name the base class and derived class of the class
heavy_vehicle.
Ans: Base class of heavy_vehicle – vehicle
Derived class of heavy_vehincle – bus
(ii)Name the data member(s) that can be accessed from function
displaydata.
Ans: bus::make
heavy_vehicle::load
vehicle::passenger
(iii)Name the data member(s) that can be accessed by an object
of bus class.
Ans: No data member can be accessed by an object of bus class.
(iv)Is the member function outputdata accessible to the objects
of heavy_vehicle class?
Ans: No.
DELHI 1998
2.c) Consider the following declarations and answer the
questions below:
class PPP
{ int H;
protected:
int S;
public:
void INPUT(int);
void OUT();
};
class QQQ:private PPP
{ int T;
protected:
int U;
public:
void INDATA(int,int);
void OUTPUT();
};
class RRR:public QQQ
{ int M;
public:
void DISP(void);
};
(i)Name the base class and derived class of the class QQQ.
Ans:Base class of QQQ – PPP
Derived class of QQQ – RRR
(ii)Name the data member(s) that can be accessed from function
DISP().
Ans: QQQ::U , RRR::M
(iii)Name the member function(s) , which can be accessed from
the object of class RRR.
Ans: QQQ::INDATA( ) QQQ::OUTPUT( ) RRR::DISP( )
(iv) Is the member function OUT() accessible by the objects of
the class QQQ?
Ans: No.
Prepared By: PGT-IT, JNV West Godavari 90 9 490236965,[email protected]
8.POINTERS
2007 Delhi:
1.d) Find the output of the following program: 2
#include<iostream.h>
void main( )
{ int Array[]={4,6,10,12};
int *pointer=Array;
for(int I=1;I<=3;I++)
{ cout<<*pointer<<”#”;
pointer++;
}
cout<<endl;
for(I=1;I<=4;I++)
{ (*pointer)*=3;
--pointer;
}
for(I=1;I<5;I++)
cout<<Array[I-1]<<”@”;
cout<<endl;
}
2007 Outside Delhi:
1.d) Find the output of the following program: 2
#include<iostream.h>
void main( )
{ int Numbers[]={2,4,8,10};
int *ptr=Numbers;
for(int C=1;C<3;C++)
{ cout<<*ptr<<”@”;
ptr++;
}
cout<<endl;
for(C=0;C<4;C++)
{ (*ptr)*=2;
--ptr;
}
for(C=0;C<4;C++)
cout<<Numbers[C]<<”#”;
cout<<endl; }
2006 Delhi:
1.d) Find the output of the following program: 3
#include<iostream.h>
#include<string.h>
class state
{ char *state_name;
int size;
public:
state( )
{
size=0;
state_name=new char[size+1]; }
Prepared By: PGT-IT, JNV West Godavari 91 9 490236965,[email protected]
state(char *s)
{ size=strlen(s);
state_name=new char[size+1];
strcpy(state_name,s);
}
void display( )
{ cout<<state_name<<endl; }
void Replace(state &a, state &b)
{ size=a.size+b.size;
delete state_name;
state_name=new char[size+1];
strcpy(state_name,a.state_name);
strcat(state_name,b.state_name);
}
};
void main( )
{ char *temp=”Delhi”;
state state1(temp),state2(“Mumbai”),state3(“Nagpur”),S1,S2;
S1.Replace(state1,state2);
S2.Replace(S1,state3);
S1.display( );
S2.display( );
}
2006 Outside Delhi:
1.d) Find the output of the following program: 3
#include<iostream.h>
#include<string.h>
class student
{ char *name;
int I;
public:
student( )
{ I=0;
name=new char[I+1];
}
student(char *s)
{ I=strlen(s);
name=new char[I+1];
strcpy(name,s); }
void display( )
{ cout<<name<<endl; }
void manipulate(student &a, student &b)
{
I=a.I+b.I;
delete name;
name=new char[I+1];
strcpy(name,a.name);
strcat(name,b.name);
}
};
Prepared By: PGT-IT, JNV West Godavari 92 9 490236965,[email protected]
void main( )
{ char *temp=”Jack”;
student name1(temp),name2(“Jill”),name3(“John”),S1,S2;
S1.manipulate(name1,name2);
S2.manipulate(S1,name3);
S1.display( );
S2.display( );
}
2006 Outside Delhi:
2.a) What is “this” pointer? Give an example to illustrate the
use of it in C++.
Ans: A special pointer known as this pointer stores the address
of the object that is currently invoking a member function. The
this pointer is implicitly passed to the member functions of a
class whenever they are invoked.
(As soon as you define a class, the member functions are
created and placed in the memory space only once. That is,
only one copy of member functions is maintained that is shared
by all the objects of the class. Only space for data members is
allocated separately for each object.
When a member function is called, it is automatically passed
an implicit(in built) argument that is a pointer to the object that
invoked the function. This pointer is called this. If an object is
invoking a member function, then an implicit argument is
passed to that member function that points to (that) object. The
programmer also can explicitly specify ‘this’ in the program if
he desires.)
Eg: Example program to demonstrate the usage of this pointer.
#include<iostream.h>
#include<conio.h>
class Rectangle
{ float area,len,bre;
public:
void input( )
{ cout<<"\nEnter the length and breadth: ";
cin>>this->len>>this->bre;
}
void calculate( )
{
area=len*bre;//Here Implicit 'this' pointer will be worked.
}
void output( )
{
cout<<"\nThe Area of the Rectangle: "<<this->area;
}
};
void main( )
{
Rectangle R;
clrscr( );
Prepared By: PGT-IT, JNV West Godavari 93 9 490236965,[email protected]
R.input( );
R.calculate( );
R.output( );
getch();
}
2004:
1.d) What will be the output of the following program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void ChangeString(char Text[],int &Counter)
{ char *Ptr=Text;
int Length=strlen(Text);
for(;Counter<Length-2;Counter+=2,Ptr++)
{
*(Ptr+Counter)=toupper(*(Ptr+Counter));
}
}
void main( )
{ clrscr( );
int Position=0;
char Message[]=”Pointers Fun”;
ChangeString(Message,Position);
cout<<Message<<”@”<<Position;
}
2001:
1.c) Identify the syntax error(s), if any, in the following program.
Also give reason for errors. 2
void main( )
{
const int i=20;
const int* const ptr=&i;
(*ptr)++;
int j=15;
ptr=&j;
}
Ans:
Error Line 5 : Cannot modify a const object.
Error Line 7 : Cannot modify a const object.
Warning Line 8 : ‘j’ is assigned a value that is never used.
Warning Line 8 : ‘ptr’ is assigned a value that is never used.
Explonation:
(1) Error 1 is in Line no.5 ie (*ptr)++
Here ptr is a constant pointer ie the contents cann’t be
modified.
(2) Error 2 is in Line no.7 ie ptr=&j;
Here ptr is a constant pointer the address in this pointer
can’t be modified. (It is already pointing the address of i.)
1.d) Give the output of the following program segment.
(Assuming all required header files are included in the program) 2
Prepared By: PGT-IT, JNV West Godavari 94 9 490236965,[email protected]
void main( )
{ int a=32,*x=&a;
char ch=65,&cho=ch;
cho+=a;
*x+=ch;
cout<<a<<’,’<<ch<<endl; }
2.a) Distinguish between
int *ptr=new int(5); int *ptr=new int[5]; 2
Ans: The int *ptr=new int(5); declares and creates the space for
the new data directly.
Ie The new operator reserves 2 bytes of memory from heap
memory (free pool) and returns the address of that memory
location to a pointer variable called ptr, 5 is the initial value to
be stored in the newly allocated memory.
The int *ptr = new int[5]; initializes an array element. A memory
space for an integer type of array having 5 elements will be
created from the heap memory (free pool).
2.c) Give the output of the following program: 4
#include<iostream.h>
#include<string.h>
class per
{ char name[20];
float salary;
public:
per(char *s, float a)
{ strcpy(name,s);
salary=a;
}
per *GR(per &x)
{ if(x.salary>=salary)
return &x;
else
return this;
}
void display( )
{ cout<<”Name:“<<name<<”\n”;
cout<<”Salary:“<<salary<<”\n”;
}
};
void main( )
{ Per P1(“REEMA”,10000),
P2(“KRISHNAN”,20000),
P3(“GEORGE”,5000);
per *P;
P=P1.GR(P3);P->display( );
P=P2.GR(P3);P->display( ); } 1999:
1.d) Give the output of the following program.
#include<stdio.h>
void main( )
{
char *p=”Difficult”;
char c; c=*p++; printf(“%c”,c); }
Prepared By: PGT-IT, JNV West Godavari 95 9 490236965,[email protected]
11.DATA BASE CONCEPTS
Delhi 2008
5.a) Differentiate between Candidate key and Primary key in
context of RDBMS.
Ans:
Candidate Key: All attribute combinations inside a relation
that can serve primary key are Candidate Keys as they are
candidates for the primary key position.
Primary Key: A primary key is a set of one or more attributes
that can uniquely identify tuples within the relations.
Delhi (2007)
5.a) Differentiate between primary key and alternate key.
Ans:
Primary Key: A primary key is a set of one or more attributes
that can uniquely identify tuples within the relations.
Alternate Key: A candidate key that is not the primary key is
called an Alternate Key.
(Where Candidate Key: All attribute combinations inside a
relation that can serve primary key(uniquely identifies a row in
a relation) are Candidate Keys as they are candidates for the
primary key position.)
Delhi (2006)
5.a) What is an alternate key?
Ans:
Alternate Key: A candidate key that is not the primary key is
called an Alternate Key.
(Where Candidate Key: All attribute combinations inside a
relation that can serve primary key(uniquely identifies a row in
a relation) are Candidate Keys as they are candidates for the
primary key position.)
Delhi (2005)
5.a)What do you understand by the terms primary key and
degree of a relation in relational data base?
Ans:
Primary Key: A primary key is a set of one or more attributes
that can uniquely identify tuples within the relations.
The number of attributes in a relation is called Degree of a
relation in relational data base.
2003:
5.a)What is primary key in a table?
(Define first normal form.- This is out of syllabus)
Ans:
Primary Key: A primary key is a set of one or more attributes
that can uniquely identify tuples within the relations.
2002:
5.a) Differentiate between data definition language and data
manipulation language.
Ans: The SQL DDL(Data Definition Language) provides
commands for defining relation schemas, deleting relations,
creating indexes and modifying relation schemas.
The SQL DML (Data Manipulation Language) includes a query
language to insert, delete and modify tuples in the database.
DML is used to put values and manipulate them in tables and
other database objects and DDL is used to create tables and
other database objects.
2001:
5.c) Explain Cartesian product of two relations.
Ans: The Cartesian product is a binary operation and is
denoted by a cross(x). The Cartesian product of two relations A
and B is written as AXB. The Cartesian product yields a new
relation which has a degree (number of attributes) equal to the
sum of the degrees of the two relations operated upon. The
number of typles (cardinality) of the new relation is the product
of the number of tuples of the two relations operated upon. The
Cartesian product of two relations yields a relation with all
possible combinations of the tuples of the two relations operated
upon.
All tuples of first relation are concatenated with all the
tuples of second realtion to form the tuples of the new relation.
Relation 1: Student
InstructorName Subject
K.Suman Computer Science
P.Pavan Electronics
1998:
CnorName CneeName
R singhal Rahul Kishore
Amit Kumar S mittal
(vii)SELECT CneeName,CneeAddress
FROM Consignee
WHERE CneeCity Not IN (‘Mumbai’, ‘Kolkata’);
Ans:
CneeName CneeAddress
P Dhingra
16/j,Moore
Enclave
B P jain 13,Block
d,a,viha
(viii) SELECT CneeID, CneeName FROM Consignee
WHERE CnorID = ‘MU15’ OR CnorID = ‘ND01’;
Ans: CneeID CneeName
MU05 Rahul Kishore
KO19 A P Roy
Delhi (2007)
5.b)Consider the following tables. Write SQL command for the
statements (i)to(iv)and give outputs for the SQL quries (v) to
( viii). 6
TABLE : SENDER
SenderID SenderName SenderAddress senderCity
ND01 R jain 2,ABC Appts New Delhi
Prepared By: PGT-IT, JNV West Godavari 103 9 490236965,[email protected]
MU02 H sinha 12, Newton Mumbai
MU15 S haj 27/ A,Park Street New Delhi
ND50 T Prasad 122-K,SDA Mumbai
TABLE :RECIPIENT
RecID SenderID ReCName RecAddress ReCCity
KO05 ND01 R Bajpayee 5,Central Kolkata
Avenue
ND08 MU02 S Mahajan 116, A Vihar New Delhi
MU19 ND01 H sing 2A,Andheri East Mumbai
MU32 MU15 P K swamy B5, CS Mumbai
Terminus
ND48 ND50 S Tripathi 13, B1 D,Mayur New Delhi
Vihar
(i)To display the names of all senders from Mumbai.
Ans: Select * from Sender where SenderCity =’Mumbai’;
(ii)To display the recID, senderName, senderAddress, RecName,
RecAddress for every recipt.
Ans: Select recID, SenderName, SenderAddress, RecName,
RecAddress from Sender, Recipient where
Sender.Senderid=Recipient.RenderId;
(iii)To display the sender details in ascending order of
SenderName.
Ans: Select * from Sender order by SenderName;
(iv)To display number of Recipients from each city.
Ans: Select RecCity,Count(*) from Recipient group by RecCity;
(v) SELECT DISTINCT SenderCity FROM Sender;
Ans:
senderCity
New Delhi
Mumbai
(vi) SELECT A.SenderName A, B.RecName
FROM Sender A, Recipient B WHERE
A.SenderID=B. SenderID AND B.RecCity=’Mumbai’;
Ans: SenderName RecName
R.Jain H.Singh
S.Jha P.K.Swamy
(vii)SELECT RecName,RecAddress FROM Recipient
WHERE RecCity Not IN (‘Mumbai’, Kolkata’);
Ans: RecName RecAddress
S Mahajan 116, A Vihar
S Tripati 13, B1 D, Mayur Vihar
(viii) SELECT RecID, RecName
FROM Recipient
WHERE SenderID = ‘MU02’ OR SenderID = ‘ND50’;
Ans: RecID RecName
ND08 S Mahajan
ND48 S Tripathi
(iii) Display the FL_NO and fare to be paid for the flights from
DELHI to MUMBAI using the tables FLIGHTS and FARES, where
the fare to be paid = FARE+FARE+TAX%/100.
Ans: Select FL_NO, FARE+FARE+(TAX%/100) from FLIGHTS,
FARES where Starting=”DELHI” AND Ending=”MUMBAI”
(iv) Display the minimum fare “Indian Airlines” is offering from
the tables FARES.
Ans: Select min(FARE) from FARES Where AIRLINES=”Indian
Airlines”
v)Select FL_NO,NO_FLIGHTS,AIRLINES from FLIGHTS, FARES
Where STARTING = “DELHI” AND FLIGHTS.FL_NO = FARES.FL_NO
Ans: FL_NO NO_FLIGHTS AIRLINES
IC799 2 Indian Airlines
(vi) SELECT count (distinct ENDING) from FLIGHTS.
Ans: (Children, Try this answer as an assignment)
Prepared By: PGT-IT, JNV West Godavari 105 9 490236965,[email protected]
DELHI 2006:
5.b) Study the following tables DOCTOR and SALARY and write
SQL commands for the questions (i) to (iv) and give outputs for
SQL queries (v) to (vi) :
TABLE: DOCTOR
ID NAME DEPT SEX EXPERIENCE
101 Johan ENT M 12
104 Smith ORTHOPEDIC M 5
107 George CARDIOLOGY M 10
114 Lara SKIN F 3
109 K George MEDICINE F 9
105 Johnson ORTHOPEDIC M 10
117 Lucy ENT F 3
111 Bill MEDICINE F 12
130 Murphy ORTHOPEDIC M 15
TABLE: SALARY
ID BASIC ALLOWANCE CONSULTAION
101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 100
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300
(i) Display NAME of all doctors who are in “MEDICINE” having
more than 10 years experience from the Table DOCTOR.
Ans: Select Name from Doctor where Dept=”Medicine” and
Experience>10
(ii) Display the average salary of all doctors working in
“ENT”department using the tables DOCTORS and SALARY
Salary =BASIC+ALLOWANCE.
Ans: Select avg(basic+allowance) from Doctor,Salary where
Dept=”Ent” and Doctor.Id=Salary.Id
(iii) Display the minimum ALLOWANCE of female doctors.
Ans: Select min(Allowance) from Doctro,Salary where Sex=”F”
and Doctor.Id=Salary.Id
(iv) Display the highest consultation fee among all male doctors.
Ans: Select max(Consulation) from Doctor,Salary where
Sex=”M” and Doctor.Id=Salary.Id
(v) SELECT count (*) from DOCTOR where SEX = “F”
Ans: 4
(vi) SELECT NAME, DEPT , BASIC from DOCTOR, SALRY
Where DEPT = “ENT” AND DOCTOR.ID = SALARY.ID
Ans: Name Dept Basic
Jonah Ent 12000
DELHI 2005:
(5) Consider the following tables EMPLOYEES and EMPSALARY.
write SQL commands for the
Statements (i) to (iv) and give outputs for SQL quires (v) to (viii).
N NAME AG
DEPARTMEN DATEOF CHAR SEX
O ET ADM GES
1 Arpit 62
Surgery 21/1/98 300 M
2 Zareena 22
Ent 12/12/97 250 F
3 Kareem 32
Arthopedic 19/2/98 200 M
4 Arun 12
Surgery 11/1/98 300 M
5 Zubin 30
Ent 12/1/98 250 M
6 Karin 16
Ent 24/2/98 250 F
7 Ankita 29
cardiology 22/2/98 800 F
8 Zareen 45
Gynecology 22/2/98 300 F
9 Kush 19
Cardiology 13/1/98 800 M
10 Shilpa 23
Nuclear 21/2/98 400 F
medicine
(b) To select all the information of patients of all cardiology
department.
Ans: Select all from Hospital where department=”Cardiology”
(c) To list the names of female patients who are in ent
department.
Ans:select name from Hospital where Department=”Ent” and
Sex=”F”
(d) To list names of all patients with their date of admission in
ascending order.
Ans: Select name,dateofadm from Hospital dateofadm.
(e) To display patients name, charges, age, for only female
patients.
Ans: Select Name,Charges,age from Hospital where sex=”F”
(f) To count the number of patients with age <30.
Ans: Select count(*) from hospitals where age<30
(g) To insert the new row in the hospital table with the following
data: 11, “aftab”, 24, “surgery”, {25/2/98}, 300, “M”.
Ans: insert into Hospital values(11, “aftab”, 24, “surgery”,
{25/02/98}, 300, “M”)
(h) Give the output of the following SQL statements:
(i) Select count (distinct charges)from hospital;
Ans: 5
(ii) Select min(age) from hospital where sex = “f’;
Ans: 16
(iii) Select sum(charges) from hospital where department =
“ent”;
Ans: 750
(iv) Select avg(charges) from hospital where date of admission
is <{12/02/98};
Ans:380
Eg:
struct Sname
{
char fname[25];
char lname[25];
} S1;
class Test
{
int a,b;
const int max; //const member
Sname &name; //reference member
Public:
Test ( ):max(300),name(S1)
{
a=0;
b=10;
}
------
};
Constructor Overloading:
The constructor of a class may also be overloaded so that even
with different number and types of initial values, an object may
still be initialized.
DESTRUCTORS
Destructor: A destructor is used to destroy the objects that
have been created by a constructor. A destructor destroys the
values of the object being destroyed.
A destructor is also a member function whose name is
the same as the class name but is preceded by tilde(~). A
destructor takes no arguments, and no return types can be
specified for it (not even void). It is automatically called by the
compiler when an object is destroyed. A local object, local to a
block, is destroyed when the block gets over; a global or static
object is destroyed when the program terminates. A destructor
cleans up the storage (memory area of the object) that is no
longer accessible.
Eg:
class Sample
{
Int i,j;
Public:
Sample(int a, int b) //Constructor
Prepared By: PGT-IT, JNV West Godavari 123 9 490236965,[email protected]
{ i=a; j=b; }
~Sample()
{ cout<<”Destructor at work\n”; }
------
------
};
void main( )
{
Sample s1(3,4); //Local object s1 constructed with values 3
// & 4 using Sample ( )
-----
----/*Automatically s1 is destructed at the end of the block
using destructor ~Sample( )*/
}
Need for Destructors: During construction of any object by the
constructor, resources may be allocated for use. (for example, a
constructor may7 have opened a file and a memory area may be
allotted to it). These allocated resources must be de allocated
before the object is destroyed.A destructor performs these types
of tasks.
Some Characteristics of Destructors:
1. Destructor functions are invoked automatically when the
objects are destroyed.
2. If a class has a destructor, each object of that class will be
deinitialized before the object goes out of scope.(Local objects at
the end of the block defining them and global and static objects
at the end of the program).
3. Destructor functions also, obey the usual access rules as
other member functions do.
4.No argument can be provided to a destructor, neither does it
return any value.
5. They cannot be inherited.
6. A destructor may not be static.
7. It is not possible to take the address of a destructor.
8. Member functions may be called from within a destructor.
9. An object of a class with a destructor cannot be a member of
a union.
C
A
Block
lock
B
#include <iostream.h>
float NUM=900; //NUM is a
global variable
void LOCAL(int T)
{
int Total=0; //Total is a
local variable
for (int I=0;I<T;I++)
Total+=I;
cout<<NUM+Total;
}
void main()
{
LOCAL(45);
}
20
Step 2: Push
30
20
Step 3: +
Push
Pop Pop
Op2=30 Op1=20
Op2=30
20 50
Step 4: Push
50
50
Step 5: Push
40
50
50
Step 6: -
Push
Pop Pop
Op2=40 Op1=50
50 Op2=40 10
50 50 50
Step 7: *
Push
Pop Pop
Op2=10 Op1=50
Op2=10
50 500
Step 8: Pop
Result
500
( ½ Mark for showing stack position for each operation +,- and *)
( ½ Mark for correctly evaluating the final result)
Prepared By: PGT-IT, JNV West Godavari 141 9 490236965,[email protected]
Q4.(a) Observe the program segment given below carefully and fill the blanks
marked as Statement 1 and Statement 2 using seekp() and seekg()
functions for performing the required task. 1
#include <fstream.h>
class Item
{ int Ino;char Item[20];
public:
//Function to search and display the content
from a particular //record number
void Search(int );
//Function to modify the content of a
particular record number
void Modify(int);
};
void Item::Search(int RecNo)
{ fstream File;
File.open(“STOCK.DAT”,ios::binary|ios::in);
______________________
//Statement 1
File.read((char*)this,sizeof(Item));
cout<<Ino<<”==>”<<Item<<endl;
File.close();
}
void Item::Modify(int RecNo)
{ fstream File;
File.open(“STOCK.DAT”,ios::binary|ios::in|ios::out);
cout>>Ino;cin.getline(Item,20);
______________________
//Statement 2
File.write((char*)this,sizeof(Item));
File.close();
}
Answer:
File.seekg(RecNo*sizeof(Item)); //Statement
1
File.seekp(RecNo*sizeof(Item)); //Statement
2
( ½ Mark for each correct statement)
(b) Write a function in C++ to count the number of lines present in a text
file “STORY.TXT”. 2
Answer:
void CountLine()
{
ifstream FIL(“STORY.TXT”);
int LINES=0;
char STR[80];
while (FIL.getline(STR,80))
LINES++;
cout<<”No. of Lines:”<<LINES<<endl;
FIL.close(); }
( ½ mark for opening the file in ‘in’ mode)
( ½ mark for initializing the variable for counting lines to 0)
Prepared By: PGT-IT, JNV West Godavari 142 9 490236965,[email protected]
( ½ mark for reading each line)
( ½ mark for incrementing and displaying/returning value of variable)
(c) Write a function in C++ to search for a BookNo from a binary file
“BOOK.DAT”, assuming the binary file is containing the objects of the
following class. 3
class BOOK
{
int Bno;
char Title[20];
public:
int RBno(){return Bno;}
void Enter(){cin>>Bno;gets(Title);}
void Display(){cout<<Bno<<Title<<endl;}
};
Answer:
void BookSearch()
{
fstream FIL;
FIL.open(“BOOK.DAT”,ios::binary|ios::in);
BOOK B;
int bn,Found=0;
cout<<”Enter Book Num to search…”;
cin>>bn;
while (FIL.read((char*)&S,sizeof(S)))
if (B.RBno()==bn)
{
B.Display();
Found++;
}
if (Found==0) cout<<”Sorry! Book not
found!!!”<<endl;
FIL.close();
}
( ½ mark for correct syntax of function header and body)
( ½ mark for opening the file in ‘in’ mode)
( ½ mark for reading content from file into the object of B)
( ½ mark for appropriate loop)
( ½ mark for correct condition for searching)
( ½ mark for displaying the content of the object)
Q5.
(a) What do you understand by Degree and Cardinality of a table? 2
Answer:
Degree of a table is total number of attributes.
Cardinality of a table is total number of rows.
(1 mark for definition of Degree)
(1 mark for definition of Cardinality)
(b) Consider the following tables ACTIVITY and COACH. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL
queries (v) to (viii) 6
Answer:
F(P,Q)=(P’+Q).(P+Q’)
(Full 2 marks for obtaining the correct Boolean Expression for the Logic
Circuit) OR (1 mark correctly interpreting SUM terms)
(d) Write the POS form of a Boolean function F, which is represented in a
truth table as follows: 1
U V W F
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
Answer:
F(U,V,W) = (U+V+W’).(U+V’+W’).(U’+V+W’)
(1 mark for correct POS representation)
(e) Reduce the following Boolean Expression using K-Map: 3
Prepared By: PGT-IT, JNV West Godavari 145 9 490236965,[email protected]
F(A,B,C,D)=Σ(0,1,2,4,5,6,8,10)
Answer:
F(A,B,C,D)=A’C’+A’D’+B’D’
(1 mark for correctly drawing K-Map with 1s represented on right
places)
(1 mark for minimizing each Quad)
(1 mark for writing the complete Boolean Expression)
Q7.
e) What is the significance of ARPANET in the network? 1
Answer:
The first evolution of network was jointly designed by The Advanced
Research Projects Agency (ARPA) and Department of Defence (DoD) in
1969 and was called ARPANET. It was an experimental project, which
connected a few computers of some of the reputed universities of USA and
DoD. ARPANET allowed access and use of computer resource sharing
projects. Later Defence Data Network (DDN) was born in 1983.
(1 marks for mentioning the significance correctly)
f) Expand the following terminologies: 1
(i) CDMA (ii) GSM
Answer:
(i) Code Division Multiple Access
(ii) Global System for Mobile Communication
(½ mark each expansion)
g) Give two major reasons to have network security. 1
Answer:
Two major reasons to have Network Security are
(i) Secrecy: Keeping information out of the reach of
unauthorized users.
(ii) Authentication: Determining the authorized user before
sharing sensitive information with or entering into a business
deal.
(½ mark for each appropriate reasons)
h) What is the purpose of using a Web Browser? Name any one commonly used
Web Browser. 1
Answer:
The Web Browser fetches the page requested, interprets the text
and formatting commands that it contains, and displays the page
properly formatted on the screen.
Example of a Web Browser:
Mozilla Firefox OR Internet Explorer OR Netscape Navigator OR
Safari OR OPERA
(½ mark for mentioning purpose of using a Web Browser)
Prepared By: PGT-IT, JNV West Godavari 146 9 490236965,[email protected]
(½ mark for Example of a Web Browser)
e) Knowledge Supplement Organisation has set up its new center at
Mangalore for its office and web based activities. It has 4 blocks of buildings as
shown in the diagram below:
Block
Block
A
C
Block
lock
D
B
Block
A
C
lock
Block
B
C
lock
Block
B
e2) Suggest the most suitable place (i.e. block) to house the server of this
organisation with a suitable reason. 1
Answer:
The most suitable place / block to house the server of this organisation
would be Block C, as this block contains the maximum number of
computers, thus decreasing the cabling cost for most of the computers
as well as increasing the efficiency of the maximum computers in the
network.
( ½ mark for mentioning the correct block)
( ½ mark for reason)
e3) Suggest the placement of the following devices with justification 1
(i) Repeater (ii)Hub/Switch
Answer:
(i) For Layout 1, since the cabling distance between Blocks A and
C, and that between B and C are quite large, so a repeater each,
would ideally be needed along their path to avoid loss of
signals during the course of data flow in these routes.
Bloc
Bloc
kA
kC
Repeate
Repeate
Bloc
Bl
oc
kD
B
k
Repeater
A
C
lock
Block
B
Fazz
Raj
Building
Jazz
Building
Harsh
void Display()
{
cout<<”Hello!”<<endl;
}
Prepared By: PGT-IT, JNV West Godavari 158 9 490236965,[email protected]
void Display(int N)
{
cout<<2*N+5<<endl;
}
(1 Mark for definition)(1 Mark for example) OR
(Full 2 marks for explaining both with the help of an example)
(c) Answer the questions (i) and (ii) after going through the following
program: 2
class Match
{
int Time;
public:
Match()
//Function 1
{
Time=0;
cout<<”Match commences”<<end1;
}
void Details()
//Function 2
{
cout<<”Inter Section Basketball
Match”<<end1;
}
(n) An array P[20][30] is stored in the memory along the column with each
of the element occupying 4 bytes, find out the memory location for the
element P[5][15], if an element P[2][20] is stored at the memory
location 5000. 4
Answer:
Given,
W=4
N=20
M=30
Loc(P[2][20])=5000
Column Major Formula:
Loc(P[I][J]) =Base(P)+W*(N*J+I)
Loc(P[2][20]) =Base(P)+4*(20*20+2)
5000 =Base(P)+4*(400+2)
Base(P) =5000- 1608
Base(P) =3392
Loc(P[5][15]) =3392+4*(20*15+5)
=3392+4*(300+5)
=3392+1220
=4612
(1/2 Mark for correct formula/substitution of values in formula)
(1 ½ Mark for correctly calculating Base Address)
(2 Mark for correctly calculating address of desired location)
(o) Write a function in C++ to perform Push operation on a dynamically
allocated Stack containing real numbers. 4
Answer:
struct NODE
{
float Data; NODE *Link;
};
True
Step 2: Push
False
True
True
False
Step 5: Push
True
True
False
Step 6: NOT Push
Pop
Op2=True False
True True
False False
Step 7: OR
Push
Pop Pop
Op2=Fals Op1=True
e
True Op2=Fals True
e
False False False
Step 8: AND
Push
Pop Pop
Op2=True Op1=Fals
e
Op2=True
False False
Step 9: Pop
Result
False
( 1½ Mark for showing stack position for operations NOT,OR and AND)
( ½ Mark for correctly evaluating the final result)
4.(a) Observe the program segment given below carefully and fill the
blanks marked as Statement 1 and Statement 2 using seekg() and
tellg() functions for performing the required task. 1
#include <fstream.h>
Prepared By: PGT-IT, JNV West Godavari 164 9 490236965,[email protected]
class Employee
{ int Eno;char Ename[20];
public:
//Function to count the total number of
records
int Countrec();
};
int Item::Countrec()
{
fstream File;
File.open(“EMP.DAT”,ios::binary|ios::in);
______________________
//Statement 1
Answer:
F(U,V)=U’.V+U.V’
(Full 2 marks for obtaining the correct Boolean Expression for the Logic
Circuit) OR (1 mark correctly interpreting Product terms)
(d) Write the SOP form of a Boolean function G, which is represented in a
truth table as follows: 1
Answer:
P Q R G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
G(P,Q,R) = P’.Q.R’+P.Q’.R’+P.Q.R’+P.Q.R
(1 mark for correct SOP representation)
(e) Reduce the following Boolean Expression using K-Map: 3
F(U,V,W,Z)=Π(0,1,2,4,5,6,8,10)
Answer:
F(U,V,W,Z)=UV+WZ+UZ
(1 mark for correctly drawing K-Map with 1s represented on right places)
(1 mark for minimizing each Quad)
(1 mark for writing the complete Boolean Expression)
7.a)Define the term Bandwidth. Give unit of Bandwidth. 1
Answer:
Bandwidth is the capability of a medium to transmit an amount of
information over a distance. Bandwidth of a medium is generally measured
in bits per second (bps) or more commonly in kilobits per second (kbps)
Prepared By: PGT-IT, JNV West Godavari 168 9 490236965,[email protected]
( ½ Mark for correct definition and ½ Mark for correct unit)
b) Expand the following terminologies: 1
(i) HTML (ii) XML
Answer:
(i) Hypertext Markup Language
(ii) Extended Markup Language
( ½ Mark for each correct expansion)
e) Define the term firewall. 1
Answer:
Firewall is a feature used for Network Security. In a Network there
is always danger of information leaking out or leaking in. Firewall is
a feature which forces all information entering or leaving the network
to pass through a check to make sure that there is no unauthorized
usage of the network.
(1 Mark for correct definition)
f) What is the importance of URL in networking? 1
Answer:
URL stands for Uniform Resource Locator. Each page that is created
for Web browsing is assigned a URL that effectively serves as the
page’s worldwide name or address. URL’s have three parts: the
protocol , the DNS name of the machine on which the page is located
and a local name uniquely indicating the specific page(generally the
filename).
(1 Mark for correct significance)
e) Ravya Industries has set up its new center at Kaka Nagar for its office and
web based activities. The company compound has 4 buildings as shown in
the diagram below:
Building
Building
Fazz
Raj
Building
Jazz
Building
Harsh
Building
Building
Fazz
Raj
Building
Jazz
Building
Harsh
Layout 2: Since the distance between Fazz Building and Jazz Building is
quite short
Building
Building
Fazz
Raj
Building
Jazz
Building
Harsh