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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <iostream>
using namespace std;
char letters[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
long int count(int a)
{
if (a == 0)
return 2700;
else
return (2 * count(a - 1));
}
// Generate random words
char random()
{
int randomList = rand() % 26; //Generate random number to be used to index array
char randomPick = letters[randomList]; //Pick a letter from the array at random
return randomPick;
}
struct Arrays
{
long int sizeList[128];
long int sizeLib[1024];
char* ptrList[128];
char* ptrLib[1024];
};
void initArrays(struct Arrays &o)
{
// random_list
for (int i = 0; i < 128; i++)
{
o.sizeList[i] = count(i);
}
// Dynamically allocate memory for recent_list
for (int i = 0; i < 128; i++)
{
o.ptrList[i] = new char[o.sizeList[i]];
// Insert letters into the arrays INSIDE the 'pointers' array
for (long int j = 0; j < o.sizeList[i]; j++)
{
o.ptrList[i][j] = random();
}
}
// Library
for (int i = 0; i < 1024; i++)
{
o.sizeLib[i] = count(i);
}
// Dynamically allocate memory for recent_list
for (int i = 0; i < 1024; i++)
{
o.ptrLib[i] = new char[o.sizeLib[i]];
// Insert letters into the arrays INSIDE the 'pointers' array
for (long int j = 0; j < o.sizeLib[i]; j++)
{
o.ptrLib[i][j] = random();
}
}
}
int main()
{
Arrays a1;
initArrays(a1);
int input = 0;
char str[100];
// Prompt for user
cout << "---------------------------------------------" << endl;
cout << " Press 1 to search the Recent List for a word" << endl;
cout << " Press 2 to exit the program" << endl;
cout << "---------------------------------------------" << endl;
cin >> input;
while (input != 1 && input != 2)
{
cout << "-----------Please press only 1 or 2-----------" << endl;
cout << " Press 1 to search the Recent List for a word" << endl;
cout << " Press 2 to exit the program" << endl;
cout << "---------------------------------------------" << endl;
cin >> input;
}
while (input != 2)
{
cout << "Enter a word: ";
cin >> str;
}
return 0;
}
|