File Handling: Count For His:2 Count For Her:1
File Handling: Count For His:2 Count For Her:1
File Handling: Count For His:2 Count For Her:1
1. WAF to copy the words not starting with vowel and second character as ‘F’ in a text file “PARA.TXT” from
“VOWEL .TXT”.
2. WAF in C++ to read a file “SPACE.DAT” and copy all the content into file “DOUBLE.DAT” with all the
sequence of consecutive blank spaces must be replaced by single space.
3. 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.
Pinky 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
4. Given a binary file ‘‘SPORTS.DAT’’ containing records of the following class:
class Player { char PNO[10]; //player number
char Name[20]; //Name of player
int rank; //rank of the player public:
Name Marks
Rohit 95
Surya 93
Ankit 93
shweta 99
roshni 96
fstream f;
f.open(“STUDENT.DAT”,ios:: binary|| ios::in);
student S;
f.read((char*)&S,sizeof(S));
f.seekg(2*sizeof(S));
S.Show();
f.read((char*)&S,sizeof(S));
cout<<”Rec:”<<F.tellg( )/ sizeof(S)<<endl;
S.Show();
25. Write function definition for show() in C++ to read text file STORY.TXT and display all such words which have the
alphabet i or I in the file.
26. Given the binary file ITEM.DAT, containing the records of the following structure:
class item{ int item_no; char item_name[20];
int stock;
public: int itmreturn() { return item_no;}};
Implement the function DelStock(), which delete a record of matching item_no entered through keyboard.
27. Write a function in C++ to read a text file “ YOURS .TXT “ and display each wordin reverse order.
Example: If value in text file is: Jack and Jill went up the hill
Output will be: kcaj dna llij tnew pu eht llih
28. Assume that a text file named “ALPHA.TXT” already contains some text written into it . But while writing into the file ,
the word “are” has been misspelled “aer” everywhere in the file . Write a function named Rectify () in c++ that reads
the file “ALPHA.TXT” and corrects the word “aer” .
29. Write a function in C++ to read the content of the text file “DELHI.TXT” and display all those lines on screen
which are either starting with ‘D’ or starting with ‘M’.
30. Write a function definition for JTOI( ) in C++ that would display the corrected version of entire content of the file
WORDS.TXT with all the alphabets ‘J’ to be displayed as an alphabet ‘I’ on screen.
31. Write a function in C++ to search for a room number (R_no) given by the user in an already existing binary file
“HOSPITAL.DAT”. Also display complete record of the R_no searched if found otherwise display a message “Not
found”.
class hospital { int R_no;
char P_name[30];
public :
void input( ) { gets (P_name); cin>>R_no; }
void output( ) { cout<<”Patient’s Name”<<P_nname<<endl;
cout<<”Room Number”<<R_no<<endl; }
intGetroom() {returnR_no; } };
32. Given a binary file EMPLOYEE.DAT containing records of the following type :
class Emp { char Ename[20], status ;
int Eid ;
public: void read();
void show();
char *getstatus() { return status ; }
void setstatus(char s) { status = s; }
int getid() { return id; } };
Write a function which changes the status of all Employee with previous status as ‘A’ to ‘B’ .
33.Write a function in C++ to search and display details, whose destination is “Chandigarh” from binary
file “Flight.Data”. Assuming the binary file is containing the objects of the following class:
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 input() { cin>>Fno>>; gets(From); get(To); }
void show( ) { cout<<Fno<< “:”<<From << “:” <<To<<endl; } };