QT/C++ | Word Unscrambler

QT/C++ | Word_Unscrambler



Hello peeps! Lord Hypersonic greets you. Today I am here with a new Qt project. Yeah, it's a GUI program. Do you remember previous c++ program to solve jumble words? The logic of this program is the same as that program.

  1. First, the user will be asked to enter the jumbled word in a line edit widget.
  2. Click the "Solve" button. If the button is clicked, call slot on_Button_Solve_clicked() ).
  3. Clear the list widget
  4. Making QString variable QJWord equal to text in line edit widget
  5. Declare QString variable sortedJWord and making equal to sortString(QJWord)
  6. sortString() function work as follows, Function declaration QString sortString (QString word); Defined as :-
    1. Making integer variable len equal to the size of word (word.length()).
    2. Starting for loop from i = 0 to i = len, and i=i+1 after each iteration. This loop is for making lower case alpha to uppercase alpha. Using member functions of QString class: isLower and toUpper
    3. Declare a string variable w and make it equal to word.toStdString(), to convert QString to string.
    4. Declaring integer array TEMP[len]. Start a loop to initialize the array with 0.
    5. Start a for loop from i = 0  to i = len and increase value of i after each iteration. Making TEMP[i] = w[i] to assign TEMP[i] value of ascii code of character at w[i]
    6. Now sort the array TEMP, you can use any sorting technique to sort array TEMP
    7. Declare a string variable J.
    8. Start a loop from i =0 to i = len (i = i+1 after each iteration). add charater at the end of J at ascii code TEMP[i] ( J.push_back(TEMP[i]) ). 
    9. Convert string to QString using a member function fromStdString(&string). QString Jumble = QString::toStdString(J);
    10. Return Jumble
  7. Declare QFile object file. And make the file equal to words.txt (a text file which contains all English words). 
  8. Check if the file is open. 
  9. If the file is open:-
    1. Declare a text stream [ QTextStream FileLine ] and make it equal to QFile variable file. [ QTextStream FileLine (&file) ].
    2. Start while loop till end of the text stream.
    3. Declare a QString variable SFileL and make it equal to FileLine.readline(). To read the file line by line.
    4. Sort the SFileL using sortString() function. Make QString variable sortedWORD equal to sortString(SFileL)
    5. If sortedWORD is equal to sortedJWord. Then print it on the screen by adding as an item to list widget. ( ui->listWidget_SOLVED->addItem(SFileL) ).
  10. Close the file. 
  11. If not able to find words.txt then display a warning message box saying Failed to open words.txt.
This is the algorithm I use to make this program. You can download the setup file of this program by clicking here.

Download project files (source code) from GitHub.

No comments

Powered by Blogger.