1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
frutty [35]
3 years ago
8

c++ Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins wi

th an integer indicating the number of words that follow. Assume that the list will always contain less than 20 words.
Computers and Technology
1 answer:
Margaret [11]3 years ago
4 0

Answer:

The following are the program in the C++ Programming Language:

#include <iostream> //header file

#include <string>  //header file

#include <vector>  //header file

//name space

using namespace std;

//main function

int main() {

  vector<string> word; //set variable

  vector<int> c;  //set variable

  int s, counts = 0; //set variable

  string strng;  //set variable

  cout<<"Enter the size of string: "; //print message

  cin >> s; //get input

  cout<<"Enter the string: "; //print message

  for(int i = 0; i < s; ++i) {  //set for loop

     cin >> strng; //get input

     word.push_back(strng);

  }

  for(int i = 0; i < s; ++i) { //set for loop

         counts = 0;

         for(int j = 0;j<word.size();j++){ //set for loop

       if(word[j] == word[i]){ //set if statement

          counts++; //increament in counts

       }        

     }

      c.push_back(counts);

  }

  for(int i = 0; i < s; ++i) {

      cout << word[i] << " " << c[i] << endl;//print result

  }

  return 0;

}

<u>Output</u>:

Enter the size of string: 2

Enter the string: hello  sir

hello 1

sir 1

Explanation:

Here, we define three header files <iostream>, <String>, <vector> and namespace "std" after that we define main() method inside it.

  • Then, we set two vector type variables first one is string variable "word" and the second one is integer variable "c".
  • Then we set two integer variable "s" and "counts" and variable "counts" assign to 0.
  • Then, we get input from the user in variable "s" for the length of the loop.
  • Then, we set for the loop inside it, we get input in the variable "strng" from the user.
  • Then, we set the for loop for count the string repetition if any word comes again in the string then the value of count will increase.
  • Finally, we set for a loop to print the result.
You might be interested in
etwork behavior analysis system __________ sensors are typically intended for network perimeter use, so they are deployed in clo
jeka94

Answer:

"Inline" is the correct answer.

Explanation:

  • Network behavior analysis (NBA)  or Analysis of network activity seems to be the technique to observe traffic trends that aren't groups or sets throughout the cable network's everyday traffic.
  • Simplest terms, this is the organization's effort to define network anomalies outside pure congested traffic expect a seamless.

So that the above is the correct answer.

6 0
3 years ago
Suzanne is following a fad diet. She has started to experience low energy during her workouts, and on a recent trip to the docto
Nastasia [14]

Answer:

Hi mate....

Explanation:

This is ur answer....

<em>-</em><em>-</em><em>></em><em> </em><em>Suzanne just facing low carbohydrates</em>....

hope it helps you,

mark me as the brainliest pls....

Follow me!

5 0
2 years ago
Read 2 more answers
Jake is preparing his resume. He is applying for the position of iOS application developer at a large software company. He wants
gavmur [86]

Answer:

C. Modern Programming Language Skills

Explanation:

4 0
2 years ago
Identify the data link trailer blocker
IRINA_888 [86]
What are ur possible answers
7 0
3 years ago
Greedy Algorithm Design
Alik [6]

Answer:

The algorithm is as follows:

1. Start

2. Get the number of items (n)

3. Get the current price of the n items (a1, a2..... an)

4. Get the possible hiked price of the n items (b1, b2..... bn)

5. Calculate the difference between the current and hiked prices for each item i.e. d_i = b_i - a_i

6. Sort the differences in descending order (i.e. from the greatest to the least)

7. Buy items in this order of difference

8. Stop

Explanation:

The algorithm is self-explanatory; however, what it does is that:

It takes a list of the current price of items (say list a)

E.g: a = [100, 150, 160]

Then take a list of the hiked price of the items (say list b)

E.g: b = [110, 180, 165]

Next, it calculates the difference (d) between corresponding prices d_i = b_i - a_i

d = [(110 - 100),(180-150),(165-160)]

d = [10,30,5]

Sort the difference from greatest to lowest (as the difference is sorted, lists a and b are also sorted)

d = [30,10,5]

a = [150, 100, 160]

b = [180, 110, 165]

If there is no hike up to item k, the couple would have saved (i = 1 to d[k-1])

Assume k = 3

The couple would have saved for 2 item

Savings = d[1] + d[2]

Savings = 30 +10

Savings = 40

The saved amount will then be added to the kth item in list a i.e. a[k](in this case k = 3) in order to buy b[k]

Using the assumed value of k

a[k] = a[3]

a[3] = 160

b[3] = 165

Add the saved amount (40) to a[3]

New\ Amount = 40 + 160

New\ Amount = 200

This new amount can then be used to buy b[3] i.e. 165, then they save the change for subsequent items

8 0
3 years ago
Other questions:
  • The condition, ____, entered in the criteria row of a long text field in a query window would retrieve all records where the lon
    8·1 answer
  • John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
    12·1 answer
  • The computer component that makes sure that instructions are decoded and executed properly is the ___________.
    11·2 answers
  • Hen using presentation software, what do you do when you "compose a slide"?
    5·1 answer
  • Which of the following is true about images that are arranged in a collumn
    9·1 answer
  • When using a function to preform a calculation how would you select the range of numbers to use
    13·1 answer
  • Micro sleep is when you ____.
    11·2 answers
  • 9. Select the correct answer.
    6·1 answer
  • Are there any Potential Dangers in Artificial Intelligence?
    11·2 answers
  • Windows 8 uses a(n) ________ account for easy access and storage of online files.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!