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

using std::map; using std::set; using std::pair; using std::string; using std::i

ID: 3804693 • Letter: U

Question


using std::map;
using std::set;
using std::pair;
using std::string;
using std::ifstream;
using std::stringstream;
using std::getline;

SpellChecker::SpellChecker() {}

SpellChecker::SpellChecker(string lang) {}

SpellChecker::SpellChecker(string lang, string valid_words_filename, string misspelled_filename)
{
   ifstream correct_words(valid_words_filename.c_str());
   if (correct_words)
   {
       string s;
       while (getline(correct_words, s))
       {
           valid_words.insert(s);
       }
   }

   ifstream wrong_words(misspelled_filename.c_str());
   if (wrong_words)
   {
       string s1, s2;
       while (wrong_words >> s1)
       {
           getline(wrong_words, s2);
           misspelled.insert(pair<string, string>(s1, s2));
       }
   }

}
bool SpellChecker::loadValidWords(string filename)
{
   ifstream correct_words(filename.c_str());
   if (correct_words)
   {
       valid_words.clear();
       string s;
       while (getline(correct_words, s))
       {
           valid_words.insert(s);
       }
       return true;
   }
   return false;
}
bool SpellChecker::loadMisspelledWords(string filename)
{
   ifstream wrong_words(filename.c_str());
   if (wrong_words)
   {
       misspelled.clear();
       string s1, s2;
       while (wrong_words >> s1)
       {
           getline(wrong_words, s2);
           s2.erase(s2.begin());
           misspelled.insert(pair<string, string>(s1, s2));
       }
       return true;
   }
   return false;
}
void SpellChecker::setBeginMarker(char begin)
{
   begin_mark = begin;
}

void SpellChecker::setEndMarker(char end)
{
   end_mark = end;
}

char SpellChecker::getBeginMarker()
{
   return begin_mark;
}

char SpellChecker::getEndMarker()
{
   return end_mark;
}

string SpellChecker::fixUp(string sentence)
{
   stringstream buff(sentence);
   string result;
   string tmp;
   while (buff >> tmp)
   {
       string word;
       for (int i = 0; i < tmp.size(); i++)
       {
           if (tmp[i] >= 'A' && tmp[i] <= 'Z')
               word.push_back(tmp[i] - ('Z' - 'z'));
           else
               word.push_back(tmp[i]);
       }
       // if word is in correct words we just add it to result
       if (valid_words.find(word) != valid_words.end()) result += word + ' '; else

      
:
#include"WordCounts.h"
#include<sstream>
#include<vector>
#include<algorithm>

using std::pair;
using std::vector;
using std::stringstream;
using std::sort;


void WordCounts::countWords(string sentence)
{
   stringstream buff(sentence);
   string tmp;
   while (buff >> tmp)
   {
       string word;
       for (int i = 0; i < tmp.size(); i++)
       {
           if (tmp[i] >= 'A' && tmp[i] <= 'Z')
               word.push_back(tmp[i] - ('Z' - 'z'));
           else
           if (tmp[i] >= 'a' && tmp[i] <= 'z')
               word.push_back(tmp[i]);
       }
       if (words.find(word) == words.end())
           words.insert(pair<string, int>(word, 1));
       else words[word]++;
   }
}

int WordCounts::getCount(string word)
{
   return words[word];
}

void WordCounts::resetCounts()
{
   words.clear();
}


bool myfunction(pair<int, string> i, pair<int, string> j) { return (i>j); }

int WordCounts::mostCommon(string commonWords[], int wordCount[], int n)
{
   // data stracture to sort words and count, by count
   vector<pair<int, string> > v;

   for (map<string, int>::iterator it = words.begin(); it != words.end(); it++)
   {
       v.push_back(pair<int, string>(it->second, it->first));
   }
   sort(v.begin(), v.end(), myfunction);
   for (int i = 0; i < v.size(); i++)
   {
       if (i == n) return n;
       wordCount[i] = v[i].first;
       commonWords[i] = v[i].second;
   }
   return v.size();
}

Assignment 7 zip src/SpellChecker.cpp [A7]-... COG Submitterator: CSCI 13... src-File Manager -a ty 26 Mar, 01:56 COG Submitterator: CSCI 1300 Mozilla Firefox COG Submitterator: CSCI 1300 x 150% C a search A https://web-cog-csci1300.cs.colorado.ed u submit/ COG Submitterator: CSCI 1300 Submit History About Hel Logged in as hayu9382 Logout Results Score: 56.0 of 100 Return Code: 0 Status: complete Run UUID b7e97ead-13e9-44ad-981e-85a4cd97cofd Checking for Required Functions. Checking SpellChecker class functions MISSING SpellChecker SpellChecker MISSING Spell Checker Spellchecker (string lang) Found 8 10 required functions Checking WordCounts class functions. MISSING: WordCounts: :WordCounts Found 4 5 required functions ERROR: Could not find all required functions Ensure you are using void in 1 Grading Deductions Summary COG-Web Beta (commit fe57bbd) l Code and license on GitHub l Built by Andy Sayler and Others in Boulder, CO

Explanation / Answer

//modify your constructors as follows

SpellChecker::SpellChecker() {

this->language="English"; //initializing to some default values

this->begin_mark='~';

this->end_mark='~';

}

SpellChecker::SpellChecker(string lang) {

this->language=lang;;

this->begin_mark='~';

this->end_mark='~';

}

SpellChecker::SpellChecker(.............)

{

this->language=lang;;

this->begin_mark='~';

this->end_mark='~';

}

//add this constructor in wordcount class

WordCounts::WordCounts()

{
//add some data memebers like

// initialize your vector words here

// and any data memeber you whom you woul like to give some default values

}