answersLogoWhite

0

#include<iostream>

#include<algorithm>

#include<string>

#include<list>

struct node {

std::string m_word;

unsigned m_freq;

node (std::string word): m_word (word), m_freq (1) {}

};

struct list {

friend std::ostream& operator<<(std::ostream& os, list& lst);

std::list<node> m_list;

list (std::string text)

{

// delimiters: space, comma, full-stop, tab, newline & null characters

std::string delimits = " ,.\t\n\0";

unsigned start = 0, end = 0;

while (end<text.size())

{

// move start position to the start of the next word

start = end;

while (start<text.size() && delimits.find (text[start]) != std::string::npos)

++start;

// move end position to the first delimiter after the start position

end = start + 1;

while (end<text.size() && delimits.find (text[end]) m_list.end())

m_list.push_back (node(word));

else

++(*n).m_freq;

}

};

std::ostream& operator<<(std::ostream& os, list& lst)

{

for (std::list<node>::iterator i=lst.m_list.begin(); i!=lst.m_list.end(); ++i)

{

// dereference the node

node& n = *i;

os << n.m_word << " (" << n.m_freq << ")\n";

}

return (os);

}

int main()

{

std::string text = "We shall fight in France, we shall fight on the"

" seas and oceans, we shall fight with growing confidence and"

" growing strength in the air, we shall defend our island,"

" whatever the cost may be.";

list table (text);

std::cout << "Text: \n"" << text << ""\n" << std::endl;

std::cout << "Unique words (frequency)\n" << std::endl;

std::cout << table << std::endl;

}

Output:

Text:

"We shall fight in France, we shall fight on the seas and oceans, we shall fight

with growing confidence and growing strength in the air, we shall defend our

island, whatever the cost may be."

Unique words (frequency)

we (4)

shall (4)

fight (3)

in (2)

france (1)

on (1)

the (3)

seas (1)

and (2)

oceans (1)

with (1)

growing (2)

confidence (1)

strength (1)

air (1)

defend (1)

our (1)

island (1)

whatever (1)

cost (1)

may (1)

be (1)

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is a sentence with the word sustainability?

Based on the data given, what is the sustainability of your program?


Will the serial number identify the caliber?

No. Serial numbers aer NOT UNIQUE. They are intended to be unique to a given make and model- but a gun can be rebarreled to a different caliber.


Can you identify all of the chirality centers in the given structure?

Chirality centers are carbon atoms that are bonded to four different groups. In the given structure, you can identify chirality centers by looking for carbon atoms with four unique groups attached to them.


Can you give a sentence that incldes the word grant?

A grant was given to the program amounting to 120,000 dollars.


Who works with the squadron commanders to identify that should be given priority to achieve an overall balanced program?

Resource Advisors (RAs)


Who works with squadron commander to identify requirements that should be given priority to achieve an overall balanced program?

Resource Advisors (RAs)


Who works with the squadron commander to identify requirements that should be given priority to achieve an overall balance program?

Resource Advisors (RAs)


Who works with the squadron commander to identify requirements that should be given priority to achieve an overall balanced program?

Resource Advisors (RAs)


Write a C program to extract a given word from a file?

program to extract a given word from a file


Algorithms to the given c plus plus programs?

The question is impossible to answer. You cannot determine an algorithm from a given program if the program is not actually given in the question. Please place the program in the discussion section.


Set of data or program instructions that has been given a name?

file is a set of data and program that has been given a name


What part of an onion cell can you identify?

Given a good microscope I can identify all parts of an onion cell.