Create a program that converts a string of words from English to Spanish. You wi
ID: 3535888 • Letter: C
Question
Create a program that converts a string of
words from English to Spanish. You will read in a file using C file
I/O that contains English/Spanish pairs in the form.
English Word, Spanish Word
There will be 100 pairs in this file. You will need to create two
string arrays (two dimensional) to hold the English and Spanish
words. Assume no word will be longer than 25 actual characters
Once the arrays are created and populated, you will ask the user to
enter a string (one word or several enclosed in quotes). Once
entered you will translate the string from English to Spanish and
print the results. If a word is not found in the 100 word set, then
use a series of 5*’s to replace that word in the output string.
This should continue until the user types the word “quit†(don’t
translate this one!)
You will need to search the English word array for each word and
then build up a string of the Spanish translations. Consider using
some of the string functions in the standard library.
This program must be written in C and standard libraries must be
used! Also the program should have the appropriate comments!
This is the link to access the words.dat file:
https://www.dropbox.com/s/fdij5014wxh6bir/words.dat
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
cout << "Type the english words here, then press enter. Make sure to copy the words correctly. If you need to spell check use www.google.com";
cin >> english;
ifstream myFile ("c:\eAh.txt");
if (myFile.is_open())
{
while (! myFile.eof() )
{
getline (myFile,line);
if(strncmp(line, english, englis.length())
{
cout <<"Match found"<< line;
}
}
myFile.close();
}
else cout << "Unable to open file";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.