Thursday

Important Questions and Answers of Data File Handling of Class 12 - CBSE

 Question 26:

Write a definition for function BUMPER() in C++ to read each object of a binary file GIFTS.DAT, find and display details of those gifts, which has remarks as “ON,DISCOUNT”. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below: Delhi 2016

class GIFTS 
{
int ID;char Gift[20]. Remarks[20]; float Price: 
public:
void Takeonstock()
{
cin>>ID;gets(Gift) ;gets (Remarks) ;cin>>Price;
}
void See()
{
cout<<ID<<":"«Gift<<":" <<Price<< ": "<<Remarks<<endl;
}
char *GetRemarks() {return Remarks;
};

Answer:

void BUMPER!)
{
GIFTS obj;
ifstream infile!"GIFTS . DAT"); 
while(infile.read!(char*)&obj, 
sizeof(obj)))
{
if(strcmp (obj.GetRemarks(),
"ON DISCOUNT") == 0) 
obj See();
}
infile.close!);
}

Question 27:
Write function definition of DISP3CHAR() in C++ to read the content of a text file KIDINME.TXT and display all those words, which has three characters in it. All India 2016
e.g. If the content of the file KIDINME.TXT is as follows:

” When I was a small child, I used to play in the garden with my grand mom.
Those days were amazingly funful and I remember all the moments of that time.”

The function DISP3CHAR() should display the following:

“was the mom and all the”

Answer:

void DISP3CHAR()
{
ifstream fin("KIDINME.TXT"); 
char word[80];
while(!fin.eof())
{
fin>>word;
if(strlen(word)==3&&(! 
(word[2]<65| |(word[2]>90&&word 
[2]<97)| | word[2]<122))) 
cout<<word<<"“; 
else if(strlen(word)==4&&
((word[3]<65| |word[3]>90)&& 
(word[3]<97| |word[3]>122)))
{
for(int i=0;i<3;i++) 
cout<<word[i];
cout<<" ”;
}
}
fin.close();
}

Question 28:
Write a definition for function ONOFFER() in C++ to read each object of a binary file TOYS.DAT, find and display details of those toys, which has status as “ON OFFER”. Assume that the file TOYS.DAT is created with the help of objects of class TOYS, which is defined below: All India 2016

class TOYS
{
int TID;char Toy[20],Status[20];float MRP;
public:
void Getinstock()
{
cin>>TID;gets(Toy);gets(Status);cin>>MRP;
}
voidView()
{
cout<<TID<<": ”<<Toy<<": "<<MRP<<n": "<<Status<<endl;
}
char*SeeOffer()(return Status;}
};

Answer:

void ONOFFER()
{
TOYS obj;
ifstream i nfileCTOYS.DAT"); 
while( infile.read((char*)&obj, 
sizeof(obj)))
{
if(strcmp(obj.SeeOffer(),
"ON OFFER")==0) 
obj.View();
}
infile.closer()
}

Question 29:
Write function definition for WORDABSTART ()in C++ to read the content of a text file JOY.TXT, and display all those words, which are starting with either ‘A’, ‘a’ or ‘B’, ‘b’. All India (C) 2016
e.g. If the content of the file JOY.TXT is as follows:

“I love to eat apples and bananas. I was travelling to Ahmedabad to buy some clothes.”

The function WORDABSTART() should display the following:

“apples and bananas Ahmedabad buy”

Answer:

void WORDABSTART()
{
ifstream fin("JOY.TXT"); 
char ch[80]; 
while (!fin.eof())
{
fin>>ch;
if(ch[0]—'A' | |ch[0]='a'| |ch[0] 
=='b' 11 chCO]—'B’) 
cout<<ch<<'"';
}
fin.close();
}

Question 30:
Write function definition for SUCCESS() in C++ to read the content of a text file STORY.TXT, count the presence of word STORY and display the number of occurrence of this word. Delhi 2015

NOTE -The word STORY should be an independent word
-Ignore type cases (i.e. lower/upper case)

e.g. if the content of the file STORY.TXT is as follows:

” Success shows others that we can do it. It is possible to achieve success with hard work. Lot of money does not mean SUCCESS.”

The function SUCCESS() should display the following:

“3”

Answer:
There is error in this question. STORY should be replaced by SUCCESS word, i.e. we have to count SUCCESS word according to output.

void SUCCESS()
{
ifstream in("STORY.TXT"); 
char ch[200];
 int count = 0; 
while(!in.eof())
{
in>>ch;
if(strcmpi(ch,"success")==0) 
count++;
}
cout<<count; 
in.close();
}

Question 31:
Write a definition for function Economic() in C++ to read each record of a binary file ITEMS.DAT, find and display those items, which cost less than 2500. Assume that the file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined below: Delhi 2015

class ITEMS 
{
int ID; char GIFTC20]; float Cost:
public:
void Get()
{
cin>>ID; gets (GIFT) ;cin>>Cost;
}
void See()
{
cout<<ID<<": "<<GIFT<<": "<<Cost<<endl;
}
float GetCost(){return Cost;}
}:

Answer:

void Economic() 
{
ifstream fcinCITEMS.DAT",ios:: in|ios::binary):
ITEMS i; 
float co;
while(fcin.read((char*)&i,
 sizeof(i)))
{
co=i.GetCost(); 
if(co<2500) 
i.See();
}
fcin.close();
}

Question 32:
Write function definition for TOWER() in C++ to read the content of a text file WRITEUP.TXT, count the presence of word TOWER and display the number of occurrences of this word. All India 2015

NOTE – The word TOWER should be an independent word.
– Ignore type cases (i.e. lower/upper case).
e.g. If the content of the file WRITEUP.TXT is as follows:

“Tower, of hanoi is an interesting problem. Mobile phone tower is away from here. Views from EIFFEL TOWER are amazing.”

The function TOWER() should display the following :

“3 ”

Answer:

void TOWER()
{
ifstream in("WRITEUP.TXT"); 
char ch[200]; 
int count = 0; 
while(!in.eof())
{
i n >> c h;
if(strcmpi (ch,"Tower") == 0) 
count++;
}
cout<<count; 
in.close ();
}

Question 33:
Write a definition for function COSTLY() in C++ to read each record of a binary file GIFTS.DAT, find and display those items, which are priced more than 2000. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below: All India 2015

class GIFTS 
{
int CODE: char ITEMC20]: float PRICE; 
public:
void Procure()
{
cin>>CODE; gets(ITEM): cin>>PRICE; 
}
void View()
{
cout<<C0DE<<": "<<ITEM<<": "<<PRICE<<endl;
}
float GetPrice() {return PRICE:)

Answer:

void COSTLY()
{
ifstream fcinCGIFTS.DAT", 
ios :: in|ios :: binary); 
GIFTS g; 
float pr;
while(fcin.read((char*)&g, 
sizeof(g)))
{
pr=g.GetPrice(); 
if (pr>2000)
g.View();-
}
fcin.close();
}

Question 34:
Write function definition for COUNTNU( )in C++ to read the content of a text file
CONTENT.TXT, count the characters N and U (in lower case as well as upper case) present in the file. All India 2015 C
e.g. Assume the content of the file CONTENT. TXT is as follows:

“New research shows that our closest evolutionary relatives have all of the cognitive, capacities required for cooking except an understanding of how to control fire.”

The function COUNTNU( )should display the following:
“13”

Answer:

void COUNTNU()
{
ifstream fin("C0NTENT.TXT"); 
char C; 
int count=0; 
while(!fin.eof())
{
C=fin.get();
if(fin.eofO)
break;
if(C=='N'||C=='n'||C= ='U'||C= ='u'|
count++;
}
fin.close(); 
cout<<count;
}

Question 35:
Write a function EUCount() in C++, which should reads each character of a text file. “IMP.TXT”, should count and display the occurrence of alphabets E and U (including small cases e and u too). Delhi 2014
e.g. If the file contains is as follows:

Update information is simplified by official websites.

The EUCount() function should display the output as:

E : 4 
U : 1

Answer:

void EUCount() 
{
ifstream infiie("IMP.TXTn); 
char ch;
int countE=0,countU=0; 
while(infile)
{
infile.get(ch);
 if(ch=='E' | | ch=='e')
countE++;
else if(ch=='U' || ch=='u') 
countU++; '
}
cout<<"E ; "<<countE<<endl; 
cout<<"U : "<<countU;
}

Question 36:
Assuming the class GAMES as declared below, write a function in C++ to read the objects of GAMES from binary file “GAMES.DAT” and display the details of those GAMES, which are meant for children of AgeRange “8 to 13”. Delhi 2014

class GAMES
{
int GameCode; 
char GameName[10]; 
char *AgeRange; 
public:
void Enter()
{
cin>>GameCode;
gets(GameName);
gets(AgeRange);
}
void Display()
{
cout<<GameCode<<": "<<GameName<<endl; 
cout<<AgeRange<<endl;
}
char*AgeR() {return AgeRange;}
};

Answer:

void READGAMES() 
{
GAMES obj;
ifstream infileCGAMES.DAT"); 
whi1e(infile.read((char*)&obj, 
sizeof(obj)))
{
if(strcmp(obj.AgeR(),"8 to 13") == 0)
obj.Display();
}
infile.close();
}

Question 37:
Write a function AECount() in C++, which should read each character of a text file “NOTES.TXT”, should count and display the occurrence of alphabets A and E (including small cases a and e too). All India 2014
e.g. If the file content is as follows: .

CBSE enhanced its
CCE guidelines further.

The AECount() function should display the output as

A: 1 
E: 7

Answer:

void AECount()
{
ifstream infile(”NOTES.TXT"); 
char ch;
int countA=0.countE=0; 
while(infile)
{
infile.get(ch);
if(ch==' A ’ | | ch=='a') 
countA++;
else if(ch= = 'E' || ch= = 'e') 
countE++;
}
cout<<"A : "<<countA<<endl; 
cout<<"E : "<<countE;
}

Question 38:
Assuming the class TOYS as declared below, write a function in C++ to read the objects of TOYS from binary file “TOYS.DAT” and display the details of those TOYS, which are meant for children of Age Range “5 to 8”. All India 2014

class TOYS 
{
int ToyCode;
char ToyName[10]; 
char *AgeRange; 
public:
void Enter()
{
cin>>ToyCode; 
gets(ToyName); 
gets(AgeRange);
}
void Display() 
{
cout<<ToyCode<<": "<<ToyName<<endl; 
cout<<AgeRange<<endl;
}
char* WhatAge()I return AgeRange;}
};

Answer:

void READTOYS()
{
TOYS obj;
ifstream infile!"TOYS.DAT"); 
while(infile.read((char*)&obj, sizeof(obj)))
{
if(strcmp(obj.WhatAge(),
"5 to 8") == 0) 
obj .Display!);
}
infile.close();
}

Question 39:
Given a binary file “SPORTS.DAT” containing records programme following class: All India (C) 2014

class Player 
{
char PNO[10]; //Player number
char Name [20]; //Name of player
int rank; //Rank of the player
public:
void EnterData()
{
gets (PNO); gets (Name) ;cin>>rank;
}
void DisplayData ()
{
cout<<setw(12)<<PN0; 
cout<<setw(32)<<Name; 
cout<<setw(3)<rank<<endl;
}
int Ret_rank(){return rank;}
};

Write a function in C++ that would read contents of the file “SPORTS.DAT” and display the details of those players whose rank is above 500.

Answer:

void READPLAYER()
 {
Player obj;
ifstream infileCSPORTS.DAT"); 
while(infile.read(char*)&obj, 
sizeof(obj)))
{
if(obj.Ret_rank()>500)
obj.DisplayDataO;
}
infile.close();
}

Question 40:
Write a function Countaroma() to count and display the number of times “Aroma” occurs in a test file “Cook.txt”.
All India (C) 2014
NOTE  Only complete word “Aroma“should be counted. Words like “Aromatic“should not be counted.

Answer:

void Countaroma()
{
ifstream inC'Cook.TXT"); 
char ch[200]; 
int count=0; 
while(!in.eof())
{
in>>ch;
if(strcmpi (ch, "aroma")=0) 
count++;
}
cout<<count; 
in.close();
}

Question 41:
Write a function CountYouMef) in C++, which reads the content of a text file “story.txt” and counts the words You and Me (not case sensitive). All India 2013
e.g. if the file contains:

You are my best friend.
You and me make a good team.

The function should display the output as

Count for You: 2 
Count for Me: 1

Answer:

void CountYouMe()
{
ifstream Filein; 
char arr[10]; clrscr();
Filein.open("story.txt", ios::in);
i f (! Filein)
{
cout<<"File does not exist!"; 
exit(0);
}
int i=0,j=0; 
while(!Filein.eof ())
{
Filein>>arr;
if(strcmpi(arr,"You")==0) 
i++;
else if(strcmpi(arr,"Me")==0) 
J++:
}
Filein.close();
cout<<"Count for Yog:"<<i<<endl; 
cout<<"Count for Me: "<<j<<endl;
}

Question 42:
Write a function CountDig() in C++, which reads the content of text file “story.txt” and displays the number of digits in it.
Delhi (C) 2013
e.g. if the file contains:

Amrapali was a queen of Gareware kingdom in 
the year 1911. She had 2 daughters.
Her palace had 200 rooms.

Then the output on the screen should be

Number of digits in story:8

Answer:

void CountDig()
{
int count=0; 
char Ch;
ifstream fcin("story.txt"); while(fcin)
{
fcin.get(Ch); 
if(Ch>=48&&Ch<=57)
{
count++;
}
}
cout<<"Number of digits in story; "<<count;
fcin.close();
}

Question 43:
Assuming the class WORKER as declared below, write a function in C++ to read the objects of WORKER from binary file named “WORKER.DAT” and display those records of workers, whose wage is less than 300. Delhi 2013C

class WORKER
{
int WN0;
char WName[30]; float Wage; 
public:
void EnterO (cin>>WN0;gets(WName); cin>>Wage;}
void DISP() {cout<<WNO<<"*"<<WName<<"*"<<Wage<<endl;}
float GetWageC) (return Wage;}
};

Answer:

void SHOW()
{
ifstream fcin!"WORKER.DAT", ios;;in|ios::binary);
WORKER W;
whi le(fcin.read((char*)&W, 
sizeof(W)))
{
if(W.GetWage()<300)
{
W.DISP();
}
}
fcin.close();
}

Question 44:
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). Delhi 2013
e.g. 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

Count for His : 2 
Count for Her : 1

Answer:

void CountHisHer()
{
ifstream AL;
AL.open("diary.txt",ios;:in); 
char Word[80]; 
int C1=0, C2=0;
while(!AL.eof())
{
AL>>Word;
if(strcmpi(Word, "His")==0)
 C1++;
else if(strcmpi(Word, "Her")==0)
C2++;
}
cout<<"Count for His :"<<C1 <<endl;
cout<<"Count for Her : "<<C2<<endl;
AL.close();
}

Question 45:
Assuming the class VINTAGE as declared below, write a function in C++ to read the objects of VINTAGE from binary file “VINTAGE.DAT” and display those vintage vehicles, which are priced between 200000 and 250000. Delhi 2013

class VINTAGE 
{
int VNO; //Vehicle Number
char VDesc[10]: //Vehicle Description
float Price; 
public:
void GET() {cin>>VN0;gets! VDesc) ;cin>>Price;}
void VIEW()
{
cout<<VNO<<endl ; 
cout<<VDesc<<endl; 
cout<<Price<<endl;
}
float ReturnPrice()
{
return Price;
}
};

Answer:

void show()
{
ifstream fcin("VINTAGE.DAT", 
ios::in|ios::binary);
VINTAGE V; 
float pr;
while(fcin.read((char*)&V, sizeof(V))) 
{
pr = V.ReturnPrice();
if(pr>=200000 && pr<=250000)
{
V.VIEW();
}
}
fcin.close();
}

Question 46:
Assuming the class ANTIQUE as declared below, write a function in C++ to read the objects of ANTIQUE from binary file “ANTIQUE.DAT” and display those antique items, which are priced between 10000 and 15000. All India 2013

class ANTIQUE 
{
int ANO; 
char Aname[10]; 
float Price; 
public:
void BUY()
{
cin>>ANO.;gets(Aname); 
cin>>Price;
}
void SHOW() 
{
cout<<AN0<<endl; 
cout<<Aname<<endl;
cout<<Price<<endl ;
}
float GetPricel){return Price;}
};

Answer:

void search()
{
ifstream ifile("ANTIQUE.DAT”, 
ios::in|ios::binary); 
if (! ifile)
{
cout<<"could not open ANTIQUE.
DAT; exit(-1);
}
else
{
ANTIQUE a;
whileCifile.read((char*)&a, sizeof(a)))
{
if(a.GetPrice()>=10000&& 
a.GetPrice()<=15000) 
a.SHOW();
}
}
}

Question 47:
Write a function in C++ to read the content of a text file “PLACES.TXT” and display all those lines on screen, which are either starting with ‘P’ or starting with ‘S’. Delhi 2012
Answer:

void Display()
{
ifstream fcin("PLACES.TXT"); 
char Ch[100]; .
fcin.getline(Ch.100); 
while(!fcin.eof())
{
if(Ch[0]=='P'|| ChCO]=='S')
{
cout<<Ch<<endl;
}
fcin.getline(Ch,100);
}
fcin.close();
}

Question 48:
Write a function in C++ to read the content of a text file “DELHI.TXT” and display all those lines on screen, which are either starting with ‘D’ or starting with ‘M’. All india 2012
Answer:

void Display()
{
char str[100]; 
ifstream fcin("DELHI.TXT"); 
fcin.getline(str,100); 
while(!fcin.eof!)
{
if(str[0]=='D' | |str[0]— ’M’) 
{
cout<<str<<endl;
}
fcin.getline(str,100);
}
fcin.close()
{

Question 49:
Write a function in C++ to search for the details (Number and Calls) of those Mobile phones, which have more than 1000 calls from a binary file “mobile.dat”. Assuming that this binary file contains records/objects of class Mobile, which is defined below. Delhi 2012

class Mobile
{
char Number[10];int Calls; 
public:
void Enter() fgets(Number) ;cin>>Calls;}
void Billing!) {cout<<Number<"#"<<Calls<<endl;}
int GetCal1s() (return Calls;)
};

Answer:

void Display()
{
Mobile M;
ifstream fcinCmobile.dat",
ios;; in | ios:: binary) ; 
fcin.read!(char*)&M, sizeof(M)); 
while(fin.eofc)
{
if(M.GetCalIs()>1000)
{
M.Billing();
}
fcin.read((char*)&M,sizeof(M));
}
fcin.close();
}

Question 50:
Write a function C++ to search for the details (Phoneno and Calls) of those phones, which have more than 1000 calls from a binary file “phones.dat”. Assuming that this binary file contains records/objects of class Phone, which is defined below.
All India 2012

class Phone
{
char Phoneno[10];int Calls; 
public:
void get(){gets(Phoneno) ;cin>>CalIs;}
void billing() (cout<<Phoneno<<"#”<<Calls<<endl;}
int getCal1s()(return Calls;}
};

Answer:

void show()
{
ifstream fcin!"phones.dat".
ios::in|ios::binary);
Phone P;
fcin.read((char*)&P,sizeof(P)); 
while(fcin)
{
if(P.getCalls()>1000)
{
P.billing();
}
fcin.read((char*)&P,sizeof(P));
}
fcin.close();
}

Question 51:
Write a function in C++ to count the number of “Me” or “My” words present in a text file “DIARY.TXT”. If the file “DIARY.TXT” content is as follows: Delhi 2011

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

Answer:

void count()
{
ifstream fin!"DIARY.TXT");
char word[10];
int C = 0;
while(!fin.eof())
{
fin>>word; *
if((strcmpi(word,"Me")== 0)
||(strcmpi(word,"My")== 0))
C++;
}
cout<<Count of Me/My in file:"<<C; fin.close();
}

Question 52:
Write a function in C++ to search!) for a laptop from a binary file “LAPTOP.DAT” containing the objects of class LAPTOP (as defined below). The user should enter the ModelNo and the function should search and display the details of the LAPTOP. Delhi 2011

class LAPTOP
{
long ModelNo; 
float RAM,HDD; 
char Details[120];
public
void StockEnter( Hcin>>ModelNo>>RAM>>HDD;gets(Detail s);}
void StockDisplay() {cout<<Model No<<RAM<<HDD<<Details<<endl;} 
long ReturnModelNo(){return ModelNo;}
};

Answer:

void Search() 
{
LAPTOP L;
long Model No; 
if stream fin;
cout<<"enter the model no of laptop:"; cin>>ModelNo; 
fin.open("LAPTOP.DAT", ios:binary); 
while(fin.read((char*)&L, sizeof(L))
{
if(L.ReturnModelNo() == Model No) 
}
L.StockDisplay();
}
fin.close();
}

Question 53:
Write a function in C++ to count the number of “He” or “She” words present in a text file “STORY.TXT”. If the file “STORY.TXT” content is as follows. All India 2011

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

Answer:

void Wordcount()
}
ifstream finOSTORY.TXT"); 
char word [10]; 
int C=0;
while(!fin.eof())
{
fin>>word;
if ((strcmpi (word, "He" )== 0)
||(strcmpi(word,"She") == 0)) 
C++;
}
cout<<"Count of He/She in file : 
”<<C;
fin.close();
}

Question 54:
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 ModelNo and the function should search and display the details of the camera.
All India 2011

class CAMERA 
{
long Model No; 
float Megapixel; 
int Zoom;
char Detai1s[120]; .
public;
void Enter() (cin>>ModelNo>>MegaPixel>>Zoom; gets (Detai Is);} 
void Display() (cout<<Model No<<MegaPixel <<Zoom<<Details<<endl;} 
long GetModelNo(){return ModelNo;}
};

Answer:

void SearchCam()
{
CAMERA C; 
long Model No; 
ifstream fin;
cout<<"enter the camera model no:"; 
cin>>ModelNo;
 fin.openCCAMERA.DAT", ios::binary);
while(fin.read((char*)&C, sizeof(C)))
{
if (C.GetModel No()==ModelNo) 
C.Display();
}
fin.close();
}

Question 55:
Write a function in C++ to count the words “to” and “the” present in a text file “POEM.TXT”. (Note that the words “to” and “the” are complete words) All India 2010
Answer:

void Wordcount()
{
ifstream fin("P0EM.TXT"); 
char word[80]; 
|| int WC=0;
while(ifin.eof())
{
fin>>word;
if((strcmp(word,"to")== 0)
11Cstrcmp(word,"the")— 0)) 
WC++;
}
cout<<"Count of to/the in file;
"<<WC;
fin.close();
}

Question 56:
Write a function in C++ to search and display details of all trains, whose destination is “Delhi” from a binary file “TRAIN.DAT”. Assuming the binary file is containing the objects of the following class: All India 2010

class TRAIN
{
int Tno; //Train number
char From[20]; //Train starting point
charTo[20]; //Train destinaton
public:
char *GetFrom()(return From;}
char *GetTo(){return To;}
void InputO (cin>>Tno; gets(From);gets(To):}
void Show() {cout<<Tno<<":"<<From<<":"<<To<<endl;}
};

Answer:

void Read() 
{
TRAIN T; 
ifstream fin;
fin.open("TRAIN.DAT",ios::binary); 
while(fin.read((char*)&T,sizeof(T))) 
{
if(strcmpi(T.GetTo(), "Del hi")== 0)
T.Show();
}
fin.close!);
}

Question 57:
Write a function in C++ to count the words “this” and “these” present in a text file “ARTICLE.TXT”. [Note that the words “this” and “these” are complete word] Delhi 2010
Answer:

void Wordcount()
{
ifstream finCARTICLE.TXT"); 
char word[80];
int C=0;
while!ifin.eof())
{
fin>>word;
if((strcmpi(word,"this") == 0)
||(strcmpi(word,"these") == 0)) 
C++;
}
cout<<"Number of this and these words are; "<<C; 
fin.close();
}

Question 58:
Write a function in C++ to search and display details of all flights, whose destination is “Mumbai” from a binary file “FLIGHT.DAT”. Assuming the binary file is containing the objects of the following class: Delhi 2010

class FLIGHT
{ 
int Fno; //flight number
char From[20]; //flight starting point
char To[20]; //flight destination
public:
char *GetFrom(){return From;}
char *GetTo(){return To;}
void Enter(){cin>>Fno;gets(From);gets(To);}
void Display()(cout<<Fno<<":”<<From<<”:"<<To<<endl;}
};

Answer:

void Read()
{
FLIGHT F;
ifstream fin;
fin.open("FLIGHT.DAT", ios::binary); 
while(fin.read((char*)&F, 
sizeof(F)))
{
if(strcmpi(F.GetTo(), "Mumbai") == 0)
F.Display();
}
fin.close!);
}

Question 59:
Write a function COUNT_TO() in C++ to count the presence of a word ‘To” in a text file “NOTES.TXT”. All India 2009
If the content of the file “NOTES.TXT” is as:

It is very important to know that 
Smoking is injurious to health 
Let us take initiative to stop it

The function COUNT_TO() will display the following message:
Count of-to-in file: 3
Answer:

void COUNT_TO
{
ifstream fin("N0TES.TXT"); 
char str[10]; 
int C=0;
while(!fin.eof)))
{
fin>>str;
if(strcmpi(str,"To")==0)
C++;
}
fin.close(); 
cout<<"Count of-to-in file: "<<C<<endl;
}

Question 60:
Write a function in C++ to read and display the details of all the users whose membership type is ‘L’ or ‘M’ from a binary file “CLUB.DAT”. Assuming the binary file “CLUB.DAT” is containing objects of class CLUB, which is defined as follows: All India 2009

class CLUB
{
int Mno; 
char Mname[20]; //member name
char Type: //member type:L Life Member M Monthly Member G Guest
public:
void Register(); //function to enter the content
void Display();  //function to display all data members 
char *WhatType() {return Type;}

Answer:

void DisplayMember()
{
CLUB C; 
ifstream fin;
fin.open("CLUB.DAT",ios::binary);
while(fin.read((char*)&C,
sizeof(C)))
{
if(((strcmpi(C.whatType!),"L") ==0)||(strempi(C.whatType (), "M" )==0))) 
C.DisplayO;
}
fin. close();
}

Question 61:
Write a function COUNT_DO() in C++ to count the presence of a word ‘do’ in a text file “MEMO.TXT”. Delhi 2009
If the content of the file “MEMO.TXT” is as

I will do it, if you request me to do it 
It would have been done much earlier

The function COUNT_DO() will display the following message
Count of do in file: 2

Answer:

void C0UNT_D0()
{
ifstream fin!("MEM0.TXT"); 
char str[10]; 
int C = 0; 
while(!fin.eof)))
{
fin>>str;
if(strcmpi(str,"Do")== 0)
C++;
}
fin.close();
cout<<"Count of do in file:" <<C<<endl;
}

Question 62:
Write a function in C++ to read and display the details of all the users whose status is ‘A’ (i.e. Active) from a binary file “USER.DAT”. Assuming the binary file “USER.DAT” is containing objects of class USER, which is defined as follows: Delhi 2009

class USER 
{
 int Uid;
 char Uname[20]; //username
 char Status: // user type : A active I inactive
 public:
 void Register(); //function to enter the content
 void Show(); //function to display all data members
 char *GetStatus(){return Status;}
};

Answer:

void DisplayActive()
{
USER U;
ifstream fin;
fin.open("USER.DAT",ios::binary); 
while(fin.read!(char*)&U,sizeof(U))) 
{
if(strcmpi(U.Get status(),
"A”)—0)
U.Show();
}
fin. close();
}

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.