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

I need the whole code. Please help me. Thank you. Write a Ctt program that reads

ID: 3576287 • Letter: I

Question


I need the whole code. Please help me. Thank you.

Write a Ctt program that reads in 10 English and 10 French words and stores each English word and its French equivalent in a Dictionary object. The dictionary data is stored in a it dict,dat. Sort the array of 10 Dictionary objects by the English word, and then allow the user to enter an English word and see its French equivalent. Remember to overload the assignment operator for the Dictionary class and use dynamic memory allocation to store the print its French equivalent. You should have a header file called dictionary.h, and a method file called dictionary.cpp, the main should be called dictionarydrvrepp An example of dict dat could be maison mother library bibliotheque bonjour good-bye au revoir chat

Explanation / Answer

#include using namespace std;

const int TRUE = 1;

const int FALSE = 0;

const int MAX_WORDS = 50;

const int WORD_LENGTH = 30;

// function declarions

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);

int main()

{

// arrays to store English and French words

char eng_array[MAX_WORDS][WORD_LENGTH];

char french_array[MAX_WORDS][WORD_LENGTH];

int num = 0;

// invoke functions

num = read_in(eng_array, french_array);

sort_words(eng_array, french_array, num);

search_words(eng_array, french_array, num);

write_out(eng_array, french_array, num);

return 0; }

// This function reads in English words and French words from the input file. The English words are stored in the array named engl which is passed to this function. The French words are stored in the array named french which is also passed to this function. Number is returned from the function and represents the number of English/French word pairs that are read from the input file.

int read_in(char engl[][WORD_LENGTH], char french[][WORD_LENGTH])

{

ifstream fin; int temp;

fin.open(“T:dict.txt”);

if(!fin)

{ cout << "Cannot open dict.dat" << endl;

exit(1); }

temp = 0;

while(fin >> engl[temp])

{ fin >> french[temp];

temp++; }

fin.close();

return temp;

}

// This function prints the English words and French words that are stored in the array named engl and the array named french which are passed to this function. Number is an integer that is contains the number of English/French word pairs that were read from the input file.

void write_out(char engl[][WORD_LENGTH],char french[][WORD_LENGTH], int number)

{ int k;

for(k = 0; k < number; k++)

{

//cout.width(WORD_LENGTH); //cout.setf(ios::left); //cout< 0)

{ strcpy(temp2,engl[k-1]);

strcpy(engl[k-1],engl[k]);

strcpy(engl[k],temp2);

strcpy(temp2,french[k-1]);

strcpy(french[k-1],french[k]);

strcpy(french[k], temp2); } } } }

// This function uses a binary search to search for an English word input by the user and then prints the English words and French words that are stored in the array named engl and the array named french which are passed to this function. Number is an integer that is contains the number of English/French word // pairs that were read from the input file.

void search_words(char engl[][WORD_LENGTH], char french[][WORD_LENGTH], int num)

{ char temp_word[WORD_LENGTH]; int beginning;

int end;

int middle;

int location;

int found;

cout << "Please enter an English word or ctrl-z to quit." << endl;

cout << "This program will display the French." << endl;

// keep getting words to search for until user wants to quit

while(cin >> temp_word)

{ found = FALSE; beginning = 0;

end = num – 1;

// stay in loop until English word is found or search is exhausted

while(end >= beginning && !found)

{ middle = (beginning + end) / 2;

//divide list in half

if(strcmp(temp_word, engl[middle]) < 0)

// alphabetically less end = middle - 1;

// throw out half the list

else if(strcmp(temp_word, engl[middle]) > 0)

// alphabetically greater

beginning = middle + 1;

//throw out half the list

else found = TRUE; // English word found in list }

if(found == TRUE)

{ location = middle; // this is the location in the array, print the English word and the French word found at this location

cout << engl[location] << "tt" << french[location] << endl; }

else { location = num; cout << "English word not found in dictionary." << endl; }

cout << "Enter an English word or ctrl-z. This program will display the French." << endl;

cin.ignore(1); } }

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