KENDRIYA VIDYALAYA SANGATHAN, KOLKATA REGION
Computer Science Question Bank
Unit – 2
Unit / Chapter
VSA
SA I
SA II
(1 Mark)
(2 Marks)
(3 Marks)
Object Oriented Programming in C++
a)
b)
c)
d)
e)
Introduction to OOP using C++
Constructor& Destructor
Inheritance
Pointers
Data File Handling
Total
_
_
1
1
1
1
_
_
1
1
LA
(4 Marks)
1
_
1
-
Total
(2) 6
(1) 2
(1) 4
1(3)
(3) 6
IMPORTANT QUESTIONS (1 OR 2 TIMES)
Chapter – Introduction to OOP using C++
2005 Define the term Data Hiding in the context of Object Oriented Programming. Give a
Suitable example using a C++ code to illustrate the same.
Define a class TravelPlan in C++ with the following descriptions :
Private Members:
PlanCode of type long
Place of type character array (string)
Number_of_travellers of type integer
Number_of_buses of type integer
Public Members:
A constructor to assign initial values of Plan Code as 1001, Place as “Agra”,
Number_of_travellers as 5, Number_of_buses as 1
A function NewPlan( ) which allows user to enter PlanCode, Place and
Number_of_travellers. Also, assign the value of Number_of_buses as per the
following conditions :
Number_of_travellersNumber_of_buses
Less than 20
Equal to or more than 20 and less than 40
Equal to 40 or more than 40 3
A function ShowPlan( ) to display the content of all the data members on screen.
2006 Define Multilevel and Multiple inheritance in context of Object Oriented Programming. Give suitable exam
Define a class named ADMISSION in C++ with the following descriptions:
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.
2007 What do
you
understand.by Data Encapsulation and Data·Hiding?Also,giveanexampleinC++toillus
Define a class STOCK in C++ with following description :
Private Members
•
!Code of type integer (Item Code)
•
Item of type string (Item Name)
•
. Price of type float (Price of each item)
•
Qty of type. integer (Quantity in stock)
•
Discount of type float (Discount percentage on the itedJ.)
•
A member function FindDisc() to calculate discount s
per the following rule :
If Qty<=50
Discount is 0
If 50<Qty<=l00 . Discount is 5
If Qty> lOO
Discount is 10
Public Members
• A function Buy() to allow user to enter values for Code, Item, Price,. Qty and call function FindDisc() to calcula& the Dis
•
A • function ShowAll() to allow user to view the content of all the data members.
2008 Differentiatebetweenmembers,whicharepresentwithintheprivatevisibility
modewiththosewhicharepresentwithinthepublicvisibilitymodes.
Define a class Candidate in C++ with following description :
Private Members
•
A data member RNo (Registration Number) of type long
•
A data member Name of type string
•
A data member Score of type float
•
A data member Remarks of type string
•
A member function AssignRem( ) to assign Remarks as per the Score obtained by a candidate. Scor
Score
Remarks
>=50
Selected
lessthan50Notselected
PublicMembers
AfunctionENTER()toallowusertoentervaluesforRNo,Name,Score &
2009
AfunctionDISPLAY()toallowusertoviewthecontentofallthedatamembe
What is copy constructor? Give an example in C++ to illustrate copy constructor.
Define a class Applicant in C++ with following description :
Private Members
•
A data member ANo (Admission Number) of type long
•
A data member Name of type string
•
A data member Agg (Aggregate Marks) of type 'float
•
A data member Grade of type char
•
A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by a student. Equivalent
as follows :
Aggregate Marks
Grade
>=80 A
less than 80 and >=65 B
less than 65 and >=50 c
less than 50
D
:,
Public Members
•
A function ENTER() to allow user to enter values for ANo, Name, Agg & call function GradeMe() to find the Grade
•
A function RESULT() to allow user to view the content of all the data members.
2010 What
do
you
understand . by Data
Encapsulation and Data • Hiding ? Also, give an example in C++ to illus
Define a class STOCK in C++ with following description :
Private Members
•
!Code of type integer (Item Code)
•
Item of type string (Item Name)
•
. Price of type float (Price of each item)
•
Qty of type. integer (Quantity in stock)
•
Discount of type float (Discount percentage on the itedJ.)
•
A member function FindDisc() to calculate discount s
per the following rule :
If Qty<=50
If Qty> lOO
Discount is 0 If 50<Qty<=l00
Discount is 10
. Discount is 5
Public Members
• A function Buy() to allow user to enter values for Code, Item, Price,. Qty and call function FindDisc() to calcula& the Dis
•
A • function ShowAll() to allow user to view the contentof all the data members.
2011 Differentiate between Constructor and Destructor function with respecttoObjectOrientedProgramming.
(c)
Define a class Applicant in C++ with following description :
Private Members
•
A data member ANo (Admission Number) of type long
•
A data member Name of type string
•
A data member Agg (Aggregate Marks) of type 'float
•
A data member Grade of type char
•
A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by a student. Equivalent
as follows :
Aggregate Marks
Grade
>=80 A
less than 80 and >=65 B
less than 65 and >=50 c
less than 50
D
:,
Public Members
•
A function ENTER() to allow user to enter values for ANo, Name, Agg & call function GradeMe() to find the Grade
•
A function RESULT() to allow user to view the content of all the data members.
2012 What is the difference between the members in private visibility mode and the members in protected visibility mode insi
Define a class RESTRA in C++ with following description:
Private Members
FoodCode of type int
Food of type String
FType of type string
Sticker of type string
A member function GetSticker() to assign the following values for Sticker as per the given FType:
FType
Sticker
Vegetarian
GREEN
Contains Egg
YELLOW
Non-Vegetarian
RED
Public Members
A function GetFood() to allow user to enter values for FoodCode,Food,FType and call function GetSticker() to ass
A function ShowFood() to allow user to view the content of all data members.
2013 Write any two differences between Constructor and Destructor. Write the function headers for constructor and destruct
Define a class Tourist in C++ with the following specification:
Data Members
carno – to store Bus No
Origin – to store Place name
Destination – to store Place name
Type – to store Car Type such as ‘E’ for Economy
Distance – to store the Distance in Kilometers
Charge – to store the car fare
Member Functions
A contructor function to initialize Type as ‘E’ and Freight as 250
A function CalcCharge() to calculate Fare as per the following citeria:
Type
Charge
‘E’
16 * Distance
‘A’
22 * Distance
‘L’
30 * Distance
A function Enter() to alow user to enter values for carno,origin,destination,type and distance. Also this function should
A function Show () to display the content of all the data members on screen.
2014
Write anytwodifferences betweenConstructor andDestructor.Write functionheadersforconstructoranddestructor
(c) Define a class Tourist in C++ with the following specification :
Data Members
•
Camo - to store Bus No
•
Origin - to store Place name
•
Destination - to store Place name
•
Type - to store Car Type such as 'E' for Economy
•
Distance - to store the Distance in Kilometers
•
Charge - to store the Car Fare Member Functions
•
A constructor function to initialize Type as 'E' and Freight as 250
•
A function CalcCharge() to calculate Fare as per the following criteria :
Type Charge
' E ' 16*Distance
'A ' 22*Distance
' L ' 30*Distance
•
A function Enter() to allow user to enter values for Carno, Origin, Destination, Type and Distance. Also,
•
A function Show() to display the content of all the data members on screen.
Chapter - Constructor & Destructor
2005 Answer the 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;
}
Test (char P [] ) // Function 2
{
strcpy(Paper,P);
Marks = 0;
}
Test (int M) // Function 3
{
strcpy(Paper,”Computer”);
Marks = M;
}
Test (char P[], int M) // Function 4
{
strcpy (Paper, P);
Marks = M;
}
};
(i) Which feature of Object Oriented Programming is demonstrated using
Function 1, Function 2, Function 3 and Function 4 in the above class Test?
(ii) Write statements in C++ that would execute Function 2 and Function 4 of
class Test.
2006 Answer the questions (i) and (ii) after going through the following class:
class Interview
{ int month;
public:
Interview (int y) {month=y ;} //Constructor 1
Interview (Interview&t); //Constructor 2
};
i. Create an object, such that it invokes Constructor 1.
ii. Write complete definition for Constructor 2.
2007
Answerthequestions(i)and(ii)aftergoingthroughthefollowing
class:
classExam
intRno,MaxMarks,MinMarks,Marks;public:
Exam()
I/Module1
Rno=l01;MaxMarks=lOO;MinMarks=40;Marks=75;Exam(intPrno,intPmarks)
Rno=Prno;MaxMarks=lOO;MinMarks=40;Marks=Pmarks;
-Exam()
I/Module3
cout<< Exam Over <<endl;
void Show()
I/Module4
11
11
cout<<Rno<<":"<<MaxMarks<<":"<<MinMarks<<endl;cout<<"[MarksGot]"<<M
};
(i)
which concept isillustrated byModule 1andMod
As per ObjectOriented Programming,
(ii)
What is Module 3referred as ? When
Module3willbeinvoked/called ?
2008 Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming used in the
'
'
by the functions [I] to [IV].
# include <iostream.h>
void Print ( )
// Function [I]
{
for(intK=l·K<=60 ·K++)cout<<"-"·
cout<<endl;
}
11Function[II]
voidPrint(intN)
{
for(intK=l·,K<=N·,L++)cout<<"*"'·cout<<endl;
}
voidPrint(charT,intN)
11 Function[IV]
{
for(intK=l;K<=N;K++)cout<<T;cout<<endl;
'
,
}
voidmain ()
{
intU=9,V=4,W=3;
charC='("a.)',·
Print(C,V);
Print(U,W);
}
2009 Write the output of the following C++ code. Also, write the name of feature of Object Oriented programming used in the
#include<iostream.h>
void Line()
// Function 1
{
for(int L=1; L<= 80; L++) cout<<”-“;
cout<<endl;
}
void Line(int N)
// Function 2
{
for(int L=1; L<=N; L++) cout<<”*”;
cout<<endl;
}
void Line(char C,A,int N)
{
for(int L=1; L<=N; L++) cout<<C;
cout<<endl;
}
void Line(intM,int N)
{
for(int L=1; L<=N; L++) cout<<M*L;
cout<<endl;
}
void main()
{
int A=9,B=4,C=3;
char K=’#’;
Line(K,B);
Line(A,C);
}
// Function 3
// Function 4
2010 Answer the questions (i) and (ii) after going through the following
class :
class Exam
int Rno,MaxMarks,MinMarks,Marks; public:
Exam () I /Module 1
Rno=l01;MaxMarks=l O O;MinMarks=40;Marks=75; Exam (int Prno,int Pmarks) I /Module 2
Rno=Prno;MaxMarks=lO O;MinMarks=40;Marks=Pmarks;
-Exam ()
I /Module 3
cout<< 11 Exam Over 11 <<endl;
void
Show () I /Module 4
cout<<Rno<<" :"<<MaxMarks<<" :"<<MinMarks<<endl; cout<<" [Marks Got]" <<Marks<<endl;
};
i)
which concept isillustrated byModule 1andMod
As per ObjectOriented Programming,
ii) What is Module 3referred as ? When
Module3willbeinvoked/called ?
do you think,
2011 Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming used i
[IV] :
*include
< iost ream .h>
void
Line ( ) / / Funct ion
[I]
{
f or
( int
L= l ; L<=8 0 ; L++ )
cout<<"-"; cout<<endl ;
1',
void
Line ( int
N)
{
f or
( int
L= l ; L<=N ;L+ + )
void
Line ( cha r
{
f or
( int
void
Line ( int
{
f or
( int
C , int N )
/ / Funct ion
[ II ]
cout<<"*"; cout<<endl ;
/ / Funct ion
[III]
L= l ;L<=N ;L++) cout<<C ; cout<<endl ;
M , int N )
/ / Funct ion
[IV]
L= l ; L<=N ;L++ ) cout<<M*L ; cout<<endl ;
void
ma in ( )
{
int
A= 9 , B= 4 , C=3;
char K='#'; Line ( K , B) ;
Line ( A , C ) ;
}
2012 Answer the questions(i) and (ii) after going through the following class :
class Travel
{
intPlaceCode; char Place[20]; float Charges;
public:
Travel()
// Function 1
{
PlaceCode =1; strcpy(Place,”DELHI”); Charges=1000;
}
Travel(float C)
// Function 2
{
Cout<<PlaceCode<<”:”<<Place<<”:”<<Charges<<endl;
}
~Travel()
// Function 3
{
Cout<<”Travel Plan Cancelled”<<endl;
}
Travel(intPC,char P[],float C)
// Function 4
{
PlaceCode = PC; strcpy(Place,P); Charges = C;
} };
i) In Object Oriented Programming, what are Function 1 and Function 4 combined together referred as ?
ii) In Object Oriented Programming, which concept is illustrate by Function 3? When is this function called/invoked?
2013 Answer the question (i) and (ii) after going through the following class :
Class Motor
{
Int MotorNo,Track;
Public:
Motor();
// Function 1
Motor (int MN);
// Function 2
Moto (Motor & M);
// Function 3
Void Allocate();
// Function 4
Void Move();
// Function 5
};
Void main()
{
Motor M;
:
:
}
(i) Out of the following, which of the option is correct foe calling function 2?
Option 1 – Moto N(M);
Option 2 – Motor P(10);
(ii) Name the feature of Object Oriented Programming, which is illustrated by Function1,Function 2 and Function 3 c
2014
Answer the questions (i) and (ii) after going through the following class :
class Motor
{
int MotorNo, Track; public:
Motor();
//Function 1
Motor (int MN) ; //Function 2 Motor(Motor &M) ; //Function 3 void Allocate {); //Function 4 void Move();
};
void main ()
{
Motor M;
}
(i) Out of the following, which of the option is correct for calling Function 2 ?
Option 1 - Motor N(M ); Option 2 - Motor P(lO );
(ii)
Name the feature of Object Oriented Programming, which is illustrated by Function 1, Function 2 and Function 3
Chapter - Inheritance
2005 Answer the questions (i) to (iv) based on the following code: 4
class Medicines
{
char Category[lO];
char Date_of_manufacture[lO];
char Company[20];
public:
Medicines();
void entermedicinedetails();
void showmedicinedetails();
} ;
class Capsules: public Medicines
{
protected:
char capsule_name[30];
char Volume_label[20];
public:
float Price;
Capsules();
void entercapsuledetails();
void showcapsuledetails();
};
class Antibiotics: public Capsule
{
intDosage_units;
char Side_effects[20];
intUse_within_days;
public:
Antibiotics() ;
void enterdetails();
void showdetails();
};
(i) How many bytes will be required by an object of class Medicines and an object
of class Antibiotics respectively?
(ii) Write names of all the member functions accessible from the object of class
Antibiotics.
(iii) Write names of all the members accessible from member functions of class
Capsules.
(iv) Write names of all the data members, which are accessible from objects of class
Antibiotics.
2006 Answer the questions (i) to (iii) based on the following code
class stationary
{
char Type;
char Manufacturer [10];
public:
stationary();
void Read_sta_details( );
void Disp_sta_details( );
};
class office: public stationary
{
intno_of_types;
float cost_of_sta;
public:
void Read_off_details( );
void Disp_off_details( );
};
class printer: private office
{
intno_of_users;
char delivery_date[10];
public:
void Read_pri_details( );
void Disp_pri_details( );
};
void main ( )
{ printer MyPrinter; }
i. Mention the member names which are accessible by MyPrinter declared in main() function
ii. What is the size of MyPrinter in bytes?
iii. Mention the names of functions accessible from the member function
Read_pri_details () of class printer.
2007 Answerthequestions(i)to(iv)basedonthefollowing
Class·Director
{
long
DID;
char Name[20];
protected:
charDescription[40];
voidAllocate();
public:
Director();voidAssign();void Show();
};
classFactory:public
{
intFID;
charAddress[20];
Directer
I/Factory
protected:
intNOE;
ID
I
I/No.ofEmployees
public:
Factory();voidInput();
Void Output();
};
classShowRoom:private Factory
{
intSID;
I/Showroo:nIDcharCity[20];
public:
ShowRoom();
voidEnter();
voidDisplay();
};
(i)Whichtypeof·inheri tance·,outofthe .followingisillustratedinthe aboveC++ ?
(a) Single level Inheritance
(b) MultiLevelInheritance
(c) Multiple Inheritance
(iii) Write the names of members which are accessible by the object of class showroom.
(iv) Write the names of member function which are accessible by the object of class showroom.
(v) Write the names of members which are accessible by the object of class Factory.
2008 Answerthequestions(i)to(iv)based·onthefollowing:
class Student
{
int Rno ;
char Name[20] ; float Marks ;
protected :
void Result ( ) ; public :
Student ( ) ;
void Register ( ) ; void Display ( ) ;
};
class Faculty
{
long FCode ;
char FName [20] ;
protected :
float Pay ; public :
Faculty ( ) ; void Enter ( ) ; void Show ( ) ;
};
class Course : public Student, private Faculty
{
long CCode [IO]; char CourseName [50]; char StartDate [8J, EndDate [8] ;
public :
Course ( ) ;
void Commence ( ) ; void CDetail ( ) ;
};
(i)
Which type of inheritance is illustrated in the above C++ code ?
(ii)
Write the names of all the data members, which is/are accessible from member function Commence of class Cou
(iii)
Write the names of member functions, which are accessible from objects of class Course.
(iv)
Write the names of all the members, which are accessible from objects of class Faculty.
2009 Answerthequestions(i)to(iv)based·onthefollowing:
Class student
{
int Rollno;
char SName [20]; float Marksl
protected:
void Result (); public:
Student();
void Enroll( );void Display( );
};
Class teacher
{
long TCode;
char TName [20]; protected:
float Salary; public:
Teacher(); void Enter (); void
Show ();
};
class Course: public Student , private Teacher
{
long CCode[lO];char CourseName[ SO]; char StartDate[8],EndDate[8];
public:
Course( );
void Commence (); void CDetail ();
};
(i)
(ii)
(iii)
(iv)
Write the names of member functions, which are accessible from objects of class Course.
Write the names of all the data members, which is/are accessible from member function Commence of class Cou
Write the names of all .the members, which are accessible from objects of class Teacher.
Which type of Inheritance 1s illustrated in the above C++ code ?
2010 Answerthequestions(i)to(iv)basedonthefollowing
Class·Director
{
long
DID;
char Name[20];
protected:
charDescription[40];
voidAllocate();
public:
Director();voidAssign();void Show();
};
classFactory:public
{
intFID;
charAddress[20];
Directer
I/Factory
protected:
intNOE;
ID
I
I/No.ofEmployees
public:
Factory();voidInput();
Void Output();
};
classShowRoom:private Factory
{
intSID;
I/Showroo:nIDcharCity[20];
public:
ShowRoom();
voidEnter();
voidDisplay();
};
(i)Whichtypeof·inheri tance·,outofthe .followingisillustratedinthe aboveC++ -'
?·
(d) Single level Inheritance
(e) MultiLevelInheritance
(f) Multiple Inheritance
(vi) Write the names of members which are accessible by the object of class showroom.
(vii) Write the names of member function which are accessible by the object of class showroom.
Write the names of members which are accessible by the object of class Factory.
2011 Answerthequestions(i)to(iv)based·onthefollowing:
Class Student
{
Int Rollno;
Char SName[20];
Float Marks1;
Protected :
Void Result();
Public:
Student();
Void Enroll(); void display();
};
Class Teacher
{
Long TCode;
Char TName[20];
Protected:
Float salary;
Public:
Teacher();
Void Enter();
Void show();
};
Class Course : public Student , private Teacher
{
Long CCode[10]; char CourseName[50];
Char StartDate[8],EndDate[8];
Public:
Course();
Void Commerce();
Void CDetails();
};
(i) Write the names of member functions, which are accessible from objects of class Course.
(ii)Writethenamesofallthedatamembers,whichis/areaccessiblefrommemberfunctionCommenceof c
(iii)Writethenamesofall.themembers,which areaccessiblefromobjectsofclassTeacher.
(iv)Which type of Inheritance 1s illustrated in the above C++ code ?
2012 Answerthequestions(i)to(iv)basedonthefollowing:
class COMPANY
char Loca tion [20 ] ;
double Budget , Incorne; pr otected :
void
Accou n ts ( ) ; public :
COMPANY ( ) ;
void
Register ( ) ; void
Show ( ) ;
};
cla ss FACTORY :public COMPANY
char
Location ( 2 0 ) ; int
Wor kers;
protected :
double Salar y; void
Computer ( ) ;
public :
FACTORY () ;
void Enter ( ) ; void
Show ( ) ;
};
class SHOP : pr ivate COMPANY
cha r Loca t ion [ 2 0 ] ; f loat
double Sale ; public :
SHOP ( ) ;
void
Inpu t ( ) ; void Outpu t ( ) ;
};
(i)
Area ;
Name thetype ofinheritanceillustrated m the above C++code.
(ii)
Writethenameofdatamembers,which arcaccessiblefromm emberfunctionsofclassS
(iii)
Write the names of all the member fonctions, which areaccessiblefromobjectsbe
(iv)
Writethe names ofall themem bers, which arcaccessiblefromobjectsofclassSHOP
2013 Consider the following C++ code and answer the questions from (i) to (iv):
Class Student
{
Int Class,Rno;
Char Section;
Protected:
Char SName[20];
Public:
Student();
Void Stentry();
Void Stddisplay();
};
Class Score : private Student
{ Float Marks[5];
Protected:
Char Grade[5];
Public:
Score();
Void Sentry();
Void Sdisplay();
};
Class Report : public Score
{
Float Total, Avg;
Public:
Char OverallGrade,Remarks[20];
Report();
Void Revaluate();
Void RPrint();
};
(i) Which type of Inheritance is shown in the above example ?
(ii) Write the names of those data members, which can be directly accessed from the objects of class Report.
(iii) Write the names of those members functions , which can be directly accessed from the objects of class Report.
(iv) Write the names of those data members, which can be directly accressed from the Sentry() function of class Scor
2014
(d)
Consider the following C++ code and answer the questions from (i) to (iv) :
class Student
{
(i)
int Class,Rno; char Section;
protected :
char SNarne[20]; public :
Student();
void Stentry(); void Stdisplay();
};
class Score: private Student
{
float Marks[S]; protected:
char Grade[S]; public:
Score ();
void Sentry(); void Sdisplay();
};
class Report: public Score
{
float Total, Avg; public:
char OverallGrade, Remarks [20];
Report();
void REvaluate( ); void RPrint();
}i
Which type of Inheritance is shown in the above example ?
(ii)
(iii)
(iv)
Write the names of those data members, which can be directly accessed from the objects of class Report.
Write the names of those member functions, which can be directly accessed from the objects of class Repo
Write the names of those data members, which can be directly accessed from the Sentry() function of class Score
Chapter –Pointers
2005
Findtheoutputofthefollowingprogram :
#include <iostream.h> void main ()
{
int *Queen,Moves[ ]={ll,22,33,44}; Queen=Moves;
Moves[ 2]+=22;
cout<<"Queen @"<<*Queen<<endl;
*Queen-=11; Queen+=2;
cout<<"Now @"<<*Queen<< ndl; Queen++;
cout<<"Finally @"<<*Queen<<endl;
cout<<"New Origin @"<<Moves[O]<<endl;
2006 Findtheoutputofthefollowingprogram
#include<iostream.h>
#include<string.h>classstate
{
char*state_name;intsize;
public;
state();{size=0;state_name=newchar[size+1];}state(char*s)
{
size=strlen(s);state_name=newchar[size+1];}strcpy(state_name,s);
}
voiddisplay(){cout<<statename<<endl;}voidReplace(state&a,state&b)
{
size=a.size+b.size;deletestate_name;
2
state_name=newchar[size+1];strcpy(state_name,a.state_name);strcat(state_name,b.stat
}
};
voidmain()
{
char*temp=“Delhi”;
statestate1(temp),state2(”Mumbai”),state3(”Nagpur”),SI,S2;SI.Replace(state1,state2);
S2.Replace(S1,state3);S1.display();
S2.display();
}
2007
(c)
Findtheoutputofthefollowingprogram:
#include<iostream.h>voidmain()
{
intTrack[]={I0,20,30,40},*Striker;Striker=Track;
Track[1]+=30;cout<<"Striker>"<<*Striker<<endl ;
*Striker-=10;Striker++;
cout<<"Next@"<<*Striker<<endl;Striker+=2;
cout<<"Last@"<<*Striker<<endl;
cout<<"ResetTo"<<Track[O]<<endl;
}
2008 Findtheoutputofthefollowingprogram:
#include<iostream.h>voidmain()
{
intTrack[]={I0,20,30,40},*Striker;Striker=Track;
Track[1]+=30;cout<<"Striker>"<<*Striker<<endl ;
*Striker-=10 ;Striker++;
cout<<"Next@"<<*Striker<<endl;Striker+=2;
cout<<"Last@"<<*Striker<<endl;
cout<<"ResetTo"<<Track[O]<<endl;
}
2009
Findtheoutputofthefollowingprogram :
#include <iostream.h> void main ()
{
int *Queen,Moves[ ]={ll,22,33,44}; Queen=Moves;
Moves[ 2]+=22;
cout<<"Queen @"<<*Queen<<endl;
*Queen-=11; Queen+=2;
cout<<"Now @"<<*Queen<< ndl; Queen++;
cout<<"Finally @"<<*Queen<<endl;
cout<<"New Origin @"<<Moves[O]<<endl;
2
2010 Find the output of the following program :
2
#include
<iostrearn.h>
#include
<ctype.h>
void
MyCode(char Msg[],char
CH)
for(int Cnt=O;Msg[Cnt] !=' \0' ;Cnt++)
if
(Msg[Cnt]>='B' &&
Msg[Cnt]<=' G' ) Msg[Cnt]=tolower(Msg[Cnt]);
else
if
(Msg[Cnt]=='A' 1 1
Msg[Cnt]==' a' ) Msg[Cnt]=CH;
else
if
(Cnt%2==0) Msg[Cnt]=toupper(Msg[ Cnt]);
else
Msg[Cnt]=Msg[Cnt-1];
void
main ()
{
char MyText []="ApEACeDri VE" ; MyCode(MyText, '@' );
cout<< "NEW TEXT: "<<MyText<<endl;
2011
2
Findtheoutputofthefollowingprogram :
#include <iostream.h> void main ()
{
int *Queen,Moves[ ]={ll,22,33,44}; Queen=Moves;
Moves[ 2]+=22;
cout<<"Queen @"<<*Queen<<endl;
*Queen-=11; Queen+=2;
cout<<"Now @"<<*Queen<< ndl; Queen++;
cout<<"Finally @"<<*Queen<<endl;
cout<<"New Origin @"<<Moves[O]<<endl;
2012
Findtheoutputofthefollowingprogram
#include
<iostrearn.h>
#include <ctype.h>
typedefcharStr80f80];
void main()
{char*Notes;
Str80SLr'-""vR2GooO";
intL=6;Notes=Str;while
(L>=3)
Str[L]=(isupper(Str!
T.l)?to.L owcr.(SLrfr,]): toupper(Str[L]));
cout<<Notes<<endl ;
L-- ;
Notes++;
}
2014 Observe the following C++ code carefully and obtain the output, which will appear on the screen after execution of it.
Important Note :
All the desired header files are already included in the code, which are required to run the code.
void main ( )
{
char *String="SHAKTI" ;
int
*Point,Value[]={l0,15,70,19}; Point=Value ; coutcc*PointccStringccendl; String++;
Point++ ; coutcc*PointccStringccendl ;
}
Chapter –Data File Handling
2006 void main( )
1
{
char=’A’;
fstream fileout(”data.dat”,ios::out); fileout<<ch;
int p = fileout.tellg( ); cout<<p;
}
What is the output if the file content before the execution of the program is the string “ABC”
(Note that” “are not part of the file)
Writeafunctiontocountthenumberofwordspresentinatextfilenamed“PARA.TXT”.Assumethateachwordisseparat
edbyasingleblank/spacecharacterandnoblanks/spacesinthebeginningandendofthefile.
c.
Following is the structure of each record in a data file named “COLONY.DAT”.
struct COLONY
{charColonyCode[
10];charColon
yName[10];in
tNoofPeople;
};
WriteafunctioninC++toupdatethefilewithanewvalueofNo_of_People.Thevalueof
Colony_CodeandNo_of_Peoplearereadduringtheexecutionoftheprogram.
2007 Observetheprogramsegmentgivenbelowcarefullyandfilltheblanksmarked asStatement
1andStatement2usingtellg()and seekp()functionsforperformingtherequiredtask.
#include <fstream.h>
class Customer
{
longCno;charName[20],Mobile[12];public:
//FunctiontoallowusertoentertheCno,Name,Mobile
voidEnter();
//Functiontoallowusertoenter
(modify)mobilenumbervoidM
odify();
//FnctiontoreturnvalueofCnolongGetCno(){r
eturnCno;}
};
void ChangeMobile()
2
3
{
Customer C;
fstream
F;
F.open (11 CONTACT. DAT 11 , i.os: :binary I ios: :in I
ios:out) ;
long Cnoc; //Customer no. whose mobile number needs to be
c:;hanC,ed•. cin>>Cnoc;
while (F.read((char*)&C,sizeof(C)))
if (Cnoc==C.GetCno())
C.Modify ();
//Statement 1
int Pos=I /To finq the curret position of file pointer \';•
//Statement 2
//To move the file pointer to write the
.}
//modified record back onto the file
//for the des.ired Cnoc • F.write( (char*)&C,sizeof(C));
}
'
F.close();
2008 Observetheprogramsegmentgivenbelowcarefullyandfilltheblanksmarked asStatement
1andStatement2usingseekg(),seekp( ),tellp()andtellg() functionsforperformingtherequiredtask.
#include<fstream.h>
classPRODUCT
{
intPno;char Pname[20];intQty;
public:
void ModifyQty ( )II The function is to modify quantity of aPRODUCT
};
voidPRODUCT: :ModifyQty()
{
fstreamFile;
Fil.open("PRODUCT.DAT", ios::binary Iios::inIios::out);int MPno;
cout <<"ProductNotomodify quantity:";cin>>MPno;
while(Fil.read((char*)this,sizeof(PRODUCT) ))
{
if(MPno==Pno)
{
1
cout<<"PresentQuantity:"<<Qty<<endl
;cout<<"ChangedQuantity:";cin>>Qty;
intPosition=
//Statement 1
//Statement2
Fil.write ((char*)this, sizeof(PRODUCT) ) ;IIRe-writing therecord
}
}
Fil.cFil.close();
}
WriteafunctioninC++tocounttheno.of"Me"or"My"wordspresenttextfile"DIARY.TXT". If
thefile"DIARY.TXT"contentisas follows:
MyfirstbookwasMeandMyfamily.Itgavemechancetobe knowntotheworld.
TheoutputofthefunctionshouldbeCountofMe/Myinfile:4
Write a function in C++ to search for a laptop from a binary
file
"LAPTOP.DAT"containingtheobjectsofclassLAPTOP (asdefinedbelow).
TheusershouldentertheModelNoandthefunctionshouldsearchanddisplay
thedetailsofthelaptop.
classLAPTOP
{
long ModelNo;float
RAM,HDD;char
Details[120];
public:
voidStockEnter(){cin>>ModelNo>>RAM>>HbD;gets(Details);}
voidStockDisplay(){cout<<ModelNo<<RAM<<HDD<<Details<<endl;}long
ReturnModelNo(){returnModelNo;}
};
2009 Observe the program segment given below carefully and fill the blanks marked as Statement1 and Statement
2 using seekg() , seekp(), tellp() and tellg() functions for performing the required task.
#include<fstream.h>
Class ITEM
{
Int Ino;
Char Iname[20]; float Price;
Public:
Void ModifyPrice(); // The function is to modify price of a particular ITEM
}:
Void ITEM :: ModifyPrice()
{
Fstream File;
File.Open(“ITEM.DAT”,ios::binary | ios::in | ios::out);
Int CIno;
Cout<<”Item No to modify price :”; cin>>Cino;
While(File.read((char *)this,sizeof(ITEM))
{
2
3
If(Cino == Ino)
{
Cout<<”Present Price: ”<<Price<<endl;
Cout<<”Changed Price:”; cin>>Price;
Int FilePos = ___________; // statement 1
_____________________; Statement 2
File.write ((char *) this, sizeof(ITEM)); // Re-writing the record
}
}
File.close();
}
Write a function in C++ to count the no. of “He” or “She” words present in a text file
“STORY.TXT”.
If the file “STORY.TXT” content is as follows :
He is playing in the ground. She is
playing with her dolls.
The output of the function should be
Count of He/She in file :2
2
WriteafunctioninC++tosearchforacamerafromabinaryfile"CAMERA.DAT" containing theobjects
ofclassCAMERA (asdefined below). The user should enter the Model No and
thefunctionshouldsearchanddisplaythedetailsofthecamera.
Class CAMERA
{
Long ModelNo;
Float MegaPixel;
Int Zoom;
Char Details[120];
Public:
Void Enter() {cin>>ModelNo>>MegaPixel>>Zoom; gets(Details);}
Void Display() {
Cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;}
Long GEtModelNo() { return ModelNo;}
3
};
2010 Observetheprogramsegmentgivenbelowcarefullyandfilltheblanksmarked asStatement
1andStatement2usingtellg()and seekp()functionsforperformingtherequiredtask.
#include<fstream.h>classCust
omer
longCno;charName[20],Mobile[12];public:
//FunctiontoallowusertoentertheCno,Name,Mobile
voidEnter();
//Functiontoallowusertoenter
(modify)mobilenumbervoidM
odify();
//FnctiontoreturnvalueofCnolongGetCno(){r
eturnCno;}
};
voidChangeMobile()
1
{
---CustomerC;
fstream
F;
F.open(11CONTACT.DAT11,i.os::binaryIios::inIios::out);
longCnoc;//Customerno.whosemobilenumberneedstobec:;
hanC,ed·.cin>>Cnoc;
while (F.read((char*)&C,sizeof(C)))
if(Cnoc==C.GetCno())
C.Modify();
Int Pos = _______________ // To find the current
position of file pointer
//Tomovethefilepointertowritethe
.}
//modifiedrecordbackontothefile
//forthedes.iredCnoc·F.write((c
har*)&C,sizeof(C));
}
'
F.close();
}
2011 Observe the program segment given below carefully and fill the blanks marked as Statement1 and Statement
2 using seekg() , seekp(), tellp() and tellg() functions for performing the required task.
#include<fstream.h>
Class ITEM
{
Int Ino;
Char Iname[20]; float Price;
Public:
Void ModifyPrice(); // The function is to modify price of a particular ITEM
}:
Void ITEM :: ModifyPrice()
{
Fstream File;
File.Open(“ITEM.DAT”,ios::binary | ios::in | ios::out);
Int CIno;
Cout<<”Item No to modify price :”; cin>>Cino;
While(File.read((char *)this,sizeof(ITEM))
{
If(Cino == Ino)
1
{
Cout<<”Present Price: ”<<Price<<endl;
Cout<<”Changed Price:”; cin>>Price;
Int FilePos = ___________; // statement 1
_____________________; Statement 2
File.write ((char *) this, sizeof(ITEM)); // Re-writing the record
}
}
File.close();
}
WriteafunctioninC++tocounttheno.of"He"or"She"words·presentinatextfile"STOR
Y.TXT".
Ifthefile"STORY.TXT"contentisasfollows:
Heisplaying
intheground.Sheisplayi
ngwithherdolls.
2
Theoutputofthef unctionshouldbe
CountofHe/She
infile:2
.
WriteafunctioninC++tosearchforacamerafromabinaryfile"CAMERA.DAT" containing theobjects
ofclassCAMERA (asdefined below). The user should enter the Model No and
thefunctionshouldsearchanddisplaythedetailsofthecamera.
Class CAMERA
{
Long ModelNo;
Float MegaPixel;
Int Zoom;
Char Details[120];
Public:
Void Enter() {cin>>ModelNo>>MegaPixel>>Zoom; gets(Details);}
Void Display() {
Cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;}
Long GEtModelNo() { return ModelNo;}
};
2012
Observe the program segmentgivenbelow carefully and thequestionsthatfollow:
class
{
Stock
int Ino,Qty; char
Item[20];
public:
void Enter() cin>>Ino; gets(Item); cin>>Qty;}
void Issue(int Q) {Qty -= Q;}
void Purchase(int Q) {Qty + = Q; }
int Getino() { return Ino;}
};
3
1
Void PurchaeItem(int Pino, int PQty)
{
f stream Fi le ;
File .open ( " STOCK .DAT " , ios : :binary l ios : :in l ios : :'ou t ) ; Stock
S;
Int Su ccess= O ;
}
while
(Success==O
&&
File.read((cha.r*) &S,sizeof(S)))
if (Pino==S.GetIno())
S.Purchase(PQty);
_________________ // Statement 1
_________________ / / Statement 2
Success++;
if( Su ccess== l }
cout<< "Pu rcha se Updated " <<endl ; else
cout<< "W rong
Item No" <<endl ; Fi le . close ( ) ;
Writestatement1topositionthefilepointertotheappropriatepla
(i)
ce,sothatthedataupdationisdonefor therequireditem.
(ii)Writestatement2toperformthewriteoperation
sothattheupdationisdoneinthebinaryfile.
Write a function in C++ to read the content of a text file"DELHI.TXT"and
displayallthoselineson screen, which areeitherstartingwith'D'orstartingwith'M'.
Write a function in C++ to search for the details (Phoneno and calls) of those Phones,
which have more than 800 calls from a binary file “Phones.dat”. Assuming that this
binary file contains records objects of class Phone, which is defined below .
2
3
Class Phone
{
charPhoneno[lO];intCalls;
public:
voidGet(){gets(Phoneno);cin>>Ca lls;}
voidBilling(){cout<<Phoneno<<"#"<<Calls<<endl;}
intGetCalls(){returnCalls;}
};
2014
Fillintheblanksmarked asStatement 1andStatement2,intheprogram
segmentgivenbelowwithappropriatefunctionsfortherequiredtask.
class Customer
{
1
long int CNo; // Customer Number
char CNmae [20]; // customer Name
char Email[30]; // Email of customer
public:
void Allocate(); // Function to allocate a member
void show(); // Function to show customer data
void ModifyEmail() // Function to modify Email
{ cout<<””Enter Modified Email :”;
Gets(Email);
}
long int GetCno() {return CNo; }
};
void ChangeData()
{
fstream File;
File .open (11 CUST.DAT 11 , ios: :binary I ios::in I ios::out) ; int Change=O ,Location;
long int ChangeCno;
cout<<"Cno - whose email required to be modified:"; cin>>ChangeCno;
Customer CU;
while(!Modify && File.read((char*)&CU,sizeof (CU)))
{
if (CU.GetCno()==ChangeCno)
{
CU .ModifyEmail() ; Location=File.tellg()- sizeof (CU);
//Statement l :To place file
pointer to
the required position
//Statement 2:To write
the
object CU on to
the binary file
Change++;
}
}
if (Change)
cout<<"Email Modified ... 11 <<endl; else
cout<< "Customer not found ... 11 <<endl; File .close();
}
WriteafunctionCountHisHer()inC++whichreadsthecontentsofatextfile
diary.txtandcountsthewordsHisandHer(notcase sensitive). Forexample,ifthefilecontains:
Pinakyhasgonetohisfriend'shouse.Hisfriend's
nameisRavya.Herhouseis12KMfromhere.
Thefunctionshoulddisplaytheoutputas
CountforHis:2
CountforHer:l
2
Assuming the class VINTAGE as declared below, write a function in C++ to read the objects of
VINTAGE from binary file VINTAGE.DAT an. d display
those vintage vehicles, which are priced between 200000 and 250000.
class VINTAGE
{
int VNO;
//Vehicle Number
char VDesc[lO] ; //Vehicle Description float Price;
.public :
void GET() {c.in>>VNO;gets {VDesc) ;cin>>Price;} void VIEW {)
{
cout<<VNO<<endl ; cout<<VDesc<<endl; cout<<Price<<endl ;
}
float ReturnPrice {) {return Price;}
};
3
© Copyright 2026 Paperzz