MENU
Question -

Write a function CountYouMe ( ) in C+ + which reads the contents of a text file story.txt and counts the words You and Me (not case sensitive).
For example, 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 fil("story.txt");
 char word [80];
 int WC = 0, WM = 0;
 while (! fil.eof())
 {
 fil>>word;
 if ((strcmp WC++ ; (word, "You") = = 0)
 if (strcmp (word, "Me") = = 0) )
 WM++ ;
 }
 cout <<"count for you" << WC;
 cout <<"count for me" << WM;
 fil. close ( ) ;}

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×