Answer to Question #290386 in C++ for Umair

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.

1
Expert's answer
2022-01-25T08:01:17-0500


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment