Help with C++

3

3than7

I am new to C++. but i have a practical problem that i am fairly
certain can be solved with C++
I am a student and am taking Latin. I want a program that will allow me
to input the english word and have the program tell me the latin word,
wich i can use to study, etc.
If someone could post some code i can use, and tell me where to put the
english words and the latin words that would be great,
thanks~3than
 
S

streamkid

Ï/Ç 3than7 Ýãñáøå:
I am new to C++. but i have a practical problem that i am fairly
certain can be solved with C++
I am a student and am taking Latin. I want a program that will allow me
to input the english word and have the program tell me the latin word,
wich i can use to study, etc.
If someone could post some code i can use, and tell me where to put the
english words and the latin words that would be great,
thanks~3than

what have you done till now?
i guess you want to dev a lexico, and that needs a database of :)

well building a language database i think is to difficult, so.. my idea
is to create a net app, that connects to an existing database (ie
babelfish) and finds the word there...
babelfish doesn't support latin, but checkout here..
http://www.google.gr/search?q=latin...&rls=org.mozilla:el:official&client=firefox-a
 
I

IR

3than7 said:
I am new to C++. but i have a practical problem that i am fairly
certain can be solved with C++
I am a student and am taking Latin. I want a program that will
allow me to input the english word and have the program tell me
the latin word, wich i can use to study, etc.
If someone could post some code i can use, and tell me where to
put the english words and the latin words that would be great,

As a personal project I've been working on a similar application for
months now (french/chinese).

Granted, chinese is way more complex than latin (traditional/simple
characters and pinyin). But I can assure you that you don't want to
mess with all the problems I faced...

At least, not for such a petty task as personal comfort concerning
your own learning process (I'd even say lazyness, but don't get me
wrong, that's not an insult: I'm lazy too ;-) ).


Cheers,
 
S

Salt_Peter

3than7 said:
I am new to C++. but i have a practical problem that i am fairly
certain can be solved with C++
I am a student and am taking Latin. I want a program that will allow me
to input the english word and have the program tell me the latin word,
wich i can use to study, etc.
If someone could post some code i can use, and tell me where to put the
english words and the latin words that would be great,
thanks~3than

The perfect candidate for such a design would be a std::multimap where
dulicate pair-entries are allowed but all elements are ordered
automatically by predicate. If you aren't familiar with STL containers
that wouldn't be a good choice to learn with at first. Its not terribly
complicated but if you haven't touched modern C++, you may find it
overwhelming.

Presumably, you'ld also want to be able to store these in a file as
well (ie: one file stores elements of 'a', another file for those
starting with 'b', etc). Which implies learning about input file
streams and output file streams. That too is basic stuff but you don't
do that with your eyes closed.

I doubt anyone would here would agree to post a working program that
does the above quest simply because of the code-base involved. Perhaps
i could paste a simple example of one with a non-duplicate map and a
very short list of entries. Enter apple, banana, carrot or date for a
fake translation.

#include <iostream>
#include <ostream>
#include <string>
#include <map>
#include <stdexcept>

void PromptString(std::string& r_s)
{
std::cout << "Enter a string to find the translation for: ";
std::cin >> r_s;
if(!std::cin.good() )
throw std::runtime_error("input failure");
}

void Verify(std::string& r_s, std::map< std::string, std::string >&
r_map)
{
typedef std::map< std::string, std::string >::iterator MIter;
MIter miter = r_map.find(r_s);
if( miter != r_map.end() )
{
std::cout << "result: ";
std::cout << (*miter).second;
std::cout << std::endl;
} else {
std::cout << "no entry found.";
std::cout << std::endl;
}
}

void PromptContinue(bool& r_b)
{
std::cout << "Enter y to try again (enter any other key to stop): ";
std::string s;
std::cin >> s;
if(!std::cin.good() )
throw std::runtime_error("input failure");
if(!("y" == s))
r_b = true;
}


int main() {
std::map< std::string, std::string > translator;
translator.insert( std::make_pair( "apple", "translation of apple" )
);
translator.insert( std::make_pair( "banana", "translation of banana"
) );
translator.insert( std::make_pair( "carrot", "translation of carrot"
) );
translator.insert( std::make_pair( "date", "translation of date" ) );

try {
std::string s;
bool done(false);
while(!done)
{
PromptString(s);
Verify(s, translator);
PromptContinue(done);
}
} catch(const std::exception& r_e) {
std::cerr << "Error: " << r_e.what();
std::cerr << std::endl;
}
}
 
3

3than7

thank you Salt_peter

so is it as simple as copying that and adding new lines for each entry?
and thank you

and for the earlyier post, if this fails how do i got about this Net
App thing

thanks~3than
 
S

Salt_Peter

3than7 said:
thank you Salt_peter

so is it as simple as copying that and adding new lines for each entry?
and thank you

Not quite, you need a compiler to compile the program with. The few
lines i enetered can certainly be modified and more entries added but
thats not the goal and not the purpose of a program - since a program
should be parsing the data/database from an outside source. It doesn't
make sense to keep data in source code. If you aren't interested in
developing a program you'll probably want to look at something else.

Why don't you just start with a spreadsheet?
OpenOffice Calculator or MS Excel, depending on your platform.
 
3

3than7

ohh no, i AAMM intrested in developing a program, and by the end of the
year i might even be able to install it at school if its comprehensive
enough.
I have Dev-C++ from Bloodshed, wich im almost positive youve heard of,
however when i compiled what youve writen, it returned an error at the
second to last line saying was expecting } sooner. Now how do i make
the program work with a database or whatever you were referencing.
thanks~3than7
 
S

Salt_Peter

3than7 said:
ohh no, i AAMM intrested in developing a program, and by the end of the
year i might even be able to install it at school if its comprehensive
enough.
I have Dev-C++ from Bloodshed, wich im almost positive youve heard of,
however when i compiled what youve writen, it returned an error at the
second to last line saying was expecting } sooner. Now how do i make
the program work with a database or whatever you were referencing.
thanks~3than7

Yes, Bloodshed will do. As far as the } is concerned, unless the last
one was parsed away by whatever you are using to read the newsgroups,
that program is correct and definitely compiles.
Perhaps you are missing a newline at the end of source which is
preventing bloodshed from parsing the last }.

You don't need a database, std::map is a database which uses a special
kind of tree structure to facilitate extremely quick searches. Whenever
you add "records", which are in form of std::pair< string, string > in
this case, they are automatically ordered using a default algorithm
(std::less<> which orders keys in assending order). Regardless of the
order you add records, that container inserts them ordered
automatically.
http://www.sgi.com/tech/stl/Map.html

To store the database, you'll need to learn how to use std::eek:fstream to
write to files and std::ifstream to read from files. Which is actually
quite easy to do but lets do one thing at a time - doing std::maps is
already a big leap over a lot of important details. Eventually, you'll
end up with a database that will look like this in the file - the left
string is the key, $ is used as seperator and terminator: In fact, many
commercially available databases today use this very format.

apple$translation of apple$
banana$translation of banana$
carrot$translation of carrot$
date$translation of date$

Once you get the program to compile, add the following immediately
after the record insertions and before the try { } block to display all
the records. Note: you can change the order of the insertions (ie:
apple after carrot) but the result is the same.

int main()
{
... // std::map insertions

// add the following
std::cout << "number of records: " << translaotor.size();
std::cout << std::endl;
typedef std::map< std::string, std::string >::iterator MIter;
for(MIter miter = translator.begin(); miter != translator.end();
++miter)
{
std::cout << (*miter).first << "\t";
std::cout << (*miter).second << std::endl;
}
std::cout << std::endl;
// end of new section

try {
...
} catch ( ... )
{
...
}
}

You should get something like:

/* output:
number of records: 4
apple trans of apple
banana trans of banana
carrot trans of carrot
date trans of date

Enter a string to find the translation for: apple
result: translation of apple
Enter y to try again (enter any other key to stop): f
*/

You can't add a second apple entry, std::map only supports unique keys,
thats where the std::multimap comes in.
 
3

3than7

i dont really understand what your saying there, but ive saved this. I
bought C++ for dummies and when im finished reading that im hoping ill
be able to understand that and get started on this. Thank for your
help. And ill be really specific incase theres anything else you have
to offer knowledge wise.

i got the idea from this

#include <iostream>

using namespace std;

int main()
{
cout<<"Hello World \n";
cin.get();

int number;

cout<<"Please enter a number: ";
cin>> number;
cin.ignore();
cout<<"You entered: "<<number <<"\n";
cin.get();

}



its an example from an online tutorial thing ive been folliwing

i just thought itd be great if instead of telling me what i entered, it
could give me something else, and i applyed that concept to latin.
thanks for all your help and if theres anythign more you can add it
would appreciate it.
 
3

3than7

After reading some more about C++, i was wondering if i could
accomplish this with an IF funcion

could i make something like
(this wont be correct c++)
int word;
{
if ( word == tree )
cout<<"silva, silvae\n";
cin.get.ignore()
}

i have no idea what that would actually do but if you get the gist
there would that work if it was correct C++ wise, can i do a different
if function for each word?
~thanks, 3than7
 
O

osmium

3than7 said:
After reading some more about C++, i was wondering if i could
accomplish this with an IF funcion

could i make something like
(this wont be correct c++)
int word;
{
if ( word == tree )
cout<<"silva, silvae\n";
cin.get.ignore()
}

i have no idea what that would actually do but if you get the gist
there would that work if it was correct C++ wise, can i do a different
if function for each word?

Yes, that general idea could be made to work. But that is not translating
English to Latin, it has no grammatical rules for one thing. The general
idea you are asking of here is to map one word to another, where a word is a
group of letters. How many tens of thousands of words are you willing to
type in? You will most likely want an import an existing data base. But
doesn't that same data base already provide the end result you wanted?
 
3

3than7

well osmium, its only about 1000 words,
it would only use the latin words given by the instructor
so i would add about 30-50 words on a weekly basis.
so if you could show me a format i can use and jsut keep repeating the
code, i
have no problem typing alot
 
R

red floyd

3than7 said:
well osmium, its only about 1000 words,
it would only use the latin words given by the instructor
so i would add about 30-50 words on a weekly basis.
so if you could show me a format i can use and jsut keep repeating the
code, i
have no problem typing alot
Look up std::map or std::multimap.
 
O

osmium

3than7 said:
well osmium, its only about 1000 words,
it would only use the latin words given by the instructor
so i would add about 30-50 words on a weekly basis.
so if you could show me a format i can use and jsut keep repeating the
code, i
have no problem typing alot

My best guess is that you are trying to do two things at once.

o learn C++
o learn Latin

And you are saying, "Hey! Why don't I commingle these two"?

For the Latin thing, I see no need to write a program, you seem to use
Windows. Notepad and its search capability does everything you have asked
about. Make your dictionary with an English word, some tab characters (for
a nice alignment with the other lines) and a Latin word on the same line.
To use, type F3, the word you want (either language) and Enter. Its hard to
imagine a purpose built program that would be significantly better. Except
it won't have a nice header that says " 3 than 7's English/Latin
Translator".

A glut of programs is already a problem in the field. If you want to
continue your C++ interest, you have already been given some C++ buzz words
by others. For starters, I would suggest you become comfortable with
std::string, std::eek:fstrream and std::ifstream. Write a program that gets
several words from the user, saves them to a file, and then retrieves them
and then displays the words.
 
N

Noah Roberts

3than7 said:
I am new to C++. but i have a practical problem that i am fairly
certain can be solved with C++
I am a student and am taking Latin. I want a program that will allow me
to input the english word and have the program tell me the latin word,
wich i can use to study, etc.
If someone could post some code i can use, and tell me where to put the
english words and the latin words that would be great,
thanks~3than

I forget what the name is but I know this exists already on the
internet. There is even a website that uses the command line
translator. I believe the translator was written in Pascal. I worked
at a Catholic university for a while and a side project for a priest
was to write a gui in Java for this thing. It's out there and it's
free...do some looking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top