Question
Hello this is my project: C++ (YOU CANNOT USE ARRAYS AND STRING.find or .get) ONLY LOOPS STRINGS Introduction In this project you are going to
Hello this is my project: C++ (YOU CANNOT USE ARRAYS AND STRING.find or .get) ONLY LOOPS STRINGS
Introduction
In this project you are going to implement a linguistic application that uses a pronunciation dictionary for finding words with similar pronunciation.
Example. You enter a word, and it reports similar-sounding words:
> donut Pronunciation : D OW1 N AH2 T Identical : DOUGHNUT Add phoneme : DONUTS DONUTS' DOUGHNUTS Remove phoneme : DON'T Replace phoneme : DONAT DONATE
We are going to use The CMU Pronouncing Dictionary as our reference. It is available as a simply formatted plain text file, a direct link to it is: cmudict.0.7a
An excerpt from it is shown below:
PROGRAM P R OW1 G R AE2 M PROGRAM'S P R OW1 G R AE2 M Z PROGRAMME P R OW1 G R AE2 M PROGRAMMER P R OW1 G R AE2 M ER0 PROGRAMMERS P R OW1 G R AE2 M ER0 Z PROGRAMS P R OW1 G R AE2 M Z PROGRAMS' P R OW1 G R AE2 M Z PROGRESS P R AA1 G R EH2 S PROGRESS(1) P R AH0 G R EH1 S PROGRESS(2) P R OW0 G R EH1 S PROGRESSED P R AH0 G R EH1 S T PROGRESSES P R AA1 G R EH2 S AH0 Z PUSH-UP P UH1 SH AH2 P PUSH-UPS P UH1 SH AH2 P S
In linguistics, a phoneme is a perceptually distinct units of sound that distinguishes one word from another, for example p, b, d, and t in the English words pad, pat, bad, and bat.
Each line of the dictionary file contains a word followed by the list of its phonemes (P R OW1 G R AE2 M). Vowel phonemes, such as OW or AE, end with an additional digit 0, 1, or 2, indicating the type of stress on that vowel (no stress, primary stress, secondary stress). If a word has multiple pronunciations, such alternatives are labeled with (1), (2), (3), and so on (see the word PROGRESS in the example above). Comment lines start with triple semicolons (these lines can be ignored). For more information about the dictionary file formatting, read its web page referenced above.
For this project, to make the task easier, your program should ignore all words that contain non-alphabetic characters, and also ignore all alternative pronunciations, The only non-letter character that is allowed in a word is apostrophe '.
So, your program should ignore entries like:
PROGRESS(1) P R AH0 G R EH1 SHowever, the following entries are considered good:
PROGRAM P R OW1 G R AE2 MProgramming Task
Write a program pronounce.cpp that
Lets the user input a word (lets call the input word W).
If the word is not found in the dictionary, print Not found. Otherwise, report:
Pronunciation : the pronunciation of the word W (as given in the dictionary),
Identical : other words from the dictionary with the same pronunciation as W,
Add phoneme : words that can be obtained from W by adding one phoneme,
Remove phoneme : words that can be obtained from W by removing one phoneme,
Replace phoneme : words that can be obtained from W by replacing one phoneme.
When listing words, include all words from the dictionary that meet the criteria, the order of listed words should be the same as they appear in the dictionary.
Your program should expect that the dictionary file cmudict.0.7a is located in the current working directory.
User input should be case-insensitive (accepting donut, DONUT, DOnUt, etc.)
Please, dont make complex user interface that allows multiple queries. The program should just ask for one word, report the answer, and exit. See examples below.
You are allowed to use only the constructs of the language that were mentioned in lecture slides and covered in class. For strings, you can use only the operations mentioned in class.
Examples:
> accord Pronunciation : AH0 K AO1 R D Identical : ACORD Add phoneme : ACCORD'S ACCORDS MCCORD RECORD Remove phoneme : CHORD CORD Replace phoneme : ABOARD ADORED AFFORD AWARD SCORED> Ackerman Pronunciation : AE1 K ER0 M AH0 N Identical : ACKERMANN AKERMAN AKKERMAN Add phoneme : Remove phoneme : ACKMAN Replace phoneme : ACKERSON ADERMAN AKERSON AMERMAN AMMERMAN ANGERMAN ATTERMANN AUKERMAN ECKERMAN OCKERMAN> DRAFT Pronunciation : D R AE1 F T Identical : DRAUGHT Add phoneme : DRAFT'S DRAFTEE DRAFTER DRAFTS DRAFTY DRAUGHTS Remove phoneme : DAFT RAFT Replace phoneme : CRAFT DRIFT GRAFT KRAFFT KRAFT> colonel's Pronunciation : K ER1 N AH0 L Z Identical : COLONELS KERNELS Add phoneme : Remove phoneme : COLONEL KERNEL Replace phoneme : CANALES JOURNAL'S JOURNALS KENNELS> FLOWERS' Pronunciation : F L AW1 ER0 Z Identical : FLOURS FLOWERS Add phoneme : Remove phoneme : FLOUR FLOWER FOWERS Replace phoneme : CLOWERS FLIERS FLOWERED FLOWERY FLUOR'S FLYERS
I AM STUCK ON THE IDENTICAL PART PLEASE HELP ME SOLVE IT. THIS IS MY CODE:
#include
#include #include #include using namespace std; void splitOnSpace(string s, string & before, string & after) { // reset strings before = ""; after = ""; // accumulate before space int i = 0; while (i
int main() { ifstream input; input.open("cmudict.0.7a.txt"); if(input.fail()){ cout >word;
while(input >> str) { if(str == word){ getline(input, word); break; } } string afterSpace; string beforeSpace; splitOnSpace(str + word, beforeSpace, afterSpace); splitOnSpace(str + word, beforeSpace, afterSpace); cout
if(str == afterSpace) { } }while(!input.eof()); splitOnSpace(str, beforeSpace, afterSpace); cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started