Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help plz, have spend almost 3 days trying to solve this but no luck Use S

ID: 3773795 • Letter: I

Question

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(). See examples in lecture notes for Stream Iterator with Files.

Write a program that counts the frequency of occurrence of each word in the file sample_doc.txt Link while excluding certain common words. 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.

(40 points) Write another program that reads a sequence of integers from a file named rand_numbers.txt Link. It should put them in a vector, sort them in ascending order, write the odd ones, to a file named odd.txt, separated by a space and write the even ones to a file called even.txt each number on a line by itself. Note the numbers in the output files will each be in ascending order because you sorted the initial list of integers you put in a vector.

Note use ifstream and ofstream for creating I/O streams bound to name files and use stream iterators for reading and writing the named files.

this is rand_numbers.txt

76   -37   86   -72   -94   -69   29   0   53   -11   58   -3   57   -90   54   -68   19   -63   34   79   -22   -79   -98   -96   50   52   -56   -15   -30   89   -78   83   -97   -5   -41   99   16   -34   -76   45   46   -77   14   -57   47   -53   8   72   39   -42   96 -31   -25   60   -28   21   -86   31   -27   -74   30   81   87   5   -49   66   78   -8   -70   -93   -21   37   43   90   62   73   7   

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

Explanation / Answer

Solution for part 1

SOURCE CODE:

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
vector<string> stopword;
map<string,int> frequency;

void copyFromStopwordsFile(ifstream& stop)
{
   string temp="";
   if(stop>>temp)
   {
       stopword.push_back(temp);
       copyFromStopwordsFile(stop);
   }
   else
       return;
  
}

void copyFromsampledocFile(ifstream& samp)
{
   string temp="";
   if(samp>>temp)
   {
       if ( find(stopword.begin(), stopword.end(), temp) == stopword.end() )
       {
           if(frequency.count(temp)==0)
           {
               frequency[temp]=1;
           }
           else
           {
               int val=frequency.begin()->second;
               frequency.at(temp)=val+1;
           }
       }
      
       copyFromsampledocFile(samp);
   }
   else
       return;
  
}

int main()
{

   ofstream freq("frequency.txt");
   ifstream samp("sample_doc.txt");
   ifstream stop("stopwords.txt");
   copyFromStopwordsFile(stop);
   copyFromsampledocFile(samp);
   for (map<string,int>::iterator it=frequency.begin(); it!=frequency.end(); ++it)
   freq<<it->first<<" "<<it->second<<" ";
cout<<"Frequencies of the non-stop words has been successfully copied into file";
}

OUTPUT:

Frequencies of the non-stop words has been successfully copied into file

frequency.txt

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

Solution for part 2


SOURCE CODE:

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> numbers;
int loc=0;

void copyFromFile(ifstream& rand)
{
   int num=0;
   if(rand>>num)
   {
       numbers.push_back(num);
       copyFromFile(rand);
   }
   else
       return;
  
}

void copyIntoFile(ofstream& odd,ofstream& even)
{
   int num=0;
   if(loc<numbers.size())
   {
       num=numbers.at(loc++);
       if(num%2==0)
           even<<num<<" ";
       else
           odd<<num<<" ";
       copyIntoFile(odd,even);
   }
   else
       return;
  
}

void display (int i)
{
cout << ' ' << i;
}

int main()
{
   ofstream odd("odd.txt");
   ofstream even("even.txt");
   ifstream rand("rand_numbers.txt");
   copyFromFile(rand);
  
   cout<<" List of numbers before sorting ";
   for_each(numbers.begin(),numbers.end(),display);

   sort(numbers.begin(),numbers.end());
      
   cout<<" List of numbers after sorting ";
   for_each(numbers.begin(),numbers.end(),display);
  
cout<<" Starting the copying process into two files, odd.txt & even.txt..... ";
  
copyIntoFile(odd,even);
  
   cout<<" Copying completeted successfully";

}

OUTPUT:


List of numbers before sorting
76 -37 86 -72 -94 -69 29 0 53 -11 58 -3 57 -90 54 -68 19 -63 34 79 -22 -79 -98
-96 50 52 -56 -15 -30 89 -78 83 -97 -5 -41 99 16 -34 -76 45 46 -77 14 -57 47 -53
8 72 39 -42 96 -31 -25 60 -28 21 -86 31 -27 -74 30 81 87 5 -49 66 78 -8 -70 -93
-21 37 43 90 62 73 7

List of numbers after sorting
-98 -97 -96 -94 -93 -90 -86 -79 -78 -77 -76 -74 -72 -70 -69 -68 -63 -57 -56 -53
-49 -42 -41 -37 -34 -31 -30 -28 -27 -25 -22 -21 -15 -11 -8 -5 -3 0 5 7 8 14 16
19 21 29 30 31 34 37 39 43 45 46 47 50 52 53 54 57 58 60 62 66 72 73 76 78 79 81
83 86 87 89 90 96 99

Starting the copying process into two files, odd.txt & even.txt.....

Copying completeted successfully

odd.txt

-97 -93 -79 -77 -69 -63 -57 -53 -49 -41 -37 -31 -27 -25 -21 -15 -11 -5 -3 5 7 19 21 29 31 37 39 43 45 47 53 57 73 79 81 83 87 89 99

even.txt

-98 -96 -94 -90 -86 -78 -76 -74 -72 -70 -68 -56 -42 -34 -30 -28 -22 -8 0 8 14 16 30 34 46 50 52 54 58 60 62 66 72 76 78 86 90 96

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote