IIT Bombay
CS 101 Lab 9   Exercises on Text/Strings
Monday March 21st, 2011

Problem 1: 

 Implement the following functions:
 
 1.  int wordCount (char *filename);

    The function counts the no. of words in the text file identified the file name. A word is
    a string read in by statement fin >> str;

2. float averageWordLength (char *filename);

   returns the average length of words in the given file.
   Again, a word is a string returned by statement fin >> str;

3. int sentenceCount (char *filename);

   The function counts the no. of sentences in the text file identified the file name.
   For the purpose of this lab, whenever a word ends with a full stop character '.', we recognize
   a sentence.

4. float averageSentenceLength (char *filename);
   
    The function returns the av. length of sentences in the given text file.

5. int countFrequency (char *filename, string s);
or int countFrequency (char *filename, char *s);

   Return the no. of times the given string appears in the file.
   Use any one of the above two signatures.


Test these functions on text files.  A sample text file: sample


Problem 2:

Extract some text pages from files available here into text files.
Write a program to compare them based on some features that
you can extract only by directly using the above functions.
(e.g. you can compare on average sentence length, av. word length; usage
of articles "a", "an", "the"; usage of prepositions etc.)
 

Deadline: 11 pm.

Upload your cpp files, and also a README file that includes
some results that you obtained.


strings (string class and member functions compare, find, insert, replace, size, capacity)
files  (ifstream for reading, ofstream for writing)
Command line arguments to main (argv[1],argv[2] will hold your two file names)
c++ reference manual