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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include<iostream>
using namespace std;
#include<cstring>
#include<stdlib.h>
//RANDOM WORD GENERATOR DEFINITION
void randword(char arrayone[][7],int num){int len;
for(int i = 0 ; i < num ; i++){
//DETERMINES THE LENGTH OF THE WORD
len = rand()3 + 4;
for(int j = 0; j<= len ; j++){
arrayone[i][j] = rand()% 26 + 'a';
if (j == len)
arrayone[i][j] ='\0';
}
}
}
//PRINT ARRAY FUNCTION DEFINITION
void PrintArray(char Array[][7], int num)
{
for( int i = 0; i < num ; i++)
cout << Array[i]<< endl;
}
//SORTDATA FUNCTION DEFINITION
void SortArray(char arraythree[][7],int num)
{char temp[7];
for(int i = 0; i< num - 1 ; i++)
for( int j = 0 ; j < num ; j++)
{ if(strcmp(arraythree[j],arraythree[j+1]) == 1)
{ strcpy(temp, arraythree[j+1]);
strcpy(arraythree[j+1],arraythree[j]);
strcpy(arraythree[j],temp);
}
}
}
void dub_search(char array5[][7], int num ){int counter=0;
for( int j = 0 ; j < num ; j++)
{ if(strcmp(array5[j],array5[j+1]) == 0){counter++;
cout <<"there is a duplicate in word " << j << ".Replace it now --->" << endl;
cin >> array5[j-1];
PrintArray(array5,num);}
}
if(counter == 0)
cout << "\n\nThere is no duplications that have been found." <<endl;}
void binSearch(char arrayfour[][7],int num, char searchkey[]){
int first = 0;
int last = num-1;
int mid;
while (first <= last){
mid = (first + last) / 2;
if( searchkey > arrayfour[mid])
first = mid + 1;
else if(searchkey < arrayfour[mid])
last = mid - 1;
else if (searchkey==arrayfour[mid])
cout << "The word " << searchkey <<" you are searching for is in location number " << mid << " of the array." <<endl;
}
}
//MAIN FUNCTION DEFINITIONS
int main()
{int wordnum;
cout << "How many words do you want to generate?";
cin >> wordnum;
char WordArray[1000][7];
char key[7];
randword(WordArray, wordnum);
cout <<"\n\n Thank you. \n Here are your words.\n"<<endl;
PrintArray(WordArray,wordnum);
cout << "\n\n\n Here they are after being sorted.\n" <<endl;
SortArray(WordArray, wordnum);
PrintArray(WordArray,wordnum);
dub_search(WordArray, wordnum);
cout << "\n\n\n Give me a word to search for?";
cin >> key;
binSearch(WordArray, wordnum, key);
char ans[1];
printf("press enter to exit.");
cin >>ans;
return 0;}
|