I want to help teach to a minority group in Milwaukee, so I want to create a dictionary program that translates a sentence (like a homework problem or teacher instructions), from English into Hmong.
I have one Idea, and that is to have an English text file of all the A-words, then a Hmong text file of the proper translations. Each text file would have the same amount of lines, with one english word per line, then translated to hmong. Would it be even possible to..
1. user inputs question, "Describe the holocaust"
2. describe is looked in the d text (like if d, search d.txt), then the word is found. then it either compares it to a translation txt (like hmong-d.txt), spitting out the word. then it would prompt to the next word to translate, one line at a time.
A different way was to have 1 giant text file for each letter. like look up "albino", when it finds the word in the a a-dictionary, it searches for the albino string, then finds the comma, then spits out the word/words after the comma. would this be possible as well? which method is easiest for someone that hasn't c++ in a few years?
so far I have a useless code typed up. i just want to start simple getting a-words to work, then get more complex from there. once i have a start i can go with it. please help me, i would love to reach the needs of my esl students who could use this greatly in the US.
summary,i want to take a line of words, compare each word to a specific dictionary, then output one line at a time, the translation. thank you so much!
this code is not correct:
#include <iostream> // I/O
#include <fstream> // file I/O
#include <iomanip> // format manipulation
#include <string>
//This program will hopefully translate english to hmong
using namespace std;
string english; //declare english word to translate
string search; //what to search
int main()
{
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;
myFile.open ("c:\\eAh.txt") ;
string* search = english; //search using input
int offset; // where it was found (or not (-1))
if ((offset = line.find(searc h, 0)) != string::npos) {
cout << "found '" << search << "' @ offset " << offset << endl;
}
return 0;
}
91 7701 DeMan 1,806
Top Contributor
Quick couple of questions....
Is this code compiling?
If not, what error messages do you get?
If so, how do you know it isn't working (ie does it crash, or does it give bad ouput and if so what is the output)?
A different way was to have 1 giant text file for each letter. like look up "albino", when it finds the word in the a a-dictionary, it searches for the albino string, then finds the comma, then spits out the word/words after the comma. would this be possible as well? which method is easiest for someone that hasn't c++ in a few years?
I think that that is the easiest way to do it instead of having to look through two different files for each word. How big do you expect these files to get? -
string* search = english; //search using input
-
int offset; // where it was found (or not (-1))
-
if ((offset = line.find(search, 0)) != string::npos) {
-
cout << "found '" << search << "' @ offset " << offset << endl;
-
You never defined "line" and I dont think that you need a search variable.
DeMan 1,806
Top Contributor
hmm... how should i define line? i kind of found this on the internet, where they didn't define the line function. can anyone help with that?
i basically will have 100 words in a textfile for the letter a... (or 200, if it includes both languages seperated by , commas)
so i want it to search through a.txt for "apple" then find apple, and state
apple = koj thoj (made that up)
hmm... maybe i could replace the ,'s in my .txt files to have " = " instead, so it can simply just output the line? that would simplify my code.
so... search textfile of a words, find "apple", then stop when it finds the space (so if it finds a word like applelot (made up) it doesnt create a false positive, then prints out apple = koj thoj.
ps: i'll make sure to give you guys credit in the code. this is a freeware program for students, i want them to have access to this stuff !
DeMan 1,806
Top Contributor
I believe the line is a string.....
While you could read the whole file into the string, you could also consider parsing the file line by line.
Provided each of your line has similar structure (and starts with the word to translate), and assuming that these are listed alphabetically, you could try to implement a binary search to speed the effort up as the file gets large (which it will if you plan to store an entire dictionary)
(I'm pretty sure a file has a getline function (or similar))
any examples?
i need an example for the function, and what to do with the input.
should i have my text be one text file for a-english words, or two text files with one with english and another with the same amount of lines/line numbers for the different language?
if one textfile for a-words, should it be...
apple = koj thao
apple, koj thao
with the first example, i could simply return the entire line which would help my students. so if i had several dictionaries it would be like this
****
input your sentence in english: I love you.
i = kuv
love = hlub
you = koj
would you like to translate more words? y/n
if i could get a head start, it would help if i could at least get an example of taking an input that is a string, one word, then searching it in a text file, once it is found in the text file, spit it back out with something like love = hlub. the text file will be alphabetical even if it is tedious for me. that way in the future i could increase efficiency.
from here i hope i can figure out how to search multiple words in multiple textfiles using the if statements and your guy's help with the function... so eventually the search can occur in a generic file like trans[a].txt or trans[b].txt where the letter for the dictionary would be based on the first letter of the english word from the cin input. that means eventually i would need to create a string for each english word, and store it temporarily, then compare each one and spit it out one at a time. or in a simple way, word one>function>sp it out, word two>function>sp it out
first few lines from my a .txt file:
Abdomen = Plab mog
Able = Rooj
Able = Ua tau
Abortion = Rho menyuam tawm
About = Li ntawm
Above = Saum toj
the description here is similiar in context, but it would not compile for me:(
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?tx tCodeId=7536&ln gWId=3#zip
DeMan 1,806
Top Contributor - #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";
-
-
}
would be one way to try (assuming the english word is the first item in a row of the file you are trying to parse)
well that is a start.. but a cin>> just restates the entire .txt file dictionary...
anything i could put at the end of a line, to indiciate... stop typing?
maybe an if statement so it only says one word.... then in my txt file have a period? so that at the end of the sentance like
love = hlub.
the line code stops printing out lines? or some better looking character ?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Derek Fountain |
last post by:
I'm just starting another PHP project and can see a familiar task not far on
the horizon. I have several database record tuples that I need to
manipulate - person, department, client, job, etc. - and each one needs a
form where the user can enter new details to create a new tuple in the DB,
another form where the user can enter a...
|
by: Aziz McTang |
last post by:
Hi Group,
I am not an experienced programmer at all. I've learned html and css
well enough to hand-write simple websites. I'm now looking to move to
the next step. Initially, I'd like to do 3 things:
1) Generate web pages
This one's fairly obvious maybe.
2) Create a simplified translation package specific to my line of work:
|
by: piaseckiac |
last post by:
I am producing a website on air and need a link to change the entire
website from standard to metric for temperature, pressure,
miles-kilometers, and volume. Thank you.
|
by: vvk4 |
last post by:
I have an excel spreadsheet that I need to parse. I was thinking of saving
this as a CSV file. And then reading the file using C. The actual in EXCEL
looks like:
a,b a"b a","b a,",b
In CSV format looks like:
"a,b","a""b","a"",""b","a,"",b"
Does anybody have suggestions or have C program based code to parse CSV.
Please reply to the...
|
by: Quick Fox |
last post by:
Hi All,
Please help for following case:
How to Load a Assembly from DLL file and create instance
of the class in the loaded file.
I want make a function that get 2 string parameters
(Assembly file Name and Class Name) and create a instance.
Thanks
| |
by: Jim Hubbard |
last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
|
by: Chris F Clark |
last post by:
Please excuse the length of this post, I am unfortunately long-winded,
and don't know how to make my postings more brief.
I have a C++ class library (and application generator, called
Yacc++(r) and the Language Objects Library) that I have converted over
to C#. It works okay. However, in the C# version, one has to build
the class library...
|
by: jerger |
last post by:
my program takes users input (words/sentance) and translates it from english to hmong. I have to main variables, but cannot post my entire code.
char In;
CString in;
basically the user cin >> In; then later in = In, then computes using the dictionary. is there anyway i can remove ! commas and periods from the input before translating in...
|
by: bvdb |
last post by:
Hi Everyone,
One of my customers lives in Taiwan and can only make my program work if he changes his Regional and Language Options to English from the Simplifies Chinese that his computer is normally set to use. Switching back and forth is very inconvenient for him.
Is there a way that I can compile my program so that it works with the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |