/* Filename: arrays.cpp Author: Br. David Carlson Date: January 13, 1998 Modified: June 25, 2000; November 21, 2001 This program prompts the user to enter integers into an array (by first asking the user for the number of integers to be entered). It then prints the array of integers on the screen. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include using namespace std; const int ArrayMax = 8; // Change this to whatever is appropriate. typedef int ArrayType[ArrayMax]; // Function prototypes: void FillArray(ArrayType Num, int & Count); void PrintArray(ArrayType Num, int Count); int main(void) { int NumItems; ArrayType MyArray; FillArray(MyArray, NumItems); PrintArray(MyArray, NumItems); return 0; } /* Given: Nothing. Task: To ask the user for the Count of how many integers to enter and to get the user to enter these integers. Return: NumArray The array of integers entered by the user. Count The number of such integers entered. */ void FillArray(ArrayType NumArray, int & Count) { int k; cout << "How many items would you like to enter? "; cin >> Count; while ((Count < 1) || (Count > ArrayMax)) { cout << "Reenter. Use an integer between 1 and " << ArrayMax << " "; cin >> Count; } for (k = 0; k < Count; k++) { cout << "Enter array item for index " << k << " "; cin >> NumArray[k]; } } /* Given: NumArray An array of Count integers stored contiguously from index 0 onward. Count The number of integers in NumArray. Task: To print the numbers in NumArray. Return: Nothing. */ void PrintArray(ArrayType NumArray, int Count) { int k; for (k = 0; k < Count; k++) cout << NumArray[k] << " "; cout << endl; }