word ladders

This is a discussion on word ladders within the C++ Programming forums, part of the General Programming Boards category; i am supposed to write a function based off of the code i have so far that can generate the ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    30

    word ladders

    i am supposed to write a function based off of the code i have so far that can generate the 5 letter sequences that are 1 letter different from a givin input; also identify the sequences that actually works.

    im not sure how to begin this but here is code so far: (wordTest is my function i just dont have anything in it)

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <set>
    using namespace std;
    
    void wordTest(string);
    
    int main()
    {
    	set<string> myset;
    	set<string>::iterator iter;
    
    	string word, search;
    	ifstream infile;
    	infile.open("words.txt");
    
    	while (infile >> word)
    	{
    		myset.insert(word);
    	}
    
    	for (iter = myset.begin(); iter != myset.end(); iter++)
    		cout << *iter << endl;
    
    	cout << "Enter word to search for: ";
    	cin >> search;
    
    	iter = myset.find(search);
    	if (iter == myset.end())
    		cout << "That word is not in the set" << endl;
    	else
    		cout << *iter << " is in the set" << endl;
    
    	wordTest(search);
    
    
    
    	return 0;
    }
    
    void wordTest (string search)
    {

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    30
    basically i am supposed to change each letter individually of a five letter word entered from user and see if it is in my words.txt file. so for example if the user enters "tears" i need to check and see if "sears" is in the file along with every other possible word that is one letter different from "tears"

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So do that -- change every letter (why not do it in order from 'a' to 'z'?) in turn, starting at the front and working to the back.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    30
    my problem is i dont know how to change every letter...that is my question...

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    30
    how do i find all words in "words.txt" that are one letter different from the user inputted word?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by AJOHNZ View Post
    my problem is i dont know how to change every letter...that is my question...
    You've never typed "f = 5"? Or "char_var = 'q' "?

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    30
    i dont think so. if this makes it easier to understand, i am supposed to find all words in "words.txt" that are one letter different from the user inputted word...

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by AJOHNZ View Post
    i dont think so.
    Interesting. Well, you can use = to assign the value on the right to the variable on the left. For instance, I could do something like
    Code:
    deg_C = (deg_F - 32.0)/1.8;
    to change the value in the variable deg_C, or as another example, if I had a string variable word, I could use
    Code:
    word[0] = 'a';
    to change the first character in the word to the letter a.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 02:22 PM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 08:55 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21