Assignment Help

Hi everyone, I need some help with my assignment. The given code below are from my lecturer for tips. I am not good with C++ but I would appreciate anyone keen to guide me to do it.



Classes to Create

Words in italics indicate what you MUST call your classes, methods or fields if you wish to receive marks for your effort.
Create a 'Word' class

 Fields:
o word (string) The word in the dictionary
o definition (string)
o usageFrequency (integer)

 Methods:
o Getters for word & definition
o Getter and Setter for usageFrequency
o calculateScrabbleScore() which returns an integer
o isHyphenated return true if the word has a hyphen
o isRareWord() which returns true if usage frequency <= 1
o isPalindrome() which return true if the word is a palindrome
o isVerb(); returns false, unless the class is a verb
o isNoun(); returns false, unless the class is a noun

Create the following classed which inherit from Word
 Noun
 Verb
 Adverb
 Adjective
 MiscWord

Create a Preposition class which inherits from MiscWord

Create a ProperNoun class which inherits from Noun

 The getter for the word field when called for this class should return a word with the first letter capitalised

Create the NounAndVerb class which inherits from Noun and Verb using multiple inheritances;
 isVerb() and isNoun() methods will return true
Create a Dictionary class which
 maintains an array of Word objects
 loads the dictionary file into its array of Word objects
 performs the assignment tasks
 provides the methods:
o getTotalNumberOfWords()
o loadDictionary() - (loads the dictionary file into its array of Word objects)



#include <iostream>
#include<string>
#include <fstream>
#include <ctime>

using namespace std;
#define MAX_WORDS 106184


struct Word {
string word;
string definition;
int usageFrequency;

//Constructor
Word(const string &theWord, const string &theDefinition)
{
word = theWord;
definition = theDefinition;
usageFrequency = 0;
}
};

int main(int argc, char* argv[])
{
string dictionaryFileName = "dictionary.txt"; //name of the dicionary file
Word *myWords[MAX_WORDS]; //array of 'Word' pointers
int wordCount = 0; //number of words loaded

//attempt to open the file
std::ifstream dictionaryFile(dictionaryFileName);

//check if the file was opened
if(dictionaryFile.is_open())
{
//start a timer (clock_t is normaly a 'long')
std::clock_t start = std::clock();

//load the file
cout << "Loading the dictionary";
std::string word, definition, type, blank;

while (std::getline(dictionaryFile, word) &&
std::getline(dictionaryFile, definition) &&
std::getline(dictionaryFile, type) &&
std::getline(dictionaryFile, blank))
{

myWords[wordCount] = new Word(word, definition);
wordCount++;

//show a progress bar
if(wordCount % (MAX_WORDS/10) == 0) {
cout << '.';
}
}

//close the file
dictionaryFile.close();

//let the user know what happend
double duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; //measure duration
cout << endl <<"Done (" << wordCount << " words in " << duration << " seconds)." << endl << endl;

string searchWord = myWords[wordCount/2]->word;

//search for the word
cout << "Testing word search for: " << searchWord << endl;
start = std::clock(); //restart the clock
int wordIndex = 0;
while(myWords[wordIndex]->word.compare(searchWord) != 0) {
wordIndex++;
}

//show the result of the search
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; //measure duration
cout << "(in " << duration << "seconds) " << myWords[wordIndex]->definition << endl << endl;
}
else
{
//normally this means the file was not found, copy the file to your solution!
cout <<"ERROR: Could not open " << dictionaryFileName << endl;
}

//done
system("pause");

}
Topic archived. No new replies allowed.