Difference: Vector2CPP (1 vs. 3)

Revision 32018-04-10 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="Fall2017"

Strings, Vectors and Classes

Line: 37 to 37
  WordCount (); WordCount(string W); WordCount(string W, int i);
Changed:
<
<
Inc();
>
>
void Inc();
  int getCount(); string getWord(); }

Revision 22017-11-02 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="Fall2017"

Strings, Vectors and Classes

Line: 40 to 39
  WordCount(string W, int i); Inc(); int getCount();
Changed:
<
<
string getString();
>
>
string getWord();
 } %ENDCODE%

Revision 12017-11-02 - JimSkon

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Fall2017"

Strings, Vectors and Classes

Goal: Count the number if unique words in a series of lines.

1. Create a function to split a line of text into a vector of strings (words)

<-- SyntaxHighlightingPlugin -->
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
    string s = "Somewhere down the road";
    istringstream iss(s);

    do
    {
        string subs;
        iss >> subs;
        cout << "Substring: " << subs << endl;
    } while (iss);
<-- end SyntaxHighlightingPlugin -->

2. Create an object that stores words, and counts

<-- SyntaxHighlightingPlugin -->
class WordCount {
private:
    string word;
    int count;
public:
    WordCount ();
    WordCount(string W);
    WordCount(string W, int i);
    Inc();
    int getCount();
    string getString();
}
<-- end SyntaxHighlightingPlugin -->

3. Make a vector of WordCount.

4. Count the words.

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback