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 101 102 103 104 105 106 107 108 109 110 111 112
|
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void bubblesort( int [], int );
void bubblesort( ?, ? ); // function overloading to sort characters
void print(int[], int);
void printH(int[], int);
void print(?,?); // function overloading to print characters
void printH(?,?); // function overloading to print histogram for characters
int main()
{
int i, magic, size;
int high;
int low ;
? // declare an integer array named a with size 100
? // declare a character array named b with size 100
cout << "how many random numbers do you want to create? (no more than 100)\n";
? // read user input into variable size
if (size > 100)
{
cout << "too many, program ends.\n";
return -1;
}
cout <<"enter the smallest and largest random number you want to create:\n";
? // read user input into variables low and high
srand(time(NULL));
? //write a for loop to run the code inside { }. The total loops = size.
{
magic = rand() % (high-low+1) + low;
a[i] = magic;
srand(time(NULL)+i*i+3);
}
cout << "\nthe random numbers generated are: \n";
? //write a statement to call print function to print a
bubblesort (a, size);
cout << "\nthe random numbers after sort:\n";
? //write a statement to call print function to print a
cout << "\nthe histogram of the numbers:\n";
printH(a,size);
cout << "\n\nhow many random lower case characters do you want to create? (no more than 100)\n";
cin >> size;
if (size > 100)
{
cout << "too many, program ends.\n";
return -1;
}
high = 122;
low = 97;
srand(time(NULL));
for (i = 0; i < size; i++)
{
magic = rand() % (high-low+1) + low;
b[i] = magic;
srand(time(NULL)+i*i+3);
}
cout << "\nthe characters generated are: \n";
print(b, size);
bubblesort (b, size);
cout << "\nthe characters after sort are: \n";
print(b, size);
cout << "\nthe histogram of the charaters:\n";
printH(b,size);
return 0;
}
void bubblesort( int x[], int len )
{
? //write function definition to bubble sort the integer array x[], len is the size of x[]
}
void bubblesort(?,? )
{
? //write function definition to bubble sort a character array
}
void print (int a[], int len)
{
? //write function definition to print an integer array
}
void printH (int a[], int len)
{
//function definition to print histogram of a sorted integer array
int current, shows;
current = -1;
shows = 0;
for (int i = 0; i < len; i++)
{
if (current != a[i] )
{
current = a[i];
cout << "\n" << a[i] << " *";
}
else
cout << "*";
}
cout << endl;
}
void print (?,?)
{
? //write function definition to print a character array
}
void printH (?,?)
{
? //write function definition to print histogram of a sorted character array
}
|