imported lab skeletons
This commit is contained in:
parent
4fc8b6c771
commit
e4df45f4a9
47 changed files with 15122 additions and 87 deletions
22
lab2/dictionary.cc
Normal file
22
lab2/dictionary.cc
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include "word.h"
|
||||
#include "dictionary.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
Dictionary::Dictionary() {
|
||||
}
|
||||
|
||||
bool Dictionary::contains(const string& word) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<string> Dictionary::get_suggestions(const string& word) const {
|
||||
vector<string> suggestions;
|
||||
return suggestions;
|
||||
}
|
||||
15
lab2/dictionary.h
Normal file
15
lab2/dictionary.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Dictionary {
|
||||
public:
|
||||
Dictionary();
|
||||
bool contains(const std::string& word) const;
|
||||
std::vector<std::string> get_suggestions(const std::string& word) const;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
38
lab2/spell.cc
Normal file
38
lab2/spell.cc
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cctype>
|
||||
#include "dictionary.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
void check_word(const string& word, const Dictionary& dict)
|
||||
{
|
||||
if (dict.contains(word)) {
|
||||
cout << "Correct." << endl;
|
||||
} else {
|
||||
vector<string> suggestions = dict.get_suggestions(word);
|
||||
if (suggestions.empty()) {
|
||||
cout << "Wrong, no suggestions." << endl;
|
||||
} else {
|
||||
cout << "Wrong. Suggestions:" << endl;
|
||||
for (const auto& w : suggestions) {
|
||||
cout << " " << w << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
Dictionary dict;
|
||||
string word;
|
||||
while (cin >> word) {
|
||||
transform(word.begin(), word.end(), word.begin(), ::tolower);
|
||||
check_word(word, dict);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
16
lab2/word.cc
Normal file
16
lab2/word.cc
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include "word.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
Word::Word(const string& w, const vector<string>& t) {}
|
||||
|
||||
string Word::get_word() const {
|
||||
return string();
|
||||
}
|
||||
|
||||
unsigned int Word::get_matches(const vector<string>& t) const {
|
||||
return 0;
|
||||
}
|
||||
21
lab2/word.h
Normal file
21
lab2/word.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef WORD_H
|
||||
#define WORD_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Word {
|
||||
public:
|
||||
/* Creates a word w with the sorted trigrams t */
|
||||
Word(const std::string& w, const std::vector<std::string>& t);
|
||||
|
||||
/* Returns the word */
|
||||
std::string get_word() const;
|
||||
|
||||
/* Returns how many of the trigrams in t that are present
|
||||
in this word's trigram vector */
|
||||
unsigned int get_matches(const std::vector<std::string>& t) const;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue