Write a program that reads a list of words. Then, the program outputs those words and their frequencies. If the input is 5 hey hi Mark hi mark (the first number indicates the number of words that follow), 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 wordsList, string currWord)

Answers

Answer 1
Answer:

Answer:

/ declare the necessary header files.

#include <iostream>

#include <string>

#include <vector>

using namespace std;

// declare the main function.

int main()

{

// declare a vector.

vector<string> words;

vector<int> counts;

// declare variables.

int size;

string str;

cin >> size;

// start the for loop.

for(int i = 0; i < size; ++i)

{

// input string.

cin >> str;

words.push_back(str);

}

// start the for loop.

for(int i = 0; i < size; ++i)

{

int count = 0;

// start the for loop.

for(int j = 0; j < words.size(); ++j)

{

// check the condition.

if(words[j] == words[i])

{

count++;

}

}

counts.push_back(count);

}

// start the for loop.

for(int i = 0; i < size; ++i)

{

// display result on console.

cout << words[i] << "\t" << counts[i] << endl;

}

return 0;

}

Explanation:


Related Questions

What do you think is the single greatest physical threat to information systems? Fire? Hurricanes? Sabotage? Terrorism? Something else? Discuss this question and provide support for your answer.
Which type of error occurred in the following lines of code? >>> print(9 / 0)Traceback (most recent call last): File " ", line 1, in 9/0ZeroDivisionError: division by zeroAnswer choices:reserved word errorlogical errorexceptionsyntax error
Describe how a web browser and web server work together to send a web page to a user
(1) Prompt the user to enter a string of their choosing. Output the string. Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. (2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. Use a for loop in this function for practice. (2 pts) (3) In main(), call the GetNumOfCharacters() function and then output the returned result. (1 pt) (4) Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the OutputWithoutWhitespace() function in main(). (2 pts) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. Number of characters: 46 String with no whitespace: The only thing we have to fear is fear itself.
#Imagine you're writing a program to check if a person is #available at a certain time. # #To do this, you want to write a function called #check_availability. check_availability will have two #parameters: a list of instances of the Meeting class, and #proposed_time, a particular date and time. # #check_availability should return True (meaning the person #is available) if there are no instances of Meeting that #conflict with the proposed_time. In other words, it should #return False if proposed_time is between the start_time and #end_time for any meeting in the list of meetings. # #The Meeting class is defined below. It has two attributes: #start_time and end_time. start_time is an instance of the #datetime class showing when the meeting starts, and #end_time is an instance of the datetime class indicating #when the meeting ends. # #Hint: Instances of the datetime have at least six #attributes: year, month, day, hour, minute, and second. # #Hint 2: Comparison operators work with instances of the #datetime class. time_1 < time_2 will be True if time_1 is #earlier than time_2, and False otherwise. # #You should not assume that the list is sorted. #Here is our definition of the Meeting class: from datetime import datetime class Meeting: def __init__(self, start_time, end_time): self.start_time = start_time self.end_time = end_time #Write your function here! #Below are some lines of code that will test your function. #You can change the value of the variable(s) to test your #function with different inputs. # #If your function works correctly, this will originally #print: True, then False meetings = [Meeting(datetime(2018, 8, 1, 9, 0, 0), datetime(2018, 8, 1, 11, 0, 0)), Meeting(datetime(2018, 8, 1, 15, 0, 0), datetime(2018, 8, 1, 16, 0, 0)), Meeting(datetime(2018, 8, 2, 9, 0, 0), datetime(2018, 8, 2, 10, 0, 0))] print(check_availability(meetings, datetime(2018, 8, 1, 12, 0, 0))) print(check_availability(meetings, datetime(2018, 8, 1, 10, 0, 0)))

Give an example of a function from N to N that is:______.a) one-to-one but not onto
b) onto but not one-to-one
c) neither one-to-one nor onto

Answers

Answer:

Let f be a function

a) f(n) = n²

b) f(n) = n/2

c) f(n) = 0

Explanation:

a) f(n) = n²

This function is one-to-one function because the square of two different or distinct natural numbers cannot be equal.

Let a and b are two elements both belong to N i.e. a ∈ N and b ∈ N. Then:

                                f(a) = f(b) ⇒ a² = b² ⇒ a = b

The function f(n)= n² is not an onto function because not every natural number is a square of a natural number. This means that there is no other natural number that can be squared to result in that natural number.  For example 2 is a natural numbers but not a perfect square and also 24 is a natural number but not a perfect square.

b) f(n) = n/2

The above function example is an onto function because every natural number, lets say n is a natural number that belongs to N, is the image of 2n. For example:

                                f(2n) = [2n/2] = n

The above function is not one-to-one function because there are certain different natural numbers that have the same value or image. For example:

When the value of n=1, then    

                                   n/2 = [1/2] = [0.5] = 1

When the value of n=2 then

                                    n/2 = [2/2] = [1] = 1

c) f(n) = 0

The above function is neither one-to-one nor onto. In order to depict that a function is not one-to-one there should be two elements in N having same image and the above example is not one to one because every integer has the same image.  The above function example is also not an onto function because every positive integer is not an image of any natural number.

Implement the logic function ( , , ) (0,4,5) f a b c m =∑ in 4 different ways. You have available 3to-8 decoders with active high (AH) or active low (AL) outputs and OR, AND, NOR and NAND gates with as many inputs as needed. In every case clearly indicate which is the Most Significant bit (MSb) and which is the Least Significant bit (LSb) of the decoder input.

Answers

Answer:

See explaination

Explanation:

Taking a look at the The Logic function, which states that an output action will become TRUE if either one “OR” more events are TRUE, but the order at which they occur is unimportant as it does not affect the final result. For example, A + B = B + A.

Alternatively the Most significant bit which is also known as the alt bit, high bit, meta bit, or senior bit, the most significant bit is the highest bit in binary.

See the attached file for those detailed logic functions designed with relation to the questions asked.

Select the correct answer. Which decimal number is equivalent to this binary number? 11111011

Answers

The decimal number which is equivalent to binary number 11111011 is 251.

Binary numbers are base-2 numbers, which means they are composed of only two digits: 0 and 1.

Each digit in a binarynumber represents a power of 2, starting from the rightmost digit.

The rightmost digit represents 2⁰ (which is 1), the next digit represents 2¹(which is 2), the next represents 2² (which is 4), and so on.

Given the binary number 11111011:

1 × 2⁷ + 1 × 2⁶ + 1 × 2⁵ + 1 × 2⁴ + 1 × 2³ + 0 × 2² + 1 × 2¹ + 1 × 2⁰

Simplifying each term:

128 + 64 + 32 + 16 + 8 + 0 + 2 + 1

= 251

Hence, 251 is the decimalnumber which is equivalent to binary number 11111011.

To learn more on Binary numbers click here:

brainly.com/question/31102086

#SPJ3

Answer:

251

Explanation:

On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows: Pocket 0 is green. For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red. For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets 29 through 36, the odd-numbered pockets are black and the even-numbered pockets are red. Write a program that asks the user to enter a pocket number and displays whether the pocket is green, red, or black. The program should display an error message if the user enters a number that is outside the range of 0 through 36.

Answers

Answer:

pkt = int(input("Pocket Number: "))

if pkt == 0:

   print("Green")

elif pkt >= 1 and pkt <=10:

   if pkt%2 == 0:

       print("Black")

   else:

       print("Red")

elif pkt >= 11 and pkt <=18:

   if pkt%2 == 0:

       print("Red")

   else:

       print("Black")

elif pkt >= 19 and pkt <=28:

   if pkt%2 == 0:

       print("Black")

   else:

       print("Red")

elif pkt >= 29 and pkt <=36:

   if pkt%2 == 0:

       print("Red")

   else:

       print("Black")

else:

   print("Error")

Explanation:

The program was written in Python and the line by line explanation is as follows;

This prompts user for pocket number

pkt = int(input("Pocket Number: "))

This prints green if the pocket number is 0

if pkt == 0:

   print("Green")

If pocket number is between 1 and 10 (inclusive)

elif pkt >= 1 and pkt <=10:

This prints black if packet number is even

   if pkt%2 == 0:

       print("Black")

Prints red, if otherwise

   else:

       print("Red")

If pocket number is between 11 and 18 (inclusive)

elif pkt >= 11 and pkt <=18:

This prints red if packet number is even

   if pkt%2 == 0:

       print("Red")

Prints black, if otherwise

   else:

       print("Black")

If pocket number is between 19 and 28 (inclusive)

elif pkt >= 19 and pkt <=28:

This prints black if packet number is even

   if pkt%2 == 0:

       print("Black")

Prints red, if otherwise

   else:

       print("Red")

If pocket number is between 29 and 36 (inclusive)

elif pkt >= 29 and pkt <=36:

This prints red if packet number is even

   if pkt%2 == 0:

       print("Red")

Prints black, if otherwise

   else:

       print("Black")

Prints error if input is out of range

else:

   print("Error")

Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.

Answers

Answer:

int main()

{

   int A1= {5,3,4,8,9,0,7};

   int SArri1 = sizeof(A1);

  printf("Original array: ");

   

   for (int i=0; i < SArri1;i++)  

   printf("", A1[i] );

   

   int i, sum = 20, n= 0;

   printf("\nArray pairs whose sum equal to 20: ");

   

   for (int i=0; i<SArri1; i++)

       for (int j=i+1; j<SArri1; j++)

           if (A1[i]+A1[j] == sum)

             {

              Printf(“\n”, array1[i])

Printf(“,”,array1[j]);

               n++;

             }

 

  printf("\nNumber of pairs whose sum equal to 20: ",n)

   return 0;

}

Explanation:

First of all, you should create the array of integers, and put random numbers. Then you have to save in a constant the size of the array (in this  code is called SArr1) With a for you can print all the numbers that are on the array because then you will print all array pairs whose sum is equal to  a specified numer. in this code we are going to use 20.

then with a condition (if) you are going to compare one of number of the array with all the others and check if its equal to 20. If yes, it going to print the numbers that answer to that condition and it's going to add +1 to the variable n (for this you will need to use two bucles for)

Then you can print the number of pairs whose sum is equal to 20 by printing n

Using your choice of pseudocode, C# or java, define a class for a Pig. A Pig object should have three attributes: a name, an age, and weight. Your class should have (i) a constructor that takes three arguments and copies them to the attributes; (ii) setters (mutators) and getter accessors) or properties (C#) for the attributes; (iii) a display method to display the Pig's attributes on screen; and (iv) a main() method that creates a Pig object, assigns values to its attributes, and displays them by calling the display method.

Answers

Answer:

Following are the code to this question:

public class Pig //Defining class Pig

{

private String name; //Defining string variable name

private int age; // Defining integer variable age

private double weight; // Defining double variable weight

Pig (String name, int age, double weight)  //Defining parameterized constructor  

{

super(); //using super key

this.name = name; //holding value in name variable

this.age = age;  // holding value in age variable

this.weight = weight; // holding value in weight variable

}

String getName() //Defining method getName

{

return name; //return name value

}

void setName(String name) // Defining method setName    

{

this.name = name; //hold name value

}

int getAge() // Defining method getAge

{

return age; //return value

}

void setAge(int age) // Defining method setAge  

{

this.age = age; // hold age value

}

double getWeight()  //Defining method getWeight

{

return weight; //return weight value

}

void setWeight(double weight) //Defining method setWeight  

{

this.weight = weight; //hold weight value

}

void display() //Defining method display

{

System.out.println("Name:" + name + " Age:" + age + " Weight:" + weight); //print value

}

public static void main(String[] ar) //Defining main method

{

Pig onc = new Pig("Jig",5,14.5); //creating class object and called parameterized constructor  

onc.display();//calling display method

}

}

Output:

please find the attachment.

Explanation:

In the given java program, a class "Pig" is declared, in which three name, age, and weight is defined which differs in datatypes, in the next step, parameterized constructor, get and set method, and display method declared, which can be described as follows:

  • In the parameterized constructor, uses super and this keyword to call and holds parameter value.  
  • In the get method three methods "getName, getAge, and getWeight" are defined, that return method values, and the set method "setName, setAge, and setWeight" uses this keyword to hold value in its variables.
  • The display method is used to print all method store values by its variables name.
  • Inside the main method, class object "onc" is created, which stores the value in it and calls the display method that print value with a message.