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

I want to convert this from C++ to Java, I am indexing a text file and returning

ID: 3535088 • Letter: I

Question

I want to convert this from C++ to Java, I am indexing a text file and returning the word and definition (example contents of text file below) where text file contain wros and definitions. I want to convert this to C++.

//Dictionary.h

#ifndef Dictionary_H

#define Dictionary_H

#include <iostream>

#include <string>

#include <fstream>

using namespace std;


class Dictionary

{

public:

Dictionary();

Dictionary(int, int);

~Dictionary();

string getWord(int);

string getDefinition(int);

int getNumWords();

string getDefinition(string &);

string getSmallDefinition(int);

string getSmallDefinition(string &);


private:

string *words;

string *definitions;

string *Smalldefinitions;

int numwords;

};


Dictionary::Dictionary()

{

numwords = 16; //number of words in text file

words = new string[numwords];

definitions = new string[numwords];

Smalldefinitions = new string[numwords];

string STRING;

int index;

int parenthesis;

int i = 0;

ifstream infile;

infile.open ("DICTIONARY.txt");

while(!infile.eof()) // to get all lines

{

getline(infile,STRING); // copies line to STRING

index = STRING.find(" ");

words[i] = STRING.substr(0,index);

definitions[i] = STRING.substr(index);

parenthesis = definitions[i].find("(",7);

Smalldefinitions[i] = definitions[i].substr(0,parenthesis);

i++;

}


char weird = -30;

int word_extracted;

for (int i = 0;i<numwords-1;i++)

{

if ((definitions[i].find(weird)) != 4294967295)

{

word_extracted = definitions[i].find(weird);

definitions[i].replace(word_extracted,3,"'");

}

}


}


Dictionary::Dictionary(int start, int end)

{

numwords = end - start;

words = new string[numwords];

definitions = new string[numwords];

string STRING;

int index;

int i = 0;

ifstream infile;

infile.open ("SATVOCABLIST.txt");

while(!infile.eof()) // to get all lines

{

if (i == end)

{

break;

}

if (i >= start)

{

getline(infile,STRING); // copies line to STRING.

index = STRING.find(" ");

words[i-start] = STRING.substr(0,index);

definitions[i-start] = STRING.substr(index);

i++;

}

else

{

getline(infile,STRING);

i++;

}

}


char weird = -30;

int word_extracted;

for (int i = 0;i<numwords-1;i++)

{

if ((definitions[i].find(weird)) != 4294967295)

{

word_extracted = definitions[i].find(weird);

definitions[i].replace(word_extracted,3,"'");

}

}



}


Dictionary::~Dictionary()

{

}



int Dictionary::getNumWords()

{

return numwords;

}


string Dictionary::getWord(int ind)//index of line number in Dictionary.txt

{

return this->words[ind-1];

}


string Dictionary::getDefinition(int ind)//index of line number in Dictionary.txt

{

return this->definitions[ind-1];


}


string Dictionary::getDefinition(string &word)

{

for (int i = 0;i<numwords-1;i++)

{

if (getWord(i).compare(word) == 0)

{

return this->definitions[i];

}

}

}


string Dictionary::getSmallDefinition(int ind)//index of line number in Dictionary.txt

{

return this->Smalldefinitions[ind-1];

}


string Dictionary::getSmallDefinition(string &word)

{

for (int i = 0;i<numwords-1;i++)

{

if (getWord(i).compare(word) == 0)

{

return this->Smalldefinitions[i];

}

}

}


#endif

//MAIN.CPP

#include <iostream>

#include <string>

#include <fstream>

#include "Dictionary.h"

using namespace std;




int main ()

{

string myword("accessible"); //word on line 12

Dictionary mydictionary2;

cout << mydictionary2.getWord(12) << endl; //line 12 is read

cout << mydictionary2.getNumWords() << endl;

cout << mydictionary2.getDefinition(12) << endl;

cout << mydictionary2.getSmallDefinition(12) << endl;


system("pause");


return 0;

}


Example text file: (Many words and definitions....)

abjure (v.)to reject, renounce (To prove his honesty, the President abjured the evil policies of his wicked predecessor.)

abnegation (n.)denial of comfort to oneself (The holy man slept on the floor, took only cold showers, and generally followed other practices of abnegation.)

abort (v.)to give up on a half-ï¬nished project or effort (After they ran out of food, the men, attempting to jump rope around the world, had to abort and go home.)

abridge 1. (v.)to cut down, shorten (The publisher thought the dictionary was too long and abridged it.) 2. (adj.)shortened (Moby-Dick is such a long book that even the abridged version is longer than most normal books.)

abrogate (v.)to abolish, usually by authority (The Bill of Rights assures that the government cannot abrogate our right to a free press.)

abscond (v.)to sneak away and hide (In the confusion, the super-spy abscondedinto the night with the secret plans.)

absolution (n.)freedom from blame, guilt, sin (Once all the facts were known, the jury gave Angela absolution by giving a verdict of not guilty.)

abstain (v.)to freely choose not to commit an action (Everyone demanded that Angus put on the kilt, but he did not want to do it and abstained.)

abstruse (adj.)hard to comprehend (Everyone else in the class understood geometry easily, but John found the subject abstruse.)

accede (v.)to agree (When the class asked the teacher whether they could play baseball instead of learn grammar they expected him to refuse, but instead he acceded to their request.)

accentuate (v.)to stress, highlight (Psychologists agree that those people who are happiest accentuate the positive in life.)

accessible (adj.)obtainable, reachable (After studying with SparkNotes and getting a great score on the SAT, Marlena happily realized that her goal of getting into an Ivy-League college was accessible.)

acclaim (n.)high praise (Greg’s excellent poem won the acclaim of his friends.)

arcane (adj.)obscure, secret, known only by a few (The professor is an expert in arcane Lithuanian literature.)

archaic (adj.)of or relating to an earlier period in time, outdated (In a few select regions of Western Mongolian, an archaicChinese dialect is still spoken.)

archetypal (adj.)the most representative or typical example of something (Some believe George Washington, with his flowing white hair and commanding stature, was the archetypal politician.)

Explanation / Answer

contact me on timacs12@gmail.com

you can rate after getting the answer

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