Question: Given a file of unsorted words with mixed case: read the entries in the file and sort those words into alphabetical order. The program should

Given a file of unsorted words with mixed case: read the entries in the file and sort those words into alphabetical order. The program should then prompt the user for an index, and display the word at that index. Since you must store the entire list in an array, you will need to know the length. The "List of 1000 Mixed Case Words" contains 1000 words. Note that some of these "words" have spaces, so read them one line at a time.
You are guaranteed that the words in the array are unique, so you don't have to worry about the order of, say, "bat" and "Bat."
For example, if the array contains ten words and the contents are
cat Rat bat Mat SAT vat Hat pat TAT eat
the sorted list is
bat cat eat Hat Mat pat Rat SAT TAT vat
and after sorting, the word at index 6 is Rat
You are encouraged to use this data to test your program.
The code I have is saying exception thrown at line 34 and the Int Main is underlined in green saying that the amount of bytes is too large. How do I fix this?
#include
#include
#include
#include
#include
#include
#include // Include the vector library
using namespace std;
bool isUnique(string words[], int cnt, string word);
void sort(string words[], int cnt);
int main(){
const int SIZE =1000;
string words[SIZE];
string word;
int count =0, index;
ifstream dataIn;
dataIn.open("MixedCaseWords.txt");
if (dataIn.fail())
{
cout <<"** File Not Found **";
return 1;
}
else
{
while (dataIn >> word)
{
bool b = isUnique(words, count, word);
if (!b)
{
words[count]= word;
count++;
}
}
dataIn.close();
sort(words, count);
while (true)
{
cout << "Enter Index :";
cin >> index;
if (index<0|| index>count)
{
cout <<"** Invalid.Must be between 0-"<< count <<"**"<< endl;
}
else
break;
}
cout << "After sorting, the word at index "<< index <<" is "<< words[index]<< endl;
}
return 0;
}
bool isUnique(string words[], int cnt, string word)
{
string str1, str2;
for (int k =0; k < word.length(); k++)
{
str2+= tolower(word.at(k));
}
for (int i =0; i < cnt; i++)
{
str1="";
for (int j =0; j < words[i].length(); j++)
{
str1+= tolower(words[i].at(j));
}
if (str1.compare(str2)==0)
{
return true;
}
}
return false;
}
void sort(string array[], int cnt)
{
string temp, mixedTemp;
string str1="";
vector lower(cnt); // Use a vector instead of an array
for (int m =0; m < cnt; m++)
{
for (int s =0; s < array[m].length(); s++)
{
str1+= tolower(array[m].at(s));
}
lower[m]= str1;
str1="";
}
for (int i =0; i < cnt; i++)
{
for (int j = i +1; j < cnt; j++)
{
if (lower[i].compare(lower[j])>0)
{
temp = lower[i];
lower[i]= lower[j];
lower[j]= temp;
mixedTemp = array[i];
array[i]= array[j];
array[j]= mixedTemp;
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!