Code:
#include <iostream>
#include <iomanip>
using namespace std;
void initArray();
void selectionSort(char [][17] , int NUM_NAMES, int SIZE);
int searchName(char [][17], int NUM_NAMES, int SIZE);
int binarySearch(char array[][17], char names[][17]);
int main()
{
initArray();
}
void initArray()
{
const int NUM_NAMES= 20, SIZE = 17;
char names[NUM_NAMES][SIZE]= {"Collins, Bill", "Smith, Bart", "Allen, Jim",
"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
"Taylor, Terri", "Johnson, Jill",
"Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
"James, Jean", "Weaver, Jim", "Pore, Bob",
"Rutherford, Greg", "Javens, Renee",
"Harrison, Rose", "Setzer, Cathy",
"Pike, Gordon", "Holland, Beth"};
selectionSort(names, NUM_NAMES, SIZE);
}
void selectionSort(char names[][17] , NUM_NAMES, SIZE)
{
int number, startScan[81], minIndex[81], elems = 17;
char minValue[][17];
for (number = 0; number < (elems - 1); number++)
{
minIndex[81] = number;
strcpy(minValue[index][17], names[index][17]);
for (int index = number+1; index < elems; index++)
{
if (strcmp(names, minValue) != 0)
{
strcpy(minValue[81], names[81]);
minIndex[81] = index;
}
strcpy(names, names);
strcpy(names, minValue);
}
}
searchName(names, NUM_NAMES, SIZE);
}
int searchName(char names[20][17])
{
char name[1][17];
int position;
cout << "Please enter a name putting the last name first.\n";
cin >> name[0][17];
binarySearch(name, names);
cout << name << " was found here: " << position << "\n";
exit(0);
return position;
}
int binarySearch(char name[20][17], char names[20][17])
{
int elems = 17,
first = 0,
last = elems - 1,
middle,
position = -1;
bool found = false;
while (!found && first <= last)
{
middle = (first + last)/2;
if(strcmp(names[middle][elems], name[20][17]) == 0)
{
found = true;
position = middle;
}
else if
(strcmp(names[index][17], name) <= 1)
last = middle - 1;
else
first = middle +1;
}
return position;
}
Errors
Code:
binarystringsearch.cpp(31) : error C2061: syntax error : identifier 'NUM_NAMES'
binarystringsearch.cpp(36) : error C2133: 'minValue' : unknown size
binarystringsearch.cpp(40) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char [][17]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
binarystringsearch.cpp(41) : error C2440: 'initializing' : cannot convert from 'int' to 'int [81]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
binarystringsearch.cpp(41) : error C2446: '<' : no conversion from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
binarystringsearch.cpp(41) : error C2040: '<' : 'int [81]' differs in levels of indirection from 'int'
binarystringsearch.cpp(41) : error C2105: '++' needs l-value
binarystringsearch.cpp(44) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char [][17]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
binarystringsearch.cpp(47) : error C2440: '=' : cannot convert from 'int [81]' to 'int'
There is no context in which this conversion is possible
binarystringsearch.cpp(49) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char [][17]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
binarystringsearch.cpp(50) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char [][17]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
binarystringsearch.cpp(54) : error C2065: 'NUM_NAMES' : undeclared identifier
binarystringsearch.cpp(54) : error C2065: 'SIZE' : undeclared identifier
binarystringsearch.cpp(81) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
binarystringsearch.cpp(87) : error C2065: 'index' : undeclared identifier
By the way, Decrypt, I really want to say that I greatly apreciate the help you have given me, so Thanks a lot.