Professional Documents
Culture Documents
_
1
1
1
_
1
1
_
1
-
Total
(2)
(1) 2
(1) 4
1(3)
(3) 6
200
6
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.
Define Multilevel and Multiple inheritance in context of Object Oriented
Programming. Give suitable example to illustrate the same.
2
4
What do
you understand . by Data Encapsulation
Also, give an example in C++ to illustrate both.
(4
)
Private Members
Discount is 0
. Discount is 5
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 Discount.
200
8
A function ShowAll() to allow user to view the content of all the data members.
Differentiate between members, which are present within the private visibility
mode with those which are present within the public visibility modes.
2
4
Remarks
>=50
Selected
less than 50
Not selected
Public Members
A function ENTER( ) to allow user to enter values for RNo, Name,
Score & call function AssignRem( ) to assign the remarks.
A function DISPLAY( ) to allow user to view the content of all the data
members.
200
9
A member function GradeMe() to find the Grade as per the Aggregate Marks
obtained by a student. Equivalent Aggregate Marks range and the respective Grades
are shown
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.
201
0
What do
you understand . by Data
Encapsulation
Also, give an example in C++ to illustrate both.
Define a class STOCK in C++ with following description :
Private Members
2
4
Public Members
A function Buy() to allow user to enter values for Code, Item, Price,. Qty and call
function FindDisc() to calcula& the Discount.
201
1
201
2
A function ShowAll() to allow user to view the content of all the data
members.
Differentiate between Constructor and Destructor function with respect to
Object Oriented Programming.
(c)
Define a class Applicant in C++ with following description :
Private Members
A member function GradeMe() to find the Grade as per the Aggregate Marks
obtained by a student. Equivalent Aggregate Marks range and the respective Grades
are shown
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.
What is the difference between the members in private visibility mode and the
members in protected visibility mode inside a class? Also, give a suitable C++ code to
illustrate both.
2
4
201
4
Write any two differences between Constructor and Destructor. Write the function
headers for constructor and destructor of a class Member.
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 call CalcCharge() to calculate Fare.
A function Show () to display the content of all the data members on screen.
Write any two differences between Constructor and Destructor. Write function headers for
constructor and destructor of a class Member.
(c) Define a class Tourist in C++ with the following specification :
Data Members
2
4
2
4
A function Enter() to allow user to enter values for Carno, Origin, Destination, Type and
Distance. Also, this function should call CalcCharge() to calculate Fare.
A function Show() to display the content of all the data members on screen.
Chapter - Constructor & Destructor
200 Answer the questions (i) and (ii) after going through the following class:
5
classTest
{
charPaper[20];
intMarks;
public:
Test()//Function1
{
strcpy(Paper,Computer)
Marks=0;
}
Test(charP[])//Function2
{
strcpy(Paper,P);
Marks=0;
}
Test(intM)//Function3
{
strcpy(Paper,Computer);
Marks=M;
}
Test(charP[],intM)//Function4
{
strcpy(Paper,P);
Marks=M;
}
};
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.
200
7
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;
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)
200
8
Write the output of the following C++ code. Also, write the name of feature of Object
Oriented Programming used in the following program jointly illustrated
by the functions [I] to [IV].
# include <iostream.h>
void Print ( )
// Function [I]
{
for (int K=l K<=60 K++) cout<< "-"
''
'
cout<<endl ;
,
}
void Print (int N)
11 Function [II]
11 Function [IV]
{
for (int K= l ;K<=N ;K++) cout<<T ;
cout<<endl ;
}
void main ( )
{
int U=9, V=4, W=3;
char C= '("a.)' ,
Print (C, V) ;
200
9
Print (U, W) ;
}
Write the output of the following C++ code. Also, write the name of feature of Object
Oriented programming used in the following program jointly illustrated by the functions
(i) to (iv) :
#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)
// Function 3
{
for(int L=1; L<=N; L++) cout<<C;
cout<<endl;
}
void Line(intM,int N)
// Function 4
{
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);
}
201
0
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)
Write the output of the following C++ code. Also, write the name of feature of
Object Oriented Programming used in the following ' program jointly illustrated by
the functions [I] to [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)
/ / Funct ion [ II ]
{
f or
( int
L= l ; L<=N ;L+ + )
void
{
f or
( int
void
Line ( int
{
f or
( int
cout<<"*"; cout<<endl ;
/ / Funct ion [ I I I ]
void
{
int
char
Line (
201
2
201
3
ma in ( )
A= 9 , B= 4 , C=3;
K='#'; Line ( K , B) ;
A,C);
}
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?
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)
(ii)
201
4
Out of the following, which of the option is correct foe calling function 2?
Option 1 Moto N(M);
Option 2 Motor P(10);
Name the feature of Object Oriented Programming, which is illustrated by
Function1,Function 2 and Function 3 combined together.
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();
//Function 5
};
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 combined together.
Chapter - Inheritance
200 Answer the questions (i) to (iv) based on the following code: 4
5
classMedicines
{
charCategory[lO];
charDate_of_manufacture[lO];
charCompany[20];
public:
Medicines();
voidentermedicinedetails();
voidshowmedicinedetails();
};
classCapsules:publicMedicines
{
protected:
charcapsule_name[30];
charVolume_label[20];
public:
floatPrice;
Capsules();
voidentercapsuledetails();
voidshowcapsuledetails();
};
classAntibiotics:publicCapsule
{
intDosage_units;
charSide_effects[20];
intUse_within_days;
public:
Antibiotics();
voidenterdetails();
voidshowdetails();
};
200
6
(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.
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?
200
7
iii. Mention the names of functions accessible from the member function
Read_pri_details () of class printer.
Answer the questions (i) to (iv) based on the following
Class Director
{
long
DID;
char Name[20];
protected:
char Description[40] ;
void Allocate ();
public:
Director(); void Assign ();
void Show ();
};
class Factory:public
{
int FID;
char Address[20];
Directer
I /Factory
ID
protected:
int NOE;
I /No. of Employees
public:
Factory(); voidInput ();
Void Output ();
};
class ShowRoom:private Factory
{
int SID;
I /Showroo:n ID char City[20];
public:
ShowRoom ();
void Enter ();
voidDisplay ();
};
(i)Which type of inheri tance, out of the . following is illustrated in the above C+
+?
Single level Inheritance
Multi Level Inheritance
(c) Multiple Inheritance
(iii)
Write the names of members which are accessible by the object of class
showroom.
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.
Answer the questions (i) to (iv) based on the following :
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
{
(iv)
200
8
200
9
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 Course.
(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.
Answer the questions (i) to (iv) based on the following :
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)
Write the names of member functions, which are accessible from objects of class
Course.
(ii)
Write the names of all the data members, which is/are accessible from member
function Commence of class Course.
(iii)
Write the names of all .the members, which are accessible from objects of class
Teacher.
(iv)
Which type of Inheritance 1s illustrated in the above C++ code ?
201
0
Directer
I /Factory
ID
201
1
};
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)Write the names of all the data members, which is/are accessible from
member function Commence of class Course.
(iii)Write the names of all .the members, which are accessible from objects of
class Teacher.
(iv)Which type of Inheritance 1s illustrated in the above C++ code ?
201
2
(i)
(ii)
Write the name of data members, which arc accessible from m ember
functions of class SHOP.
(iii)
Write the names of all the member fonction s, which are accessible
201
4
Write the names of all the mem bers, which arc accessible from
objects of class SHOP.
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 Score.
(d)
Consider the following C++ code and answer the questions from (i) to
(iv) :
class Student
{
int Class,Rno; char Section;
protected :
char SNarne[20]; public :
Student();
void Stentry(); void Stdisplay();
(i)
};
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)
Write the names of those data members, which can be directly accessed from
the objects of class Report.
(iii)
Write the names of those member functions, which can be directly
accessed from the objects of class Report.
(iv)
Write the names of those data members, which can be directly accessed from
the Sentry() function of class Score.
Chapter Pointers
200
Find the output of the following program :
5
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( )
{
}
200
7
(c)
# inclu de <iostream.h>
void main ( )
{
int Track [ ] = {I 0, 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 << "Reset To" <<Track [O] <<endl ;
}
200 Find the output of the following program :
8
201
0
#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'
11
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;
201
1
201
2
<iostrearn .h>
void main()
{
char
*Notes;
Str80 SLr'-""vR2GooO" ;
int L=6; Notes=Str
; while
(L>=3 )
L-- ;
Notes++;
}
201
4
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 ;
}
char Colony
Code[10];
char Colony
Name[10]; int
No of People;
};
Write a function in C++ to update the file with a new value of No _of_People.
The value of Colony_Code and No_of_People are read during the execution of
the program.
200 Observe the program segment given below carefully and fill the
7
blanks marked as Statement 1 and Statement 2 using tellg() and
seekp() functions for performing the required task.
#include <fstream.h>
class Customer
{
long Cno;char Name[20], Mobile[12]; public:
//Function to allow user to enter the Cno, Name, Mobile
void Enter();
//Function to allow user to enter (modify) mobile number
void Modify();
//Fnction to return value of Cno long
GetCno() {return Cno;}
};
void ChangeMobile()
{
Customer C;
fstream
F;
.}
'
F.close();
200
8
Observe the program segment given below carefully and fill the blanks marked as Statement
1 and Statement 2 using seekg( ), seekp( ), tellp( ) and tellg( ) functions for performing the
required task.
# include <fstream.h>
class PRODUCT
{
{
fstream File ;
Fil.open ("PRODUCT.DAT", ios : : binary
I ios
: : in
I ios
Fil.cFil.close( ) ;
}
Write a function in C++ to count the no. of "Me" or "My" words present text file "DIARY.TXT".
If the file "DIARY.TXT" content is as follows :
My first book was Me and My family. It gave me chance to be known to the world.
The output of the function should be Count of Me/My in file : 4
Write a function in C++ to search for a laptop from a binary file
};
200
9
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)
{
Cout<<Present Price: <<Price<<endl;
Cout<<Changed Price:; cin>>Price;
Int FilePos = ___________; // statement 1
_____________________; Statement 2
}
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
Write a function in C++ to search for a camera from a binary file
"CAMERA.DAT" containing the objects of class CAMERA (as defined below).
The user should enter the Model No and the function should search and
display the details of the camera.
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;}
201
0
};
Observe the program segment given below carefully and fill the
blanks marked as Statement 1 and Statement 2 using tellg() and
seekp() functions for performing the required task.
#include <fstream.h> class
Customer
long Cno;char Name[20], Mobile[12]; public:
//Function to allow user to enter the Cno, Name, Mobile
void Enter();
//Function to allow user to enter (modify) mobile number
void Modify();
//Fnction to return value of Cno long
GetCno() {return Cno;}
};
void ChangeMobile()
{
Customer C;
fstream
F;
11
,
(F.read((char*)&C,sizeof(C)))
if (Cnoc==C.GetCno())
C.Modify();
Int Pos = _______________ // To find the current
position of file pointer
.}
'
F.close();
201
1
}
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)
{
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.
Stock
Item [ 2 0 ] ;
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;}
};
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
if( Su ccess== l }
cout<< "Pu rcha se Updated " < <endl ; else
cout<< "W rong
(i)
Class Phone
{
char Phoneno[lO];int Calls;
public :
void Get (){gets(Phoneno); cin>>Calls;}
void Billing(){cout<<Phoneno<<"#"<<Cal ls<<endl;}
int GetCalls (){return Calls;}
201
4
};
Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given
below with appropriate functions for the required task.
class Customer
{
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();
}
Write a function CountHisHer ( ) in C++ which reads the contents of a text file
diary.txt and counts the words His and Her (not case sensitive). For example, if the file contains :
Pinaky has gone to his friend's house. His friend's
name is Ravya. Her house is 12 KM from here.
The function should display the output as
//Vehicle Number