1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tester [92]
3 years ago
15

Now you are ready to implement a spell checker by using or quadratic. Given a document, your program should output all of the co

rrectly spelled words, labeled as such, and all of the misspelled words. For each misspelled word you should provide a list of candidate corrections from the dictionary, that can be formed by applying one of the following rules to the misspelled word:
a) Adding one character in any possible position
b) Removing one character from the word
c) Swapping adjacent characters in the word
Your program should run from the command line as follows:
% ./spell_check
You will be provided with a small document named document1_short.txt, document_1.txt,
and a dictionary file with approximately 370k words named wordsEnglish.txt.
As an example, your spell checker should correct the following mistakes.
deciive -> decisive (Case A)
deciasion -> decision (Case B)
ocunry -> counry (Case C)
//spell_check.cc file
#include "quadratic_probing.h"
#include
#include
#include
using namespace std;
int testSpellingWrapper(int argument_count, char** argument_list) {
const string document_filename(argument_list[1]);
const string dictionary_filename(argument_list[2]);
// Call functions implementing the assignment requirements.
// HashTableDouble dictionary = MakeDictionary(dictionary_filename);
// SpellChecker(dictionary, document_filename);
return 0;
}
// Sample main for program spell_check.
// WE WILL NOT USE YOUR MAIN IN TESTING. DO NOT CODE FUNCTIONALITY INTO THE
// MAIN. WE WILL DIRECTLY CALL testSpellingWrapper. ALL FUNCTIONALITY SHOULD BE
// THERE. This main is only here for your own testing purposes.
int main(int argc, char** argv) {
if (argc != 3) {
cout << "Usage: " << argv[0] << " "
<< endl;
return 0;
}
testSpellingWrapper(argc, argv);
return 0;
}

//quadratic_probing.h file
#ifndef QUADRATIC_PROBING_H
#define QUADRATIC_PROBING_H
#include
#include
#include
namespace {
// Internal method to test if a positive number is prime.
bool IsPrime(size_t n) {
if( n == 2 || n == 3 )
return true;
if( n == 1 || n % 2 == 0 )
return false;
for( int i = 3; i * i <= n; i += 2 )
if( n % i == 0 )
return false;
return true;
}
// Internal method to return a prime number at least as large as n.
int NextPrime(size_t n) {
if (n % 2 == 0)
++n;
while (!IsPrime(n)) n += 2;
return n;
}
} // namespace
// Quadratic probing implementation.
template
class HashTable {
public:
enum EntryType {ACTIVE, EMPTY, DELETED};
explicit HashTable(size_t size = 101) : array_(NextPrime(size))
{ MakeEmpty(); }
bool Contains(const HashedObj & x) const {
return IsActive(FindPos(x));
}
void MakeEmpty() {
current_size_ = 0;
for (auto &entry : array_)
entry.info_ = EMPTY;
}
bool Insert(const HashedObj & x) {
// Insert x as active
size_t current_pos = FindPos(x);
if (IsActive(current_pos))
return false;
array_[current_pos].element_ = x;
array_[current_pos].info_ = ACTIVE;
// Rehash; see Section 5.5
if (++current_size_ > array_.size() / 2)
Rehash();
return true;
}
bool Insert(HashedObj && x) {
// Insert x as active
size_t current_pos = FindPos(x);
if (IsActive(current_pos))
return false;
array_[current_pos] = std::move(x);
array_[current_pos].info_ = ACTIVE;
// Rehash; see Section 5.5
if (++current_size_ > array_.size() / 2)
Rehash();
return true;
}
bool Remove(const HashedObj & x) {
size_t current_pos = FindPos(x);
if (!IsActive(current_pos))
return false;
array_[current_pos].info_ = DELETED;
return true;
}
private:
struct HashEntry {
HashedObj element_;
EntryType info_;
HashEntry(const HashedObj& e = HashedObj{}, EntryType i = EMPTY)
:element_{e}, info_{i} { }
HashEntry(HashedObj && e, EntryType i = EMPTY)
:element_{std::move(e)}, info_{ i } {}
};
std::vector array_;
size_t current_size_;
bool IsActive(size_t current_pos) const
{ return array_[current_pos].info_ == ACTIVE; }
size_t FindPos(const HashedObj & x) const {
size_t offset = 1;
size_t current_pos = InternalHash(x);
while (array_[current_pos].info_ != EMPTY &&
array_[current_pos].element_ != x) {
current_pos += offset; // Compute ith probe.
offset += 2;
if (current_pos >= array_.size())
current_pos -= array_.size();
}
return current_pos;
}
void Rehash() {
std::vector old_array = array_;
// Create new double-sized, empty table.
array_.resize(NextPrime(2 * old_array.size()));
for (auto & entry : array_)
entry.info_ = EMPTY;
// Copy table over.
current_size_ = 0;
for (auto & entry :old_array)
if (entry.info_ == ACTIVE)
Insert(std::move(entry.element_));
}
size_t InternalHash(const HashedObj & x) const {
static std::hash hf;
return hf(x) % array_.size( );
}
};
#endif // QUADRATIC_PROBING_H
Computers and Technology
1 answer:
Harlamova29_29 [7]3 years ago
5 0

Answer:

Sorry po idont know po ehhh sorry

You might be interested in
Why is it important to enforce access controls and to keep logs regarding who has access to data closets
vlada-n [284]

Answer:

To ensure that in the event of a failure or breach, there is a record of when the equipment was accessed.

Explanation:

Hope this helps:)....if it don't then sorry for wasting your time and may God bless you:)

8 0
3 years ago
Read 2 more answers
Which operating system became obsolete with the arrival of more advanced graphical user interfaces
Alexandra [31]

Answer:

Single User/ Single Tasking Operating System

8 0
4 years ago
Please tell fast plzzzzz​
AURORKA [14]

Answer:

binary sequences

Explanation:

hahxvdavqkqbduvhsyax

7 0
3 years ago
How do I report a user? (https://brainly.com/profile/TheBrainHelper-20043487)
Veseljchak [2.6K]

Answer:

I don't think you can report someone but you always can report the question

7 0
3 years ago
Read 2 more answers
Suppose that you want to write a program that inputs customer data including name, zipCode, balance, and regionNum. At the end o
Misha Larkins [42]

Answer:

The answer to the given question is option "b".

Explanation:

In this question, we use option b because this option will provide a list of the number of customers in 12 each region owing more than $1,000.  and other option is not correct that will be described as:

  • In the option a, It will provide the balance of the customer.
  • In the option c, It will decrease the list of region number.  
  • In the option d, It will provide the total balance of the regions.  

That's why the answer to this question is option b which is "customerCount[regionNum] = customerCount[regionNum] +1".

3 0
3 years ago
Other questions:
  • A(n) __________________ device is a breath analyzer on your vehicle that is electronically connected to the ignition.
    11·1 answer
  • You are the network adminstrator for your company your network consists of two active directory domains research.westsim.local a
    12·1 answer
  • Which characteristic of a relational database distinguishes it from a flat file?
    5·1 answer
  • A company has a website that has seen a large increase in visitors and they are concerned that if the trend continues, the web s
    13·1 answer
  • Write a function called random_marks. random_marks should #take three parameters, all integers. It should return a #string. # #T
    13·1 answer
  • Why vechiles Tyres are black in colour?​
    14·1 answer
  • Layers allow you to work with one element of an image without disturbing the others true or false​
    15·1 answer
  • Use the factorial operation to evaluate 4!.<br><br> 24<br><br> 1<br><br> 4<br><br> 10
    10·1 answer
  • What is the full form of the OS?​
    15·2 answers
  • 2. Which of these Is NOT part of the definition of Electricity?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!