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
|
// Practice with arrays for lab
#include <iostream>
#include <ctime>
#include <iomanip>
#include <string>
using namespace std;
void printArray ( const int [], int );
void initializeArray( int anArray [], int size );
void randomizeArray( int anArray [], int size );
void printBackwards (const int anArray [], int size);
//printBackwards function
//targetCount function
//cubeArray function
//findHighest function
////////////////////////////////////////////////////////////////////
int main()
{
const int SIZEA = 15;
const int SIZEB = 15; //ADDED THIS
int alpha_List [SIZEA];
int beta_List [SIZEB]; //ADDED THIS
initializeArray ( alpha_List, SIZEA );
cout << "\nalpha_List initialized by user input\n";
printArray ( alpha_List, SIZEA);
randomizeArray ( alpha_List, SIZEA );
cout << "\nalpha_List randomized!\n";
printArray ( alpha_List, SIZEA );
initializeArray ( beta_List, SIZEB ); //added this
cout << "\nbeta_List initialized by user input\n";
printArray ( beta_List, SIZEB);
randomizeArray ( beta_List, SIZEB ); //added this
cout << "\nbeta_List randomized!\n";
printArray ( beta_List, SIZEB );
cout << endl<< endl;
system("pause");
return 0;
}
////////////////////////////////////////////////////////////////////
// prints out the entries in an array
void printArray ( const int anArray [], int size )
{
static int count = 0;
int looper ;
cout<<"\n---------------\n";
for (looper =0;looper <size;looper++)
cout << setw(5) <<anArray [looper] <<endl;
count++;
cout <<"This print function has been called "<<count<<" times.\n";
cout<<"\n=============================\n";
}
////////////////////////////////////////////////////////////////////
// fills an array with random numbers between 0 and 50, inclusive
void randomizeArray( int anArray [], int size )
{
int num ;
int looper;
for ( looper = 0; looper < size ; looper++)
{
num = (rand () + time (0) ) % 51;
anArray[looper] = num;
}
}
////////////////////////////////////////////////////////////////////
void initializeArray( int myArray [], int size )
{
int value; // number used for initializing each array location
cout <<"\n\nEnter an integer to initialize the array components: ";
cin >> value;
int looper;
for ( looper = 0; looper < size ; looper++)
{
myArray[looper] = value;
}
void printBackwards ( int alpha_List, int beta_List )
{
static int count = 15;
int looper ;
cout<<"\n---------------\n";
for (looper =0;looper <size;looper--)
cout << setw(5) <<anArray [looper] <<endl;
count--;
}
////////////////////////////////////////////////////////////////////
|