how to write a spell checking program in c++

Discussion in 'C++' started by c1one, Feb 24, 2009.

  1. c1one

    c1one New Member

    Joined:
    Feb 24, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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);
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  3. c1one

    c1one New Member

    Joined:
    Feb 24, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    the problem is that i dont know how to do it :( would be cool if some1 could do 1 for me.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Where did you get the assignment from, is it in a book, or are you on a course, or something else?
     
  5. c1one

    c1one New Member

    Joined:
    Feb 24, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    assignment
     
  6. c1one

    c1one New Member

    Joined:
    Feb 24, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    was an assignment for a class.
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  8. c1one

    c1one New Member

    Joined:
    Feb 24, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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 .
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  10. c1one

    c1one New Member

    Joined:
    Feb 24, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    ok thanks you can delete this thread now
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice