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
Taya2010 [7]
2 years ago
11

Word frequencies - functions

Computers and Technology
1 answer:
Nuetrik [128]2 years ago
5 0

Answer:

#include <iostream>

#include <vector>

#include <iomanip>

#include <string.h>

#include <string>

#include <algorithm>

using namespace std;

bool strEqual(const string& str1, const string& str2)

{

 //check each characters by case insensitive  

 return std::equal(str1.begin(), str1.end(),

                     str2.begin(), str2.end(),

                     [](char str1, char str2) {

                         return tolower(str1) == tolower(str2);

                     });

}

unsigned GetWordFrequency(vector<string>& vec,const string& str)

{

 //return the number of occurrences of the search word in the

 unsigned res=0;//the numbers of occurences

 for(auto itr:vec)

   {

     if(strEqual(itr,str))

       res++;

   }

 return res;

}

int main()

{

 int size=0;

 cin>>size;

 vector<string>vec;

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

   {

     string str;

     cin>>str;

     vec.push_back(str);

   }

   cout<<"Output:"<<endl;

 for(auto itr: vec)

   {

     cout<<itr<<" - "<<GetWordFrequency(vec,itr)<<endl;

   }

 return 0;

}

Explanation:

You might be interested in
The Account class contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and a
melamori03 [73]

Answer:

I've updated the Account class as per the instructions. The instructions mention "the constructor for this class creates a random account number" although I didn't find where that was. As a result, I created a simple method to generates the account number (located at the bottom of the class). Be sure you understand the changes (highlighted in yellow) and feel free to ask follow-up questions:

Explanation:

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

// Account.java

//

// A bank account class with methods to deposit to, withdraw from,

// change the name on, and get a String representation

// of the account.

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

import java.util.Random;   // Used for Random # generator

public class Account

{

      private double balance;

  private String name;

     private long acctNum;

      //----------------------------------------------

 //Constructor -- initializes balance, owner, and account number

  //----------------------------------------------

 public Account(double initBal, String owner, long number)

{

        balance = initBal;

               name = owner;

            acctNum = number;

}

// !!!!!! New Constructor !!!!!!

public Account(double initBal, String owner)

     {

        balance = initBal;

               name = owner;

            acctNum = generateAccountNumber();

       }

  // !!!!!! New Constructor !!!!!!

 public Account(String owner)

     {

        balance = 0;

             name = owner;

            acctNum = generateAccountNumber();

       }

   //----------------------------------------------

 // Checks to see if balance is sufficient for withdrawal.

// If so, decrements balance by amount; if not, prints message.

  //----------------------------------------------

 public void withdraw(double amount)

      {

        if (balance >= amount)

                balance -= amount;

               else

                     System.out.println("Insufficient funds");

}

 // !!!!!! New withdraw() method !!!!!!

   public void withdraw(double amount, double fee)

  {

        double amountWithFee = amount + fee;

               if (balance >= amountWithFee)

                 balance -= amountWithFee;

        else

                     System.out.println("Insufficient funds");

}

   //----------------------------------------------

 // Adds deposit amount to balance.

       //----------------------------------------------

 public void deposit(double amount)

       {

        balance += amount;

       }

  //----------------------------------------------

 // Returns balance.

      //----------------------------------------------

 public double getBalance()

       {

        return balance;

  }

    //----------------------------------------------

 // Returns a string containing the name, account number, and balance.

    //----------------------------------------------

 public String toString()

 {

        return "Name:" + name +

          "\nAccount Number: " + acctNum +

         "\nBalance: " + balance;

 }

 // !!!! NEW PRIVATE HELPER METHOD TO GENERATE ACCOUNT NUMBERS !!!!!

//-------------------------------------------------------

// Returns a random account number between 10000 - 99999

 //--------------------------------------------------------

       private long generateAccountNumber()

     {

        Random r = new Random();        // Seed the random number genertor with the system time

         return 10000 + r.nextInt(89999);        // .nextInt(89999) will return a value between 0 and 89999)

      }

}

8 0
4 years ago
U GET BRAINLIEST HELP PLZ
Art [367]
BOTH OF THEM ARE C : )
3 0
3 years ago
One way to describe the note-taking tool eNotes is to call it an<br> Someone help ._.
vagabundo [1.1K]

Answer:

Electronic notebook

5 0
4 years ago
Read 2 more answers
57. Tammy's income for the month of January was $2,475. Her fixed expenses during that same
Roman55 [17]

Answer:

57. Tammy's income for the month of January was $2,475. Her fixed expenses during that same

month were $750, and her variable expenses totaled $1,750. What was Tammy's net cash flow

during the month of January? Be sure to indicate whether she had a surplus or a deficit.

Explanation:

no clue

5 0
3 years ago
Assume that the reference variable r refers to a serializable object. Write code that serializes the object to the file ObjectDa
laiz [17]

Answer:

FileOutputStream out = new FileOutputStream("ObjectData.dat");

ObjectOutputStream ostream = new ObjectOutputStream(out);

ostream.writeObject(r);

Explanation:

For object serialization, we can use the writeObject method of java.io.ObjectOutputStream class.

The complete code fragment is as follows:

import java.io.*;

class Demo{

      public static void main(String args[]){

             try{

                  r = <Reference to Object to be serialized> ;

                 FileOutputStream out = new FileOutputStream("ObjectData.dat");

                 ObjectOutputStream ostream = new ObjectOutputStream(out);

                  ostream.writeObject(r);

                 ostream.close();

            } catch(Exception e){

                   e.printStackTrace();

            }

      }

}

5 0
3 years ago
Other questions:
  • Type the correct answer in the box. Spell all words correctly.
    9·1 answer
  • How do you open two different picture in photoshop?
    14·1 answer
  • What component of a computer system holds the operating system when the computer is not running
    6·2 answers
  • In Excel, an individual cell is the intersection of a row and a column.<br> True<br> False
    10·2 answers
  • Oop skskskssksksksksk
    15·2 answers
  • Write an algorithm that receives a number from the user (you can store the number in a variable called N). Then the algorithm sh
    8·1 answer
  • There are spoilers that doctor brenner is back in stranger things four and eleven is going back. Do you believe it or no? Make s
    12·1 answer
  • Choose the item which best describes the free frame list. 1. a per process data structure of available physical memory 2. a glob
    7·1 answer
  • Areas on which the development of the computer as a communication technology is based
    5·1 answer
  • Question 1 of 10 Which type of information systems personnel are involved in organizing information so that users can access it
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!