Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how to write a spell checking program in c++ (http://www.go4expert.com/forums/write-spell-checking-program-cpp-t16323/)

c1one 24Feb2009 23:36

how to write a spell checking program in c++
 
Spell Checker
You will write a program that reads a file and performs a spell check on the file. You should specify the name of the file from the command line.
Example
SpellCheck example.txt
Your program should read in a word list to use for the spell check. You can find a word list online using google or some other search engine. A suitable word list should list a single word per line in the file. You will read this word list into some data structure. An array can be used, but you will need to calculate the size of the array before running the program. You may also want to look into an alternate data structure like a vector or list or hash table. Once you read the dictionary into memory, you will read the file to be checked, and compare each word to the dictionary to determine if the word is in the list. If the word is not in the list, you should print the word and its location in the text. You do not need to offer suggestions for the incorrect word, just identify it as misspelled.
For instance, given the following input:
I lvoe programming class. It is teh best!
You program should output
Misspelled Words
Location Word
2 lvoe
7 teh
__________________________________________________ ______________
so basically this is how far i got that i realized i was confused can some1 help me out but like keep the code as simple as possible
Code:

#include <iostream>
#include <conio.h>
#include <fstream>
#include <cstring>

using namespace std;
int main()
{
Int item[5]
Int I
ifstream inFile;
inFile.open("C:\\temp\\datafile.txt");
Char str[30];
Cin.get(str,31);


xpi0t0s 25Feb2009 03:39

Re: how to write a spell checking program in c++
 
There are two key things you need to do in this program:
(1) loop over all the words in the input
(2) determine whether or not a given word is in your input list.

So where I'd start is to create a program that does each of these separately. Write a function that loops over the input string and prints each word. Don't do anything more than that yet; make sure this works first.

Then add a new function that checks for the existence of a given word in the data file. Just write it so that the user can enter a word and that it looks through the data file and gives you a yes or no output. Call this function *instead of* the one you wrote before.

Then when you've got both of those working you can look at interfacing the two functions with each other, so that the overall program asks for a string, loops through the words, checks each one off against the list then displays the word if it isn't, or does nothing if it is. You'll also need a counter so that you can display the 2 and 7 in the example output you gave.

c1one 25Feb2009 03:58

Re: how to write a spell checking program in c++
 
Quote:

Originally Posted by xpi0t0s (Post 43394)
There are two key things you need to do in this program:
(1) loop over all the words in the input
(2) determine whether or not a given word is in your input list.

So where I'd start is to create a program that does each of these separately. Write a function that loops over the input string and prints each word. Don't do anything more than that yet; make sure this works first.

Then add a new function that checks for the existence of a given word in the data file. Just write it so that the user can enter a word and that it looks through the data file and gives you a yes or no output. Call this function *instead of* the one you wrote before.

Then when you've got both of those working you can look at interfacing the two functions with each other, so that the overall program asks for a string, loops through the words, checks each one off against the list then displays the word if it isn't, or does nothing if it is. You'll also need a counter so that you can display the 2 and 7 in the example output you gave.

the problem is that i dont know how to do it :( would be cool if some1 could do 1 for me.

xpi0t0s 25Feb2009 04:18

Re: how to write a spell checking program in c++
 
Where did you get the assignment from, is it in a book, or are you on a course, or something else?

c1one 25Feb2009 08:07

Re: how to write a spell checking program in c++
 
assignment

c1one 25Feb2009 08:07

Re: how to write a spell checking program in c++
 
was an assignment for a class.

xpi0t0s 25Feb2009 13:23

Re: how to write a spell checking program in c++
 
OK, so you're not going to have been given this cold. Look through your course notes and I'm sure you'll find code examples that can be adapted to cover this. If there really is nothing then you should complain to the tutor for doing a duff job and giving you assignments for which he hasn't already given you the tools you need to solve it.

c1one 25Feb2009 13:28

Re: how to write a spell checking program in c++
 
yeah well i asked the teacher for help and he told me to read the book.. so i did and did not find anything hence i am here.. itd be helpful if someone here was so nice as to write this code for me.. thanks in advance .

xpi0t0s 25Feb2009 14:20

Re: how to write a spell checking program in c++
 
Well, programming is a skill learnt by doing, not by looking at other people's completed examples.
If I were to write this code for you then that'd get you absolutely nowhere; you wouldn't learn anything, and next time you had an assignment you'd be just as stuck and back here for someone to be "so nice as to help you fail the course", because if there's a final exam where you have no internet access then you'll have absolutely no chance.

So, no, you'll have to write this code yourself. As your tutor says, read the book, and I'm sure you'll find stuff in there that will help. I understand you want a quick fix, but that isn't how programming works. What book is it? If I have access to a copy somewhere I might be able to give you some pointers.

c1one 26Feb2009 08:44

Re: how to write a spell checking program in c++
 
ok thanks you can delete this thread now


All times are GMT +5.5. The time now is 10:06.