Write a C++ program to open and read a text file and count each unique token (word) by creating a new data type, struct, and by managing a vector of struct objects, passing the vector into and out of a function.
Declare a struct TokenFreq that consists of two data members: (1) string value; and (2) int freq; Obviously, an object of this struct will be used to store a specific token and its frequency. For example, the following object word stores the token "dream" and its frequency 100:
TokenFreq word;
word.value="dream";
word.freq=100;
Implement the function vector<TokenFreq> getTokenFreq( string inFile_name); This function reads the specified input file line by line, identifies all the unique tokens in the file and the frequency of each token. It stores all the identified (token, freq) pairs in a vector and returns this vector to the calling function. Don't forget to close the file before exiting the function.
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
struct TokenFreq
{
string value;
int freq;
};
vector<TokenFreq> getTokenFreq(string inFile_Name)
{
}
int main()
{
}
In: Computer Science
Using java, commenting should be proper, along with testing for valid and invalid inputs:
Develop a simple tool for analyzing a segment of text that determines the number of words in that segment and the average word length. The application should have a single window with a scrolling text box (JTextArea) and an area to display the statistics. The statistics area should be a panel with a titled border, containing labelled fields that display the number of words in the text and the average word length, as well as any other statistics you would like to add. The statistics area should also contain a button that, when pressed, computes the statistics for the current text content.
Hint: Use a Scanner object to parse the text content. The .next() operation will get the next word.
Design and implement an application that works as a stopwatch. Include a display that shows the time as it increments. The time value should be seconds only, to one decimal place. Include buttons that allow the user to start and stop the time, and to reset the display to zero. Arrange the components to present a nice user interface. The buttons should include a mnemonic shortcut. Only a single action listener should be used for the buttons.
In: Computer Science
Please carefully review the code to fill in after the given instructions and complete the code for me.
Thank you in advance.
In this problem, we will implement a simple dictionary of common words in the English language, represented as an array of words paired with their lengths. You will need to implement each of the below methods in the Dictionary class. In this problem, the first line of input represents the method to call. It will be one of the following: MIN, MAX, RANGE, AVERAGE, MODE. The second line will represent an integer n, which denotes the number of words in the list. The following n lines will each be a word. The words will not necessarily be sorted. Your output should be a single line representing the results of the method. (a) Implement the minWordLength() method, which should return the length of the smallest word in the list. (b) Implement a method called maxWordLength(), which should return the length of the largest word in the list. (c) Implement a method called wordLengthRange(), which should return the range of lengths in the word list. (d) Implement a method called averageWordLength(), which should return the average word length in the word list. The method should return a string representing the average, accurate to exactly two decimal places (i.e. if the average length is 5, return 5.00). (e) Implement a method called mostCommonWordLength(), which should return the most common length of the words in the list. If there is a tie, you should return -1. You may assume that the length of a word is at most 100 and at least 1.
import java.lang.UnsupportedOperationException;
import java.util.Scanner;
public class Main {
// Constants for function names in input
public static final String MIN_METHOD_NAME = "MIN";
public static final String MAX_METHOD_NAME = "MAX";
public static final String RANGE_METHOD_NAME = "RANGE";
public static final String AVERAGE_METHOD_NAME = "AVERAGE";
public static final String MODE_METHOD_NAME = "MODE";
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read in the method name that we want to call
String methodName = sc.nextLine();
// Read in number of words
int numWords = Integer.parseInt(sc.nextLine());
// Read in list of words
String[] words = new String[numWords];
for (int i = 0; i < numWords; i++) {
words[i] = sc.nextLine();
}
// Run the specified method
switch (methodName) {
case MIN_METHOD_NAME:
System.out.println(minWordLength(words));
break;
case MAX_METHOD_NAME:
System.out.println(maxWordLength(words));
break;
case RANGE_METHOD_NAME:
System.out.println(wordLengthRange(words));
break;
case AVERAGE_METHOD_NAME:
System.out.println(averageWordLength(words));
break;
case MODE_METHOD_NAME:
System.out.println(mostCommonWordLength(words));
break;
default:
throw new UnsupportedOperationException();
}
}
private static int minWordLength(String[] words) {
// TODO implement this function
throw new UnsupportedOperationException();
}
private static int maxWordLength(String[] words) {
// TODO implement this function
throw new UnsupportedOperationException();
}
private static int wordLengthRange(String[] words) {
// TODO implement this function
throw new UnsupportedOperationException();
}
private static String averageWordLength(String[] words) {
// TODO implement this function
throw new UnsupportedOperationException();
}
private static int mostCommonWordLength(String[] words) {
// TODO implement this function
throw new UnsupportedOperationException();
}
}
In: Computer Science
write an essay of complete and well composed paragraphs (200 word minimum for the entire essay) where you identify a company in your community and describe the human resources challenges facing it.
In: Finance
In: Economics
can anyone explain to me according to the own simple word not copy and paste about the theory of the blanned behavior and social Learning and relate them in the dental Hyegene
thank You
In: Nursing
Compare and contrast the characteristics of economic growth in the High-Performance Asian Economies (HPAE) with the characteristics in Latin America. (Please write more than one page on word font 12.)
In: Economics
Write a 175- to 265-word response to the following:
In: Nursing
There are five time value of money components – FV, PV, N, I, and PMT. Briefly describe each and create a hypothetical and realistic calculation word problem to find one of the components
In: Finance
Should you have exclusive rights to your own intellectual property? Use the Normative ethics like Deontology and consequentialism to answer the question. (minimum word limit is 300 words)
In: Economics