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]
2 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]2 years ago
5 0

Answer:

Sorry po idont know po ehhh sorry

You might be interested in
Select the correct answer.
Harrizon [31]

Answer: B. judgment

Explanation: To critique a work of art, there are a 4 steps method:

<u>Description</u>: describe everything you see in the work: name of the artist, the title, what you observe, what media he/she used, the year it was created;

<u>Analysis</u>: describe how the artist uses the <u>elements of art</u> (line, shape, color, texture, space) and the <u>principles</u> <u>of</u> <u>design</u> (balance, movement, pattern, emphasis, contrast);

<u>Interpretation</u>: try to explain what is the meaning of the art, why the artist created it, what was he/she's idea for it, based on the 2 previous steps;

<u>Judgment</u> <u>or</u> <u>Evaluate</u>: make an opinion of why the art is worth it based on the other steps and give reasons for liking or disliking, its importance or the way it make you feel;

After going through each step, your evaluation or opinion will be expressed in the 4th step: Judgment.

6 0
3 years ago
As a general rule, what is the size of a brochure?
svlad2 [7]
The general size of a brochure is 8.5x11 when open or flat. Typically they are broken into three segments though!
5 0
3 years ago
Which of the following loop conditions will read all the data in the file assuming that each line in the file contains two integ
PSYCHO15rus [73]

Answer:

while(inFile >> intOne >> intTwo)

Explanation:

Options are missing but the line of code that does the illustration in the question is while(inFile >> intOne >> intTwo)

Considering two variables, intOne and intTwo

Suppose that a file location has been specified, the infile statement identifies file which could either be an external data or an in-stream data from which data should be read.

while(inFile >> intOne >> intTwo)

Declares a while loop, with the help of the inFile statement, values in the first column are entered into intOne while the second column are entered into intTwo through with the help of then input channel symbol (>>).

3 0
3 years ago
The speed of sound depends on the material the sound is passing through. Below is the approximate speed of sound (in feet per se
german

Answer:

The Java Program for the given problem is as below. Directly copy the code and run it on your machine.

Explanation:

Refer the Screenshots attached for the output.

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class TheSpeedOfSound {

public static void main(String[] s)

{

String medium;

double distance;

double time;

try{

BufferedReader choice = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter one of the following: air, water, or steel: ");

medium = choice.readLine(); // reading input i.e. air, water or steel

//check for air water and steel

if (medium.equalsIgnoreCase("air") || medium.equalsIgnoreCase("water") || medium.equalsIgnoreCase("steel")){

System.out.println("Enter the distance the sound wave will travel: ");

distance = Double.parseDouble(choice.readLine()); // read distance value if it is air water or steel

switch (medium)

{

//if medium is air

case "air":

time = distance/1100;

System.out.print("It will take " + time + " seconds.");

break;

//if medium is water

case "water":

time = distance/4900;

System.out.print("It will take " + time + " seconds.");

break;

//if medium is steel

case "steel":

time = distance/16400;

System.out.print("It will take " + time + " seconds.");

break;

}

}

else{

System.out.print("Sorry, you must enter air, water, or steel.");  

}

}

catch(Exception e){

e.printStackTrace();

}

}

}

8 0
3 years ago
Exchanging which type of data uses the least bandwidth?
Over [174]
Voice. voice uses the least bandwidth
5 0
3 years ago
Read 2 more answers
Other questions:
  • Windows uses a graphical user interface (GUI), which means: a user can carry out commands by clicking, dragging, or otherwise ma
    6·1 answer
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • Who is responsible for ensuring the security of business systems and developing strategies and safeguards against attacks by hac
    9·1 answer
  • Nikolas has a idea that he could use the compressed carbon dioxide in a fire extinguisher to propel him on his skateboard. Nikol
    13·2 answers
  • On which of the following pointing devices can you control the pointer by sliding your fingertip?
    11·1 answer
  • How is this fictional tex in the people could fly different from the nonfictional text​
    12·2 answers
  • Which of the following is a benefit, as well as a risk, associated with peer-to-peer networks?
    6·2 answers
  • Read two numbers from user input. Then, print the sum of those numbers. Hint - Copy/paste the following code, then just type cod
    9·1 answer
  • The Curiosity Rover has recently landed on Mars and likes to send Twitter updates on its progress. If a tweet is posted 10 minut
    6·1 answer
  • The Internet is based on a U.S. government project called ________. Today, the Internet is a collection of networks, tied togeth
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!