I have an assignment in which I need the user to enter names into an array, sort it, ask for a string to search for, and provide an index for the string if it is in the array. The user can either enter 20 names or press the enter key to stop entering names early. The names have no character limit, so we are supposed to use an array of pointers.
void main()
{
int index;
int i;
string * Names[20];
bool typenames;
char find;
cout << "Type up to 20 names, press enter to stop." << endl;
typenames = true;
do{
for (i = 0;i < 20; i++)
{
cin >> Names[i];
}
//if enter is pressed typenames=false
typenames = false;
} while (typenames);
cout << "Before sort" << endl;
for (i = 0; i < 20; i++)
{
cout << Names[i] << endl;
}
BubbleSort(Names[], strlen(Names[]));
cout << "After sort" << endl;
for (i = 0; i < 20; i++)
{
cout << Names[i] << endl;
}
//index = BinarySearch(Names, find, i-1);
//cout << "Index is " << index << endl;
system("pause");
}
We were also given some basic functions within the past few weeks that sort and search, but I have had a difficult time figuring out how to pass the arrays into them properly. Obviously they need to be altered as well to complete the program but I haven't even attempted that yet.