Question #290386

Write a program, using functions only, with the following features.


1. Program reads paragraph(s) from the file and stores in a string.


2. Then program counts the occurrence of each word in the paragraph(s) and stores all


words with their number of occurrences.


3. If that word has appeared more than one time in whole string, itshould store the word


only once along its total number occurrences.


4. The output described in above (int part 3) must be stored in a new file.

Expert's answer



#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;


int main () {
	
	//Read a  paragraph from a text file called input
  string line;
  string paragraph = "";
  int i=0;
  ifstream myfile("input.txt");
  if (myfile.is_open())
  {
  while(!myfile.eof())
  {
    getline (myfile, line);
     cout << "line ["<<++i<<"]:" << line << endl;
     paragraph = paragraph + line;
     
	 }
  }
  
  
  //
    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS