Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I need help writing a program that allows you to read an English-French dict

ID: 3548669 • Letter: H

Question

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.

Explanation / Answer

#include <iostream> #include<conio.h> #include <string> #include <iomanip> #include <fstream>
using namespace std; const int Word_Length = 30, N = 50; //Defining constants int n = 0; int read_in(char [][Word_Length], char [][Word_Length]); // as given in question void sort_words(char [][Word_Length], char [][Word_Length],int); // as given in question void search_words(char [][Word_Length], char [][Word_Length],int); //as given in question void write_out(char [][Word_Length], char [][Word_Length],int); // as given in question
int main() { char english[N][Word_Length],french[N][Word_Length]; read_in(english,french); // call the function read_in write_out(english,french,n); // call the function write_out search_words(english,french,n); // call the function search_words sort_words(english,french,n); // call the function sort_words return 0; }
int read_in(char a[][Word_Length],char b[][Word_Length]) { ifstream inputfile; int i=0,j=0,k=0; char str1[N],str2[N]; // declaring inputfile.open("DIC.DAT"); // open file // To check if there is any error opening file if(!inputfile.is_open()){ cout << "Error opening file..." << endl; return 0; } // read the file with 2 columns into arrays for(i=0;!inputfile.eof(); i++) { inputfile >> str1 >> str2 ; // read letters from the file and the letters are separated by a space strcpy_s(a[i] ,str1); // english words in array a[] strcpy_s(b[i] ,str2); // french words in array b[] }
for(int m=0;m<i;m++) a[i-1][m]=0; n=i; // total number of words return n; }


void search_words(char a[][Word_Length],char b[][Word_Length],int sum) {    int i=0; char str[N], search[N][Word_Length], ans = 'y'; do { int j=0; cout<<"Enter the English word: "; cin>>str; strcpy(search[0],str); // copy inpute so that we can compare it element by element with a[i] for (i=0;i<sum;i++) { if(strcmp(a[i],search[0]) == 0) // if the words equal and strcmp() will return a zero which indicates both are same { cout<<right<<setw(23)<<"French: "<<b[i]<<endl<<endl; j=1; } } if (!j) cout<<"Oops no such word found. Please try again "<<endl<<endl; cout<<"Search another word? : (Y/N)"<<endl; cin>>ans; cout<<endl; }while((ans =='y') || (ans == 'Y') || (ans == 'Yes') || (ans == 'yes')); }
void sort_words(char a[][Word_Length],char b[][Word_Length],int sum) { int i=0, j=0, z=0; char str1[N], str2[N]; for (z=0;z<sum-1;z++) // applying bubble sort technique { for (i=0;i<sum-1;i++) { for (j=0;j<Word_Length;j++) { if (a[i][j]-a[i+1][j]<0) break; else if (a[i][j]-a[i+1][j]>0){ strcpy_s(str1,a[i]); strcpy_s(str2,b[i]); strcpy_s(a[i],a[i+1]); strcpy_s(b[i],b[i+1]); strcpy_s(a[i+1],str1); strcpy_s(b[i+1],str2); break;} else continue; } } } }
void write_out(char a[][Word_Length],char b[][Word_Length],int sum) { int i=0; ofstream outputfile; outputfile.open("OUTPUT.TXT"); for (i=0;i<sum;i++) {    outputfile<<a[i]<<" "<<b[i]<<endl; } outputfile.close(); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote