Read the words in from the binary file and figure out how many times each word appears in the file. Display the results to the user.
Use ObjectInputStream to read binary file
Use a HashMap with the word as a key (String) and an Integer as the value. For each word, first check to see if it already exists in the Map. If not, add the word as key with a value of 1 for the Integer value. If it does, get the current value and increment by 1 â replace the old key,value with the new key, value. After all the words are processed and the HashMap is complete. Iterate through the Hash map and display the results in a user -friendly fashion.
Create an easy to read table and print to the console. Hint: Use tabs (/t) (values are not from file)
Example:
Word Count
A 190
Apple 6
Etc
In: Computer Science
Complete the function, MycountWords in C++, which will count the number of words in a string. We will have different word separators(such as newline(\n), spaces, special symbols(? | \ , . : ;) ) That will separate the words in the giving istringstream. Remember if a words is separated by a hyphen and followed by a new line, they're still one word. The function has an option to be sensitive to case and also avoid duplicates. for duplicates, this is a boolean value that checks whether a word is repeated or not if its set to true and sensitive case is if the word count is sensitive to case and differentiates two words based on their case. even though they have different cases, they are the same word hence duplicates.
complete this function based on the description above.
unsigned int MycountWords(istringstream & iss, bool Duplicate=false, bool SenstiveCase =false) {
}
In: Computer Science
Create the infrastructure for building a word cloud application by
(1) Reading the content of a text file and creating a binary tree of words in that file. When a duplicate word is encountered. we simply increase the frequency count of that word in its corresponding node. In other words, the nodes in the tree have two parts. One part maintains the word, and the other maintains the frequency count. It should also be noted that words will not be case sensitive, hence three variations of the word (hello, Hello, HELLO), should be stored in the same node in the tree, and it should have a frequency of 3.
(2) Once the binary tree of words (including their frequency) has been created, we need to print the words and their frequency count (one word per line). (Use InOrder() traversal to display the words and their frequency count)
I have additional files,
if I have the code I can try link the files
In: Computer Science
In C++ Language
English/Spanish Translation Program.
Create a menu driven program that translates English to Spanish and Spanish to English.
Your translation program should use arrays for this program. You will need to populate the arrays with the contents of the English and Spanish data files provided. The two files are ordered such that each word in the one file corresponds to the respective translation in the other (i.e.: the first word in the ENG.txt file corresponds to the first word in the SPAN.txt file; the second word in the ENG.txt file corresponds to the second word in the SPAN.txt file, and so on).
Read each file into an array, one array for English words and one for Spanish words. The text files provided each have 100 words. Use a menu driven process.
A message should be displayed if the selected word is not in the dictionary and an error message is displayed if you select an incorrect menu option. Your program must be in a loop so that you can make multiple selections without having to restart your program each time.
In: Computer Science
Code in Java
Create a class named DictionaryWord as:
|
DictionaryWord |
|
- word: String
|
|
+ DictionaryWord (String word, String meanings) |
Write a program with the following requirements:
Creates 8 DictionaryWord objects with:
|
word |
meanings |
|
bank robber |
Steals money from a bank |
|
burglar |
Breaks into a home to steal things |
|
forger |
Makes an illegal copy of something |
|
hacker |
Breaks into a computer system |
|
hijacker |
Takes control of an airplane |
|
kidnapper |
Holds someone for ransom money |
|
mugger |
Attacks and steals money from someone |
|
murderer |
Kills another person |
Displays all DictionaryWord with the format as:
<<no>.<<word>>
<<meanings>>
<<no>.<<word>>
<<meanings>>
Where: <<no>>=1,2âŠ
Hint:
In: Computer Science
A corpus is a technical term for a collection of texts used to analyze a language and verify its linguistic properties. The first modern, computer-readable corpus was the Brown Corpus of Standard American English, compiled by Henry Kucera and W. Nelson Francis of Brown University. The Brown Corpus draws from American English texts printed in 1961 and was for many years a widely cited resource in computational linguistics.
The five most frequently occurring words in the Brown Corpus are the, of, and, to, and a. Consider a data set consisting of all occurrences of these words in the Corpus. The values of the variable named Word are and, to, of, the, and a, so Word is a nominal variable with five categories.
Frequency and relative frequency distributions are constructed to summarize the data. They are shown in the table that follows
|
able 1 |
||
|---|---|---|
|
Word |
Frequency |
Relative Frequency |
|
(Thousands of occurrences) |
||
| and | 28.9 | 0.1566 |
| to | 26.1 | 0.1415 |
| of | 36.4 | 0.1973 |
| the | 70.0 | 0.3794 |
| a | 23.1 | 0.1252 |
| Total | 184.5 | 1.0000 |
A census is an enumeration of a population. The U.S. Census Bureau conducts a census every 10 years, but in addition, the Population Estimates Program of the bureau publishes population estimates for incorporated places every year. According to 2007 estimates, the five largest U.S. cities (by population) are New York City, Los Angeles, Chicago, Houston, and Phoenix.
Consider a data set consisting of all the residents of these five cities. The values of the variable named City are Phoenix, Chicago, Houston, Los Angeles, and New York City, so City is a nominal variable with five categories. Frequency and relative frequency distributions are provided in the table below.
|
Table 1 |
||
|---|---|---|
|
City |
Frequency |
Relative Frequency |
|
(Millions of people) |
||
| Phoenix | 1.55 | 0.0829 |
| Chicago | 2.84 | 0.1519 |
| Houston | 2.21 | 0.1182 |
| Los Angeles | 3.83 | 0.2048 |
| New York City | 8.27 | 0.4422 |
| Total | 18.70 | 1.0000 |
In 1935, Harvard linguist George Zipf pointed out that the frequency of the kth most frequent word in a language is roughly proportional to 1/k. This implies that the second most frequent word in a language has a frequency one-half that of the most frequent word, the third most frequent word has a frequency one-third that of the most frequent word, and so on. A distribution that follows this rule is said to obey Zipfâs Law.
Zipfâs Law has been observed not only in word distributions, but in other phenomena as well, such as the populations of cities. Answer the questions/ blank below in percentages
The frequency of the second most frequent word in the Brown Corpus is ----------- that of the most frequent word. The population of the second largest city in the United States is-------- that of the largest city.
The frequency of the fourth most frequent word in the Brown Corpus is-------------- that of the most frequent word. The population of the fourth largest city in the United States is --------- that of the largest city.
In: Statistics and Probability
in c++ please
In this program you are going to have several files to turn in (NOT JUST ONE!!)
COMPILE THIS WAY:
g++ -Wall -std=c++11 hangman.cpp functions.cpp âo
hangman
PROGRAM DESCRIPTION:
You will create a C++ program that will allow the user to play the game Hangman. Hangman is traditionally a paper & pencil game. One player thinks of a word and the other player tries to guess it by suggesting letters that may be in the word. Your program will be player one, by pulling a word from a âword bankâ and then player two is the user of your program. The game is over when one of two things happen:
ARRAYS
You will have four arrays. Three of the arrays will be C-Strings (NOT C++ STRING CLASS STRINGS!!!).
WORD BANK
You will have to create an input file called wordBank.txt. You need to manually type in TEN or more words to this file. Your program will not be outputting to this file. wordBank.txt will be used as an input file only. Here is one of my wordBank.txt files to see what I mean. Please do not use my words â make up your own!
FUNCTION: INT MAIN()
SETTING UP FOR THE GAME
GAME PLAY
Function: void printStage(int)
This function will accept as a parameter the current stage and print out the respective diagram to the screen. Each time the user guesses, a diagram is printed out. The diagram represents the user being closer and closer to being âhangedâ â which is why the game is called Hangman. At the beginning of the game, the diagram starts at stage 0. The user will stay at stage 0 (zero) until he or she guesses incorrectly, and then he/she will advance one stage to stage 1. There are 7 stages (stage 0 to stage 6) to represent the user guessing incorrectly six times. If the user gets to stage 6, they lose the game. I have already provided this function for you!
Function: void printWord(char[], char[])
This function will print out the letters in the word that have already been correctly guessed. At the beginning of the game, this function should just print out underscores to represent each letter. This lets the user know how many letters is in the word they are trying to guess.
WORD: _ _ _ _ _ _ _
Then, as the user guesses a letter, replace the underscore with the letter:
WORD: W _ _ _ _ _ _
How the function should work:
Function: void printLettersGuessed(bool[], char[])
This function will print out all the letters the user has guessed so far (correct & incorrect).
LETTERS YOU HAVE ALREADY GUESSED: Q W X Z
How the function should work:
In: Computer Science
For this project, you are going to write a program to find the anagrams in a given dictionary for a given word. If two words have the same letters but in different order, they are called anagrams. For example, âlistenâ and âsilentâ are a pair of anagrams.
**JAVA**
First letâs focus on âLetterInventory.javaâ.
Its purpose is to compute the canonical âsorted letter formâ for a given word.
1. Implement the constructor, which takes the String input word. You can assume that the input word contains only valid letters (e.g. no punctuation or blanks), but it may contain letters in different cases.
2. Implement the method: public String getCanonical() It should return the canonical âsorted letter formâ for the input word (given in the constructor). It should use only lower cases. For example, if the given word is âAliBabaâ, then this method should return âaaabbilâ.
****I have already completed all of the above tasks I am struggling with the next part****
**below is the code I have for LetterInventory.java**
import java.util.*;
public class LetterInventory {
private String input;
//stores the original word.
public LetterInventory(String input) {
this.input = input;
}
//uses an array of chars to hold word and sorts it
into alphabetical order.
//displays it in lower case.
public String getCanonical() {
input = input.toLowerCase(); // converting input to
lower case
char [] word = input.toCharArray();
Arrays.sort(word);
String sorted = new String (word);
return sorted;
}
}
*** this is where i am stuck ***
Once âLetterInventory.javaâ is working as expected, we can now focus on âAnagramFinder.javaâ. It will read an input âdictionaryâ file, which contains quite many words, to build a map. The âkeyâ for the map is a wordâs canonical form, the âvalueâ for the map will be all the words in the given dictionary that share the same canonical form. For example, if both âlistenâ and âsilentâ are in the dictionary, one entry in the map would have key as âeilnstâ and value as an ArrayList of words âlistenâ and âsilentâ.
Implement the constructor, which takes in the input dictionary file and build the map. You can assume the words in the dictionary contain only valid letters. You should take advantage of âLetterInventoryâ.
3. Now implement the method: public void printAnagrams(String word) It should try to search the anagrams for the given word in the map. Again, you can assume the input word contains only valid letters, and you should take advantage of âLetterInventoryâ.
Print out any anagrams found. For now, donât worry about the case where the input word is the same as the word inside the dictionary, just print them out.
Here is some sample print out:
Your input is: silent. Found anagrams: listen, silent, tinsel.
Your input is: AliBaba. Sorry, didnât find any anagrams.
A sample main method is already written for you to test various functionalities with some sample input words.
*** Below is the shell for the main method ***
import java.io.*;
import java.util.*;
public class AnagramFinder {
public static void main(String[] args) throws FileNotFoundException
{
String[] originals = new String[] {
"realfun",
"mias",
"EVIL",
"unable",
"Silent",
"AliBaba"
};
for(String original: originals) {
LetterInventory inv = new LetterInventory(original);
System.out.println("Original: " + original + ", Canonical: " +
inv.getCanonical());
}
System.out.println("\n");
File f = new File("HW_sample_dict.txt");
AnagramFinder finder = new AnagramFinder(f);
for(String original: originals) {
finder.printAnagrams(original);
}
}
public AnagramFinder(File f) throws FileNotFoundException
{
//TODO implement
}
public void printAnagrams(String word) {
//TODO implement
}
public void printAnagrams2(String word) {
// Extra Credit: optional to implement
}
}
** can leave out extra credit part i just need help with the first 2 methods in the main file **
** the dict.txt is 400 pages long so I did not include it (the file just contains thousands of words) **
In: Computer Science
In: Nursing
Write a hangman program in c++.The game is played as follows:
1. The program selects a random word for the user to guess (Read words for the user to guess into an array of strings from a file. The words are: revolutionary, meaning, recovery, compartment, trainer, pursuit, harm, platform, error, confusion)
2. User guesses one letter at a time until either they guess the word, or they run out of guesses.
3. Select a random word from the array of strings to the word the user has to guess.
Maintain 2 char arrays:
a. availableLetters: a char array of the available letters the user can choose their guess from. Initialize availableLetters as the lowercase alphabet. As the user guesses letters, replace the corresponding guessed letter with a space to denote the letter has already been guessed.
b. visibleLetters: a char array of the not guessed letters in the word. Initialize visibleLetter to all dashes ("-"). As the user correctly guesses a letter, replace the corresponding dash(es) with the correct letter.
4. The main game loop:
a. Display information regarding the status of the game (visibleLetters, availableLetters, and the number of incorrect guesses remaining (the user gets 7 incorrect guesses)).
b. Prompt the user to enter their guess. If the user tries to guess a letter they have already guessed, inform the user and re-prompt.
c. Exit the loop if the users completely guesses the letters of the word or if the user runs out of incorrect guesses.
Note: relevant string methods you will likely need to use for this program are <string variable>.at(i) to get a character at index position and i and <string variable>.size() (or <string variable>.length() to get the number of characters in the string.
Example output:
The word to guess has 5 letters. ----- Available letters: abcdefghijklmnopqrstuvwxyz 7 incorrect guesses remaining. Please enter your guess: s s is not in the word. Too bad. 6 incorrect guesses remaining. ----- Available letters: abcdefghijklmnopqr tuvwxyz 6 incorrect guesses remaining. Please enter your guess: e Nice! e is in the word. -e--- Available letters: abcd fghijklmnopqr tuvwxyz 6 incorrect guesses remaining. Please enter your guess: r r is not in the word. Too bad. 5 incorrect guesses remaining. -e--- Available letters: abcd fghijklmnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: r r is not an available letter -e--- Available letters: abcd fghijklmnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: l Nice! l is in the word. -ell- Available letters: abcd fghijk mnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: h Nice! h is in the word. hell- Available letters: abcd fg ijk mnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: o Nice! o is in the word. Congrats, you guessed the word hello!
In: Computer Science