Here is all of the code used:
#include <cstdlib> // Includes
#include <iostream> // Includes
#include <fstream> // Includes
#include <string> // Includes
#include <vector> // Includes
#include <algorithm> // Includes
using namespace std; // Using the standard namespace
string sRead; // Declare variables
ifstream scrambled; // Declare variables
ofstream unscrambled; // Declare variable
ifstream wordslist; // Declare variable
ofstream newwords;
string wordA; // Declare variables
string sLine1; // Declare variables
string sW; // Declare variables
string sC; // Declare variables
void CountWords()
{
}
int main() // Start the main() function
{ // Start the main function
cout << "Please type 'sort' to organize the words in wordlist.txt by name and delete;\nduplicates, 'scramb' to unscramble the words in scrambled.txt while using\nthe words in wordlist.txt, 'count' to count the words in wordlist.txt, or \n'quit' to exit.\n" << endl; // Output instructions
cin >> sW;
if (sW == "sort") // If sorting
{ // Start the sorting code
cout << endl;
string temp;
string temp1;
string temp2;
string temp3;
string temp4;
vector<string> wordlist;
wordslist.open("wordlist.txt");
newwords.open("newwordlist.txt");
while (!wordslist.eof())
{
wordslist >> temp;
wordlist.push_back(temp);
}
cout << "** Commencing Word Sort!! **" << endl;
for (int p=0;p<wordlist.size();p++)
{
temp1 = wordlist[p];
cout << "Now sorting word " << p + 1 << " of " << wordlist.size() << endl;
for (int j=0;j<wordlist.size();j++)
{
temp2 = wordlist[j];
if (temp1==temp2 && p!=j)
{
wordlist[j]="";
}
}
}
for (int p=0;p<wordlist.size();p++)
{
if (wordlist[p]!="")
{
temp3 = wordlist[p];
newwords << temp3 << endl;
}
}
cout << "** Finished Sorting Words!! **" << endl;
wordslist.close();
newwords.close();
wordlist.clear();
} else if (sW == "scramb") // End if sorting code and start if unscrambling code
{ // Start the unscramble code
cout << "** Starting to Unscramble the Words!! **" << endl;
fstream wordslist;
cout << endl;
vector<string> wordlist;
vector<string> scrambledwords;
vector<string> sortedwordlist;
string temp;
scrambled.open("scrambled.txt");
while (!scrambled.eof())
{
scrambled >> temp;
scrambledwords.push_back(temp);
}
scrambled.close();
wordslist.open("wordlist.txt");
unscrambled.open("unscrambled.txt");
wordlist.resize(0);//wordlist resize spot
while (!wordslist.eof())
{
wordslist >> temp;
wordlist.push_back(temp);
}
temp4 = sortedwordlist.size();
sortedwordlist.resize(0);//sorted word list resize spot
for (int p=0;p<wordlist.size();p++)
{
sortedwordlist.push_back(wordlist[p]);
}
for (int p=0;p<sortedwordlist.size();p++)
{
sort(sortedwordlist[p].begin(), sortedwordlist[p].end());
}
for (int p=0;p<scrambledwords.size();p++)
{
sort(scrambledwords[p].begin(), scrambledwords[p].end());
}
for (int p=0;p<sortedwordlist.size();p++)
{
for (int j=0;j<scrambledwords.size();j++)
{
if (scrambledwords[j] == sortedwordlist[p])
{
cout << wordlist[p] << endl;
unscrambled << wordlist[p] << ",";
}
}
}
cout << "** Finished Unscrambling the Words!! **" << endl;
wordslist.close();
unscrambled.close();
} else if (sW == "quit") // End the uncramble code and start quit the program code
{ // Start quit the program code
return EXIT_SUCCESS; // Command to return from the main() function and exit
} else if (sW == "count") // End quit the program code and start if count code
{
cout << "** Beginning to Count the Words!! **" << endl;
string temp;
vector<string> wordlist;
wordslist.open("wordlist.txt");
newwords.open("newwordlist.txt");
while (!wordslist.eof())
{
wordslist >> temp;
wordlist.push_back(temp);
}
wordslist.close();
cout << "** Finished Counting the Words!! **" << endl;
cout << "There are " << wordlist.size() << " words in wordlist.txt." << endl;
} else {cout << "** No valid answer!! **" << endl;} // End the count code and start if no valid answer code
system("PAUSE");
return 0;
} // End the main() function
This post has been edited by devilsson2010: 20 January 2008 - 03:32 PM

New Topic/Question
Reply




MultiQuote





|