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
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int MAX = 100;
//Function for rows and columns
void getRowColumn(int&, int&);
//Function to return values
char getRandom(int);
//Function to construct 2D array
void construct2D(char[][MAX], int, int, int);
//Function to print 2D array
void print2D(const char [][MAX], int, int, int);
int main()
{
char str[MAX][MAX];
int rows, columns;
int k;
srand(time (NULL));
getRandom(k);
construct2D(str, rows, columns, k);
print2D(str, rows, columns, k);
}
void getRowColumn(int& rows, int& columns)
{
rows = rand() % 7 + 4;
columns = rand() % 7 + 4;
}
char getRandom(int k)
{
const char alphaNumeric [] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
k = sizeof(alphaNumeric) - 1;
return alphaNumeric[rand() % k];
}
void construct2D(char str[][MAX], int rows, int columns, int k)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
str [i][j] = k;
}
}
}
void print2D(const char str [][MAX], int rows, int columns, int k)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
cout << str [i][j] << " ";
}
cout << endl;
}
}
|