Share

# 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 - CBSE (Science) Class 12 - Computer Science (C++)

#### Question

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.

Note:

•  The word TOWER should be an independent word
• Ignore type cases (i.e. lower/upper case)

Example:

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

#### Solution

void TOWER()
{
int count=0;
ifstream f("WRITEUP.TXT");
char s[20];
while (!f.eof())
{
f>>s;
if (strcmpi(s,"TOWER")==0)
count++;
}
cout<<count;
f.close();
}

Is there an error in this question or solution?

#### APPEARS IN

Solution 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 Concept: ifstream, ofstream, Classes.
S