Translate English words to French

Hi, I need help writing a program that allows you to read an English-French dictionary into two arrays. The English words are stored in one file alphabetically while the French words are stored in the other file corresponding to the English words. This means that the program would ask the user to type a random word and then it would print its French equivalent. The dictionary has to store up to 50 words and use the following function prototypes:

int read_in(char[][Word Length], char[][Word Length]);
void sort_words(char[][Word Length], char[][Word Length], int);
void search_words(char[][Word Length],char[][Word Length], int);
void write_out(char[][Word Length],char[][Word Length], int);

I'm using Word Length equals to 30. Look, it seems like a lot but I don't want the full answer, pseudo-code or even the format would be fine because I'm really at a loss at how to start thanks to my professor's lack of any teaching ability. Asking for help from him always leads to a look like you're some kind of jerk.
probably the most common way is:

- make a text file (*.txt) as the dictionary
- make a fstream variable (or ifstream) to search through the text file
- search from the beginning every time make a new searching

CMIIW
I would read the text files just the once, into arrays, and then search them, rather than rescanning the text files.

Where did the function prototypes come from? Are they fixed for your exercise?

Do you know how to read a text file into an array, line by line?
Do you know how to use a loop to output the values stored in an array?
Do you know about string comparison?

Andy

PS I assume your'e not familar with/allowed to use STL classes like string or vector?
Yes the function prototypes are fixed for this exercise.

Well I did use the fstream method for one other exercise where it would read the contents of one file and output those same contents to another. My professor did go over strings but I didn't really grasp it since he blew past the lesson in 30 minutes and then made us go home. Can't say I know about the loop to output stored in an array.
This is as far as I got:

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <fstream>
int read_in(char[][30], char[][30]);
void sort_words(char[][30], char[][30], int);
void search_words(char[][30],char[][30], int);
void write_out(char[][30],char[][30], int);
using namespace std;
int main()
{


I'm honestly totally lost.
Well, I don't think I can provide a specific response to such an open question.

But I would look at solving read_in and write_out first, then worry about the other two.

search_words() should also be easy enough; it just needs to find a translation, as your orig post says (you ask the user for an English word then find and display the French eqiv.)

But the point of sort_words() is unclear to me as the input file starts off sorted.

See the first half of "Input/Output with files"
http://www.cplusplus.com/doc/tutorial/files/

And "Arrays"
http://www.cplusplus.com/doc/tutorial/arrays/

They should give you enough info to solve 3 out of the four (all bar the sort).

And maybe "Basic Input/Output", if you want to review the use of cin and cout
http://www.cplusplus.com/doc/tutorial/basic_io/

The function signatures suggest you need to use arrays, rather than strings. But I suggest you use a const for the word length in case you decide 30 doesn't work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
using namespace std;

const int max_word_len = 30;

int read_in(char[][max_word_len], char[][max_word_len]);
void sort_words(char[][max_word_len], char[][max_word_len], int);
void search_words(char[][max_word_len],char[][max_word_len], int);
void write_out(char[][max_word_len],char[][max_word_len], int);

int main()
{
    const int max_word_count = 50; // this might need to be made global?

    char english_words[max_word_count][max_word_len];
    char french_words[max_word_count][max_word_len];

    int word_count = read_in(english_words, french_word);

    // Etc

    return 0;
}
Last edited on
Messed with databases at all? Throwing a ton of words into a database, or connecting a database to a larger online database might be worth looking into
I have this so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
using namespace std;
const int max_word_len = 30;
int read_in(char[][30], char[][30]);
void search_words(char[][30],char[][30], int);
void write_out(char[][30],char[][30], int);
int main()
{
	const int max_word_count = 50;
    char english_words[50][30];
    char french_words[50][30];
    int word_count = read_in(english_words, french_words);
	ifstream infile;							
	ofstream outfile;							
	infile.open("english_words.txt");
	if (infile.is_open())
	{

	infile.close();
	}
	else cout <<"Unable to open the file"<<endl;
    return 0;
}


I got rid of the sort and just sorted it alphabetically by hand but I'm not sure how to read a text file into an array...
Anyone have any ideas, please?
Some of the information you need is in the references I posted (inc. some liftable code!). You are unlikely to get anymore info till you show a bit more evidence of effort.

Of course, you could be lucky. There are some people who are prone to spoon feed!
Topic archived. No new replies allowed.