fork download
  1. Dictionary::Dictionary() {
  2. wordCount = 0;
  3. dictionaryFileName = "dictionary.txt";
  4. //attempt to open the file
  5. ifstream dictionaryFile(dictionaryFileName);
  6. //check if the file was opened
  7. if (dictionaryFile.is_open()) {
  8. //start a timer (clock_t is normaly a 'long')
  9. clock_t start = clock();
  10. //load the file
  11. cout << "Loading the dictionary";
  12. string word, definition, type, blank;
  13. Word* fromRecord(const string &theWord,
  14. const string &theDefinition,
  15. const string &theType)
  16. {
  17.  
  18. if (theType.compare("v") == 0) {
  19. return new Verb(theWord, theDefinition);
  20. }
  21. else if (theType.compare("n") == 0) {
  22. return new Noun(theWord, theDefinition);
  23. }
  24. else if (theType.compare("adv") == 0) {
  25. return new adVerb(theWord, theDefinition);
  26. }
  27. else
  28. {
  29. cout << "your error message";
  30. return NULL;
  31. }
  32. }
  33.  
  34. while (getline(dictionaryFile, word) &&
  35. getline(dictionaryFile, definition) &&
  36. getline(dictionaryFile, type) &&
  37. getline(dictionaryFile, blank))
  38. {
  39. myWords[wordCount] = fromRecord(word, definition, type);
  40. wordCount++;
  41. }
  42.  
  43. //show a progress bar
  44. if (wordCount % (MAX_WORDS / 10) == 0) {
  45. cout << '.';
  46. }
  47.  
  48. //close the file
  49. dictionaryFile.close();
  50. //let the user know what happend
  51. double duration = (std::clock() - start) / (double) CLOCKS_PER_SEC;
  52. //measure duration
  53. cout << endl << "Done (" << wordCount << " words in " << duration << "seconds)." << endl << endl;
  54. string searchWord = myWords[wordCount / 2]->getWord();
  55. //search for the word
  56. cout << "Testing word search for: " << searchWord << endl;
  57. start = std::clock(); //restart the clock
  58. int wordIndex = 0;
  59. while (myWords[wordIndex]->getWord().compare(searchWord) != 0) {
  60. wordIndex++;
  61. }
  62. //show the result of the search
  63. duration = (std::clock() - start) / (double) CLOCKS_PER_SEC; //measureduration
  64. cout << "(in " << duration << "seconds) " <<
  65. myWords[wordIndex]->getDefinition() << endl << endl;
  66. }
  67. else {
  68. //normally this means the file was not found, copy the file to yoursolution!
  69. cout << "ERROR: Could not open " << dictionaryFileName << endl;
  70. }
  71. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘Dictionary’ does not name a type
 Dictionary::Dictionary() {
 ^
stdout
Standard output is empty