I need help plz have spend almost 3 days trying to solve thi

I need help plz, have spend almost 3 days trying to solve this but no luck Use STL containers, iterators, algorithms, and (perhaps) lambdas, functions or function objects to write the two programs described below. Do not use any low-level C++ loops - this means while () … and for (...;...;...).... and even for (auto E: L) … Instead use copy() and for_each(). Ignore letter case differences by converting each word (both input and exclude words) into all lower case. Print the list of words with their respective frequencies to a file named frequency.txt. Use set, map, and lambda in your solution.

Details: (20 points) Define a word exclusion set containing words in a file stopwords.txt use this stopwords file.

(20 points) Store each word (that is not a stopword) in a map. Use the word for the map key and store the frequency of occurance as the map value. All punctuation has been removed from this input file, so your program need not handle punctuation.

(20 points) Write the words with their associated count (one word with its count per line, in ascending order by key) to the output file frequency.txt.

this is sample_doc.txt Computer programming often shortened to programming is a process that leads from an original formulation of a computing problem to executable computer programs Programming involves activities such as analysis developing understanding generating algorithms verification of requirements of algorithms including their correctness and resources consumption and implementation commonly referred to as coding of algorithms in a target programming language Source code is written in one or more programming languages The purpose of programming is to find a sequence of instructions that will automate performing a specific task or solving a given problem The process of programming thus often requires expertise in many different subjects including knowledge of the application domain specialized algorithms and formal logic

stopwords.txt a about above after again against all am an and any are aren\'t as at be because been before being below between both but by can\'t cannot could couldn\'t did didn\'t do does doesn\'t doing

Solution

Solution:

#include <iostream>
#include <map>
#include <fstream>
#include <string>
using namespace std;


//metod to print the map
template <class Key, class val> void StringPrintMap(map<Key, val> map)
{
    typedef std::map<Key, val>::iterator iterator;
    for (iterator cp = map.begin(); cp != map.end(); cp++)
        cout << cp->first << \": \" << cp->second << endl;
}

// main method for process the file
int main(void)
{
   // declare the variable and initialize the file name
    static const char* file_Name = \"data.txt\";

    // Map to store the word and its count.
    map<string, unsigned int> countofWords;
    {
        // read file:
        ifstream fileStream(file_Name);

        // Check file opening
        if (fileStream.is_open())
       {
            while (fileStream.good())
            {
                // Store the word from file
                string inpword;
                fileStream >> inpword;

                // check the existence
                if (countofWords.find(inpword) == countofWords.end())
                    // initialize count
                   countofWords[inpword] = 1;
                else
                   // Already exist then increase the count
                    countofWords[inpword]++;
            }
       }      
        else
        {
            cerr << \"Couldn\'t open the file.\" << endl;
            return EXIT_FAILURE;
        }

        // Print mapped words
        StringPrintMap(countofWords);
    }
    system(\"pause\");
    return EXIT_SUCCESS;
}

Result:

a: 1
about: 1
above: 1
after: 1
again: 1
against: 1
all: 1
am: 1
an: 1
and: 1
any: 1
are: 1
aren\'t: 1
as: 1
at: 1
be: 1
because: 1
been: 1
before: 1
being: 1
below: 1

I need help plz, have spend almost 3 days trying to solve this but no luck Use STL containers, iterators, algorithms, and (perhaps) lambdas, functions or functi
I need help plz, have spend almost 3 days trying to solve this but no luck Use STL containers, iterators, algorithms, and (perhaps) lambdas, functions or functi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site