### Word count and strings

Assignment: https://imgur.com/a/SU45W

Skeleton: https://imgur.com/a/4da0L

Its a group project and i'm in charge of Wc (word count)

I want a simple explanation of what needs to be done, where to start and a few guide lines.

I honestly don't get what I'm suppose to do. Edit the skeleton so that whenever I echo or specify a file it would display the WC info?
Last edited on
You are a member of a team. The team must work together.

Your program "wc" reads standard input. When the input ends, the program must print some statistics.

How many characters were in the input?
How many lines were in the input?
How many words were in the input?
How many unique words were in the input?

How should you read that you are able to count those?
I very briefly looked at the problem description. These are some general guidelines.
1: Decide what a word is. To do this you need to determine what is a non-word, and you must terminate on non-words.
2: Note that once a 'word' has been discovered, the next issue is to discover the start of the next word.
b. <word> count characters in word.
c. <word terminator> recognize end of a word.

I have left all the details out. This is a problem that you have to solve. The general 'wc' counts characters, words, and lines. You have to determine what is a countable character, word, and line.
From: https://www.freebsd.org/cgi/man.cgi?query=wc&apropos=0&sektion=0&manpath=FreeBSD+11.1-RELEASE+and+Ports&arch=default&format=html

1. "A line is defined as a string of characters delimited by a <newline> character"

To read one line from stdin, use std::string line ; std::getline( std::cin, line ) ;
The number of characters which were read to extract the line would be line.size() + 1
(+1 is for the <newline> character which was extracted and discarded.)

Keep reading lines in a loop till input fails while( std::getline( std::cin, line ) ) { /* process line */ }

2. "A word is defined as a string of characters delimited by white space characters."

To extract the words from the line, use an input stringstream. See: https://stackoverflow.com/a/656868

3. for the --uwords option, add every word extracted to a set std::set<std::string> unique_words ;
The number of unique words would be size of the set unique_words.size() at the end of the program.
Note that the skeleton already has #include <set>
This is what I have added so far,
 ``12345678910111213141516`` ``````/* TODO: write me... */ string line; int linescount = 0; int wordcount = 0; int bytescount = 0; int longestline = 0; int uniquewords = 0; while (getline(cin, line)) linescount++; line.size(); cout << " " << linescount << " " << wordcount << " " << bytescount << endl;``````

It works so far but I don't know the functions like getline but for words, bytes etc.
JLBorges did give quite good hints.

If you don't know what, for example, a "std::set" is, you can look it up from the reference documentation: http://www.cplusplus.com/reference/