Write a C++ program that reads in 10 English and 10 French words and stores each
ID: 3575487 • Letter: W
Question
Write a C++ 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 file, call 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 sec 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 dicfionary.cpp, the main should be called dictionarydrvr.cpp An example of dict.dat could be: house maison mother mere father pere sister soeur brother frere library bibliotheque door porte hello bonjour good-bye au revoir cat chat dog chien book livreExplanation / Answer
I am providing the starter code for this. Please implement the sorting and later stuff for complete program.
#include <iostream>
#include <fstream>
#include <string>
#include <map>
// in C++, map is used as Dictionary.
using namespace std;
// Dictionary class
class Dictionary{
public:
string english_name;
string french_name;
// Constructor
Dictionary(string e,string f){
this.english_name = e;
this.french_name = f;
}
// Overloaded assignment operator.
void operator = (const Dictionary &D ) {
english_name = D.english_name;
french_name = D.french_name;
}
}
int main ()
{
string line;
string eng;
string fre;
// Read the filename
string filename = "dict.dat";
Dictionary dc[10];
ifstream myfile(filename);
// Read all the entries from the file.
if(myfile.is_open()){
for(int i=0;i<10;i++){
getline(myfile,line);
eng = line[0];
fre = line[2];
dc[i](eng,fre);
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.