Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with an integer indicating the number of words that follow.Ex: If the input is:5 hey hi Mark hi markthe output is:hey 1 hi 2 Mark 1 hi 2 mark 1Hint: Use two vectors, one for the strings, another for the frequencies.Your program must define and use the following function:int GetFrequencyOfWord(vector<string> wordsList, string currWord)#include <iostream>#include <vector> #include <string>using namespace std;/* Define your function here */int main() {/* Type your code here */return 0;}Please help me with this problem using c++.

Question
Asked Nov 27, 2019

Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with an integer indicating the number of words that follow.

Ex: If the input is:

5 hey hi Mark hi mark

the output is:

hey 1 hi 2 Mark 1 hi 2 mark 1

Hint: Use two vectors, one for the strings, another for the frequencies.

Your program must define and use the following function:
int GetFrequencyOfWord(vector<string> wordsList, string currWord)

#include <iostream>
#include <vector>
#include <string>
using namespace std;

/* Define your function here */

int main() {
/* Type your code here */

return 0;
}

Please help me with this problem using c++.

check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1
  • In main all the variable and vector declared.
  • push_back() function is used to insert the words in vector.
  • at() function is used to find current word.
  • In GetFrequencyOfWord() function, compare each word in vector with current word and counting the frequency.
Step 2

Program:

//header file

#include <iostream>

#include <vector>

#include <string>

//namespace inclusion

using namespace std;

//function GetFrequencyOfWord

int GetFrequencyOfWord (vector<string> wordsList, string currWord) {

  //declare variable count

            int count = 0;  

            // computing frequency

            for (int itr = 0; itr < wordsList.size(); itr++) {

                        if (wordsList.at(itr) == currWord) {

                                    count = count + 1;

                        }

            }

  //retuning count in main

            return count;

}

int main() {

            int numberOfWords = 0;

  &nbs...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: The Java program and the program plan to calculate the average of the elements of three rows of a 2-...

question_answer

Q: In C++, I have seen this line of code: while(cin.get() != '\n'); What does this mean/do?

A: ⦁ Start from cin.get() method, get() is a method which is called and which has inbuilt one argument ...

question_answer

Q: Given the following business rules, define the relationships between entities and identify cardinali...

A: Entity-Relationship (ER) diagram:The following ER diagram defines the cardinalities and relationship...

question_answer

Q: If originally x = 4, y = 0, and z = 2, which is the value of x, y and z after executing the followin...

A: Code(in Java)-class Main{            public static void main(String[] args)            {            ...

question_answer

Q: C++ program IF NOT COMFORTABLE WITH CLASSES,I WOULD START WITH DEFINING THE CLASS WITH ONE constru...

A: The implementation for the given criteria is as follows,File name: “student2.h”#include&lt;iostream&...

question_answer

Q: What are the SQL query commands to create the tables (attached) with appropriate attributes and data...

A: Primary key:A primary key, also referred to as a primary keyword, is a key in a relational database ...

question_answer

Q: Is Amazon Web Services an enterprise application integration (EAI) system?

A: “Yes”, Amazon Web Services (AWS) provides many default connectors to provide integration of many app...

question_answer

Q: If a non-key column determines a key column, which normal form is violated?A) 1NFB) 2NFC) 3NFD) BCNF

A: BCNF:Boyce – Codd Normal Form (BCNF) is based on functional dependencies that in a relationship all ...

question_answer

Q: A contact list is a place where you can store a specific contact with other associated information s...

A: The below given C++ program will obey the following rubrics:Importing essential header files.Definin...