reate a program to do the following:
1) Read in names to sort until the user types the “enter” key as the first character of a string (the maximum number of names is 20, there is not a maximum length to a name).
2) After sorting and displaying the array of strings, ask the user for a string to search for (again, no maximum length).
3) Do a binary search to find if the string is in the array
4) If the string is in the array, tell the user the index of the string.
5) If the string is not in the array, tell the user that it is missing.
6) Repeat items 3 thru 5 until the user enters the “enter” key as the first character of the string, at which time the program will complete.
BONUS: A bonus of 20 points if you create the program in such a way that there is no limit on the number of names to be handled.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
#include "BinarySearch.h"
#include "Bubblesort.h"
#include <string>
using namespace std;
void main()
{
int Num;
char ** Names2;
Names2 = new char *[20];
char i;
void inputStrings(string words[], int Num);
cout << "How many strings would you like to enter?" << endl;
cin >> Num;
cout << "You would like to enter " << Num << "strings. ";
string words = new char[Num];
//inputStrings(words, Num);
for (int i = 0; i < Num; i++)
{
cout << "You have entered: " << words[i] << "/n";
//cin >> Names2[i];
}
//cout << "Here are the numbers you entered:" << endl;
//for (int i = 0; i < Num; i++)
//{
// cout << Names2[i] << " ";
//}
//cout << endl << endl;
BubbleSort(Names2[i]);
cout << "Here are your sorted numbers:" << endl;
for (int i = 0; i < Num; i++)
{
cout << Names2[i] << " ";
}
cout << endl;
}
BinarySearch (N)
|
[/code]
#include "BinarySearch.h"
#include <string.h> // for string length
int Search(const char Array[], char Item)
{
int First;
int Middle;
int Last;
First = 0;
Last = strlen (Array) -1 ;
do {
Middle = (First + Last) / 2;
if (Array[Middle] == Item)
return Middle;
else
if (Array[Middle] > Item)
Last = Middle - 1;
else
First = Middle + 1;
} while (Last >= First);
return -1;
return Last;
}
[/code]
I believe my Binary Sort is ok, but im lost in the main file. I've missed some classes while healing so im trying to get caught back up. Can someone just point suggestions on what needs to be changed or added for this to work? Much Thanks