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
Consider the following program that monitors two sensors. Here sensor1 and sensor2 denote
dusya [7]

Answer:

Check the explanation

Explanation:

a)

It is a technical impossible for the update in the value of sensor1 in ISR while the main function is still evaluating whether sensor1 is with a fault or not at the point of execution in the critical section block because in this block no other instructions are not executed until the completion of instructions in the critical section.

Also semaphores are used to execute instructions when they are get lock to execute. if we write the code in operating system in such a way that at any instant of time shared resources cannot be executed in parallel, then only it is not possible to update ISR value of sensor1 while main function checking for sensor1 faultiness.

-> It is possible that  to update ISR value of sensor1 while main function checking for sensor1 faultiness if operating system and compilers are coded for parallel execution even though shared resources.

for example:

int i=5;

main()

if (i==5)

{print "i is %d",i}

other()

i=7;

//if above program executes parallel boh main() and other() functions are parallel executed

then at first clock cycle in main method i=5 so goes to next instruction print.

but in the first clock cycle also in other method i value changes to 7.

so in the next clock cycle in main method result as " i is 7.

b)

if there is an occurrence of error related to only for faulty value of sensor 1 or sensor 2 then only it is possible for this code would report "Sensor1 faulty" or "Sensor2 faulty" when there is no error related to other issues.

Like power interrupt etc.

if a spurious error can cause not only sensor1 or sensor2 to be a faulty value but also interrupting whole program or suspending entire program etc may possible for this code would not report  "Sensor1 faulty" or "Sensor2 faulty".

c)

if we Assume the interrupt source for ISR() is timer-driven , then there are conditions could cause this code to never check whether sensors are faulty or not.

timer driven means set a clock for its execution how can we set the clock. if we set clock for ISR() method to stop the entire program or repeated continuously at setting up interrupts and enabling interrupts.

these two conditions 1)set clock to stop the program would not enter into checking sensors faultiness.

2)set the clock to spare entire time to execute  at setting up interrupts and enabling interrupts. repeated continuously.

It means never run ":while(1) {} " block instructions for checking faultiness of the sensors.

5 0
3 years ago
Create a geometry application For this exercise you will create a module named ‘shapes.py’ and a program that uses it. The modul
Maurinko [17]

Answer:

See explaination

Explanation:

# shapes.py

import math class Circle: def __init__(self, radius = 0): self.__radius = radius self.__area = math.pi * self.__radius ** 2 self.__circumference = 2 * math.pi * self.__radius def set_radius(self, radius): self.__radius = radius self.__area = math.pi * self.__radius ** 2 self.__circumference = 2 * math.pi * self.__radius def get_radius(self): return self.__radius def get_area(self): return self.__area def get_circumference(self): return self.__circumference class Rectangle: def __init__(self, length = 0, breadth = 0): self.__length = length self.__breadth = breadth self.__calc_area() self.__calc_perimeter() def __calc_area(self): self.__area = self.__length * self.__breadth def __calc_perimeter(self): self.__perimeter = 2 * (self.__length + self.__breadth) def set_length(self, length): self.__length = length self.__calc_area() self.__calc_perimeter() def set_breadth(self, breadth): self.__breadth = breadth self.__calc_area() self.__calc_perimeter() def get_length(self): return self.__length def get_breadth(self): return self.__breadth def get_area(self): return self.__area def get_perimeter(self): return self.__perimeter

# testShapes.py (Main program)

import shapes if __name__ == "__main__": print("a. Circle") print("b. Rectangle") choice = input("\nChoose a Shape to continue: ") if choice == "a": radius = int(input("\nEnter Radius of the Circle: ")) myCircle = shapes.Circle(radius) print("\nArea of Circle:", myCircle.get_area()) print("Circumference of Circle:", myCircle.get_circumference()) reset = input("Do you want to change Radius (y/n): ") if reset == "y" or reset == "Y": radius = int(input("\nEnter new Radius of the Circle: ")) myCircle = shapes.Circle(radius) print("\nArea of Circle:", myCircle.get_area()) print("Circumference of Circle:", myCircle.get_circumference()) elif choice == "b": length = int(input("\nEnter length of Rectangle: ")) breadth = int(input("Enter breadth of Rectangle: ")) myRectangle = shapes.Rectangle(length, breadth) print("\nArea of Rectangle:", myRectangle.get_area()) print("Perimeter of Rectangle:", myRectangle.get_perimeter()) reset = input("Do you want to change Length and Breadth (y/n): ") if reset == "y" or reset == "Y": length = int(input("\nEnter new length of Rectangle: ")) breadth = int(input("Enter new breadth of Rectangle: ")) myRectangle = shapes.Rectangle(length, breadth) print("\nArea of Rectangle:", myRectangle.get_area()) print("Perimeter of Rectangle:", myRectangle.get_perimeter()) else: print("Invalid choice!!! \'", choice, "\'\nExiting...")

7 0
3 years ago
Drag the tiles to the correct boxes to complete the pairs. Match the tools that you can use while solving a problem with their c
Lana71 [14]

1. A

2. Algorithm

3 Flowchart

4. Heuristic


Sorry that it's a bit late. Hopefully this is still of some use to you.

6 0
3 years ago
Read 2 more answers
You need to create a basic report from a query. The report will contain a list of employees in the human resources division. Whi
dedylja [7]
The first one is the most suitable one to use
3 0
3 years ago
Bruce realizes he's getting a cramp in his neck after texting with his buddy for several minutes. he puts the phone down and tak
Arlecino [84]

Answer:Tech Neck

Explanation:

Tech Neck is when you are looking down to a phone for too long and you get a cramp in your neck

6 0
1 year ago
Other questions:
  • Melissa and Sue want to show a presentation to twenty employees using a presentation while using a projector. They learn that th
    12·2 answers
  • Many of today’s digital devices operate on battery power supplied by what kind of ion batteries.
    15·1 answer
  • C. to which cache block will the memory address 0x000063fa map
    14·1 answer
  • Which process refers to starting up a computer?<br> is the process of starting a computer.
    9·2 answers
  • ____________________ are compromised systems that are directed remotely (usually by a transmitted command) by the attacker to pa
    7·2 answers
  • Two strings, and , are called anagrams if they contain all the same characters in the same frequencies. For example, the anagram
    13·1 answer
  • A business has recently deployed laptops to all sales employees. The laptops will be used primarily from home offices and while
    14·1 answer
  • PLZ ANSWER ALL MY QUESTION. Which line of code will display the variable num rounded to the nearest tenth?
    14·1 answer
  • Which of the following statements are true concerning abstraction and refinement? Select 3 options:
    14·1 answer
  • true or false You are able to change the formatting of a table after it is inserted into a placeholder.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!