Can you compelete the functions ?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Can you compelete the functions ?

 

#include <iostream>

#include <map>

#include <string>

 

 

// So we don't have to type "std::" everywhere...

using namespace std;

 

 

string processWord(string word);

void processText(map<string, int>& wordCounts);

void outputWordsByCount(map<string, int>& wordCounts);

 

 

int main()

{

  map<string, int> wordCounts;

 

  // Process the text on console-input, using the skip-list.

  processText(wordCounts);

 

  // Finally, output the word-list and the associated counts.

  outputWordsByCount(wordCounts);

}

 

 

/*

 * This helper-function converts a word to all lower-case, and then removes

 * any leading and/or trailing punctuation.

 *

 * Parameters:

 *   word    The word to process.  It is passed by-value so that it can be

 *           manipulated within the function without affecting the caller.

 *

 * Return value:

 *   The word after all leading and trailing punctuation have been removed.

 *   Of course, if the word is entirely punctuation (e.g. "--") then the result

 *   may be an empty string object (containing "").

 */

string processWord(string word)

{

  /*****************************************/

  /* TODO:  Your implementation goes here! */

  /*****************************************/

}

 

 

void processText(map<string, int>& wordCounts)

{

  /*****************************************/

  /* TODO:  Your implementation goes here! */

  /*****************************************/

}

 

 

/*

 * This helper-function outputs the generated word-list in descending order

 * of count.  The function uses an STL associative container to sort the words

 * by how many times they appear.  Because multiple words can have the same

 * counts, a multimap is used.

 */

void outputWordsByCount(map<string, int>& wordCounts)

{

  multimap<int, string, greater<int> > sortByCount;

  map<string, int>::const_iterator wIter;

 

  for (wIter = wordCounts.begin(); wIter != wordCounts.end(); wIter++)

    sortByCount.insert(pair<int, string>(wIter->second, wIter->first));

 

  multimap<int, string>::const_iterator cIter;

  for (cIter = sortByCount.begin(); cIter != sortByCount.end(); cIter++)

    cout << cIter->second << "\t" << cIter->first << endl;

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education