//Charlotte Davies-Kiernan CS1A Chapter 9 P. 537 #1
//
/*****************************************************************************
*
* Allocate Integer Array
* ___________________________________________________________________________
* This program will allocate an array of integers and display the sequence
* of integers up to the amount elements asked for, each element being squared.
* ___________________________________________________________________________
* Input
* number :number of elements to allocate
* Output
* allocateArray :function that creates the array and sends its address back to main
* myArray :a pointer that stores the address of the array and lets you access and modify it
*****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//Function Prototype
int* allocateArray(int size);
int main() {
int number;
int* myArray;
//User Input
cout << "Enter number of elements to allocate: " << endl;
cin >> number;
//Call Function
myArray = allocateArray(number);
//Print!
for(int i = 0; i < number; i++){
myArray[i] = (i + 1) * (i + 1);
cout << myArray[i] << " ";
}
//Free Memory
delete [] myArray;
return 0;
}
//Function Definition
int* allocateArray(int size) {
int* arr = new int[size];
return arr;
}