Write a C++ program that does the task given (the rest of the infomation is to better explain the task). The dictionary can be reached through this url: "http://svn.code.sf.net/p/cmusphinx/code/trunk/cmudict/cmudict.0.7a". Solve as soon as you can (due in a few hours). Thank you very much.
Note: In the following program the alternate pronunciations have been included as well.
Code Screenshots:
Sample Output:
Code To Copy:
//Include the required
//header files.
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
//Use the standard namespace.
using namespace std;
void splitOnSpace(string s, string &before, string &after);
string getProunication(string word) {
string W = "";
for (int i = 0; i < word.length(); i++) {
if ((word[i] >= 'a') && (word[i] <= 'z')) {
word[i] = char((int)word[i] - 32);
}
W = W + word[i];
}
string before = "";
string after = "";
std::ifstream fin("cmudict.0.7a"); // open file and read in
std::string line;
if (fin.fail()) {
std::cerr << "File cannot be opened for reading." << std::endl;
exit(1);
}
while (getline(fin, line)) {
splitOnSpace(line, before, after);
if (W == before) {
return after;
}
}
fin.close();
//Return not found if the file was
//fully traversed but the word wasn't found.
return "Not found";
}
//Define the function getIdentical().
void getIdentical(string word, string pron) {
//Convert the word to uppercase.
string W = "";
for (int i = 0; i < word.length(); i++) {
if ((word[i] >= 'a') && (word[i] <= 'z')) {
word[i] = char((int)word[i] - 32);
}
W = W + word[i];
}
//Declare the strings to store
//the word and its pronunciation.
string dict_word = "";
string dict_pron = "";
//Open the file.
ifstream file("cmudict.0.7a");
string line;
//Read the file line by line.
while (getline(file, line)) {
splitOnSpace(line, dict_word, dict_pron);
//If the Pronounciation of the current word
//matches the pronounciaton of the given word.
//then, display the word.
if (pron == dict_pron && dict_word != W) {
cout << dict_word << " ";
}
}
cout << endl;
file.close();
}
//Define the addphenome()
void addphenome(string word, string pron) {
//Convert the word to uppercase.
string W = "";
for (int i = 0; i < word.length(); i++) {
if ((word[i] >= 'a') && (word[i] <= 'z')) {
word[i] = char((int)word[i] - 32);
}
W = W + word[i];
}
//Define the required string variables.
string before = "";
string after = "";
string before1 = "";
string after1 = "";
string add_p;
//Open the file
ifstream file("cmudict.0.7a");
string line;
int fail = 0;
//Read the file in a line-by-line manner.
while (getline(file, line)) {
splitOnSpace(line, before, after);
//Store the current word.
add_p = before;
//Split to get the first phenome of the pronounciation.
splitOnSpace(after, before, after);
//Split again to get the first phenome
// conatins an extra space before it.
splitOnSpace(after, before, after);
splitOnSpace(pron, before1, after1);
splitOnSpace(after1, before1, after1);
fail = 0;
//Comapre the phenomes of the two word one by one.
//If the pronounciation of the current word has
//only one extra phenome then display the current word.
while (after != "" || before != "") {
if (before == before1) {
splitOnSpace(after1, before1, after1);
if (before1 == "") {
while (after != "") {
splitOnSpace(after, before, after);
fail = fail + 1;
}
splitOnSpace(after, before, after);
} else {
splitOnSpace(after, before, after);
}
} else {
fail++;
splitOnSpace(after, before, after);
if (fail == 1 && before == "") {
fail = 2;
break;
}
}
}
//Reset the string values.
before = "";
after = "";
//If there was a difference of only one
//phenome in the pronounciation then,
//display the word.
if (fail == 1 && after1 == "") {
cout << add_p << " ";
}
}
cout << endl;
//Close the file.
file.close();
}
void reomvephenome(string word, string pron) {
//Convert the word to uppercase.
string W = "";
for (int i = 0; i < word.length(); i++) {
if ((word[i] >= 'a') && (word[i] <= 'z')) {
word[i] = char((int)word[i] - 32);
}
W = W + word[i];
}
//Declare the
//required variables.
string dict_word = "";
string dict_pron = "";
string line;
string before = "";
string after = "";
string trav = "";
string curr_pron = "";
string temp_pron = pron;
splitOnSpace(temp_pron, before, after);
//Remove a phenome 1 by 1 and check if
//a word can be formed from the
//obtained pronounciation.
while(after != "")
{
splitOnSpace(after, before, after);
trav = trav+" "+ before;
curr_pron = curr_pron + " " + after;
//Open the file and check the
//pronounciation of all the words.
ifstream file("cmudict.0.7a");
while (getline(file, line)) {
splitOnSpace(line, dict_word, dict_pron);
if (curr_pron == dict_pron) {
cout << dict_word << " ";
}
}
temp_pron = after;
curr_pron = trav;
file.close();
}
cout << endl;
}
void replacephenome(string word, string pron)
{
//Convert the word to uppercase.
string W = "";
for (int i = 0; i < word.length(); i++) {
if ((word[i] >= 'a') && (word[i] <= 'z')) {
word[i] = char((int)word[i] - 32);
}
W = W + word[i];
}
//Define the required string variables.
string before = "";
string after = "";
string before1 = "";
string after1 = "";
string add_p;
//Open the file
ifstream file("cmudict.0.7a");
string line;
int fail = 0;
//Read the file in a line-by-line manner.
while (getline(file, line)) {
splitOnSpace(line, before, after);
//Store the current word.
add_p = before;
//Split to get the first phenome of the pronounciation.
splitOnSpace(after, before, after);
//Split again to get the first phenome
// conatins an extra space before it.
splitOnSpace(after, before, after);
splitOnSpace(pron, before1, after1);
splitOnSpace(after1, before1, after1);
fail = 0;
while(after !="" || before !="")
{
if(before != before1)
{
fail = fail + 1;
}
if(fail > 1)
{
break;
}
splitOnSpace(after, before, after);
splitOnSpace(after1, before1, after1);
if(after == "" || after1 == "")
{
break;
}
}
if(fail <= 1 && after1 == "" && after == "")
{
if(fail == 0 && add_p != W)
{
cout<<add_p<<" ";
}
else if(fail == 1 && before == before1)
{
cout<<add_p<<" ";
}
}
}
cout << endl;
//Close the file.
file.close();
}
void splitOnSpace(string s, string &before, string &after) {
// this fucntion helsp split my string into parts. Ex: "Fortune favors the
// bold" ? "Fortune" and "favors the bold".
// reset strings
before = "";
after = "";
// accumulate before space
int i = 0;
while (i < s.size() && !isspace(s[i])) {
before += s[i];
i++;
}
// skip the space
i++;
// accumulate after space
while (i < s.size()) {
after += s[i];
i++;
}
}
//Define the main() function.
int main() {
//Declare the string to
//store the input word.
string word;
//Declare the string to store the
//obtained pronunciation of the word.
string pron;
cout << "Enter the word: ";
cin >> word;
//Call the function getProunication() to get
// the pronunciation of the current
// word from the file.
pron = getProunication(word);
//If the word wasn't found in the file
//then display the error message
//and end the program.
if(pron=="Not found")
{
cout<<pron;
exit(0);
}
//Display the pronunciation.
cout << "Pronounciation :"
<< pron << endl;
//Display the identical
//words and the add_phenome words.
cout << "Identical :";
getIdentical(word, pron);
cout << "Add phenome :";
addphenome(word, pron);
cout << "Remove phenome: ";
reomvephenome(word, pron);
cout<<"Replace phenome: ";
replacephenome(word, pron);
return 0;
}
Write a C++ program that does the task given (the rest of the infomation is to...
CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from the given data file "data.txt" The program should be case insensitive and count the number of occurances of each character in the alphabet. It should print a histogram of the results as follows: A : B : C : * D : * E : * F : G : H : I : J : * K : L : M : N...
Character Count Write a program that reads a file and counts the number of occurrences of each character in the file (case sensitive). The file name is "char.txt". You should use a dictionary to hold the number of occurrences of each character, and print out that dictionary. For example, if the file contains only six characters, "tactic", your dictionary should contain the following key-value pairs (order can be different): {'a': 1, 'c': 2, 'i': 1, 't': 2} Sample Input: Follow...
Write a python program that writes to an output file "decoder.txt" a table of letters as follows: ___1_2_3_4_5 1: A B C D E 2: F G H I K 3: L M N O P 4: Q R S T U 5: V W X Y Z Note that the letter J has been removed. Use string.ascii_uppercase to start
Java... Write a program that has 4 separate threads. The threads will have the following arrays: Thread1: A E I M Q U Y Thread2: B F J N R V Z Thread3: C G K O S W ThreadD: D H L P T X Your goal is to synchronize the threads in such a way that they print out all the letters of the alphabet in order.
Write a program that prompts the user to enter a 10 alphabets (A-Z) and converts it to numbers using the following mapping: A, B, C = 8 D, E, F = 6 G, H, I = 4 J, K, L = 5 M, N, 0 = 7 P, Q, R, S = 2 T, U, V, W = 3 X, Y, Z = 1 Please be sure to use Object Oriented Programming concepts when designing and writing code for this...
This is a c++ question note: not using namespace std; at the beginning of the program Writing Data to a File This program will write a series of letters, starting with 'A', to an external file (letters.txt). The user will decide how many letters in total get saved to the file. ** IMPORTANT: The test cases will evaluate your code against .txt files that I uploaded. You do NOT have to upload your own txt files. Input: Including 'A', how many...
Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is a system that encodes a word into a letter followed by three numbers that roughly describe how the word sounds. Therefore, similar sounding words have the same four-character code. Use the following set of (slightly modified #4) rules to create a translator from English words to Soundex Code: Retain the first letter of the word. For letters 2 …n, delete any/all occurrences of the...
Given the text file “Alamo defenders.txt” (attached to this assignment), write a simple Java program to do the following: - count how many names are in the file - find the longest full name in the file - find the longest single name (first, middle or last) in the file - find whether there were any Alamo defenders named “Jones” - write out, to the screen (console), all of the above information Alamo defenders.txt file: Juan Abamillo James L. Allen...
2. Write the chemical formulas for the following: b. aluminum a. copper c. hydrochloric acid e. copper(II) chloride g. sodium hydroxide i. hydrogen k. carbon dioxide m. calcium carbonate o. aluminum chloride q. calcium chloride d. magnesium sulfate – f. sodium bicarbonate h. methane j. sodium chloride 1. oxygen n. magnesium hydroxide p. sodium carbonate — r. water t. carbon monoxide S. sodium v. iron u. sulfur w.iron (II) sulfide y. sulfuric acid x. magnesium chloride z. sodium sulfate 3....
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...