Dynamic Array and Pointers (p. 518, Ch 9.8 Dynamic Memory Allocation) Purpose In
ID: 3553078 • Letter: D
Question
Dynamic Array and Pointers
(p. 518, Ch 9.8 Dynamic Memory Allocation)
Purpose In these makeup assignment you are to develop functions that have dynamic arrays as parameters. Remember that dynamic arrays are accessed by a pointer variable and thus the parameters that serve as dynamic arrays are, in fact, pointer variables.
Description
The demand for resource is cyclical similar to the traffic hour to the freeways. To dynamically allocate resources when the demand is growing and to deallocate resource when shrinking. We often don't know how much space we will need at "compile-time".
Dynamic memory allocation is the allocation of memory at "run-time".
In Java, all objects use memory that is allocated at "run time", but not in C++. Therefore, to program in C++, we often have to manage the run-time memory ourselves.
You are to redo the Assignment 2 array management. Instead of pre-allocate a large memory block (user_array, bubble_sorted_array, and selection_sorted_array), you are to change the pre-allocation to dynamic allocation.
In this makeup Lab3A, There are two memory blocks of integers that the use have access to: the program_memory and the user_array.
Managing the User_array
In this assignment, the user can read/write access the user_array contents using the array subscription, but to use the pointers.
Dynamic memory re-allocation algorithm for the program_memory
In this assignment we are going to use the user initiated memory re-allocation algorithm:
User Interface reduced Lab 3A command option to 1-6 and q
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
__________________________________________________________
Example C++ Programming Segments
1 Dynamically allocate and release an integer array:
The C++ program requests dynamically allocated memory is through the new operator.
For creating an integer array of 100:
int *iptr = new int[100];
When a program is nished using a dynamically allocated array, it should release it to the system memory pool. The delete operator is used to free memory that was allocated with new:
delete [] iptr;
2. Initialize the array using pointer:
for (int count = 0; count < 100; count++) *iptr++ = 0;
3. Update the working array
Copy the content from old allocated memory to newly allocated array then release the old one.
4. The structure of the applicationwith some actual working program segments.
A working lab3a_starter.cpp is provided to get you started and help you to focus on the pointer mechanism part of the work.
5. Dynamic Memory ReAllocation algorithm
The INCREASE dynamic memory re-allocation algorithm is provided inside the lab3a_starter.cpp. This is the exact same implementation of the Lab3. You shall implement the DECREASE dynamic memory re-allocation for command option 6.
_______________________________________________
Sample Test Patterns:
Here is a listing of test run:
Process started >>>
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 25)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 10 elements.
And it contains: 100, 90, 80, 70, 60, 50, 40, 30, 20, 10
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 25)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 4
The mean of user array (size of 10) is 55
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 25)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 5
The allocated size is 100
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 10 elements.
And it contains: 100, 90, 80, 70, 60, 50, 40, 30, 20, 10
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 2
Enter a location between 1 and 10: 1
The current value is 100; What is the new value? 222
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 10 elements.
And it contains: 222, 90, 80, 70, 60, 50, 40, 30, 20, 10
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 10
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 3
The current size is 10; Enter the new size between 1 and 100: 23
resize from: 10 to: 23
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 23
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 5
The allocated size is 400
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 23
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 23 elements.
And it contains: 222, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 23
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 4
The mean of user array (size of 23) is 29
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 23
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 3
The current size is 23; Enter the new size between 1 and 400: 128
resize from: 23 to: 128
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 128
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 128 elements.
And it contains: 222, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 128
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 2
Enter a location between 1 and 128 :22
The current value is 0; What is the new value? 333 <=== to check the value is zero out after size down the user_array
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 128
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 3
The current size is 128; Enter the new size between 1 and 400: 20
resize from: 128 to: 20
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 20
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 20 elements.
And it contains: 222, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 20
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 3
The current size is 20; Enter the new size between 1 and 400: 24
resize from: 20 to: 24
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 24
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 1
The user_array has 24 elements.
And it contains: 222, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 24
2 - modify user_array content
3 - modify user_array size (between 1 - 400)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 6
The allocated size is 100
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 23
2 - modify user_array content
3 - modify user_array size (between 1 - 100)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 6
The allocated size is 25
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 23
2 - modify user_array content
3 - modify user_array size (between 1 - 25)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice: 6
The allocated size is 6
----- LAB3A COMMAND MENU -------------
1 - display user_array, size of: 6
2 - modify user_array content
3 - modify user_array size (between 1 - 6)
4 - display mean of user_array
5 - INCREASE 4X the program_memory (up to 10000)
6 - DECREASE 1/4 the program_memory (down to 1)
q - quit
Enter your choice:
___________________________________________________
Code::Blocks fix
for (int i; i<size; i++) *ptr++ = xyz;
needs to write as:
for (int i; i<size; i++) *(ptr+i) = xyz;
___________________________________________________
Provided files: lab3a_starter.cpp
Grading Your submitted lab3a.cpp will return for redo and 1 point deduction for each occurance of the following:
Your code shall not make any reference to array (square) bracket [] except for dynamic memory new allocation, or code not related with the user array management, such as
char ch = choice[0]; // only process the first character user input
Submit please submit one signle lab3a.cpp file to the dropbox here.
Universal Requirement all assignments for this course:
All submitted files shall contain the following information on top of the files (header of the C++, h file)
Here it's what I've done so far...
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int prompt4Size(int, int);
int prompt4Value();
/* meanOfArray prototype using array notation
int meanOfArray(int [], int);
*/
int meanOfArray(const int *, int); // meanOfArray prototype using pointer notation
/* Startup allocation uses a pre-defined constant
const int INIT_ALLOCATED_SIZE = 25;
The run-time user re-allocation uses a local variable inside the main()
*/
// string to integer conversion method
double str2Int(string s) {
int i;
stringstream ss(s); //turn the string into a stream
ss >> i; //convert
return i;
}
void menu(int user_array_size, int allocated_size) {
std::cout << " ----- LAB3A COMMAND MENU ------------- "
<< " 1 - display user_array, size of: " << user_array_size << " "
<< " 2 - modify user_array content "
<< " 3 - modify user_array size (between 1 - " << allocated_size<< ") "
<< " 4 - display mean of user_array "
<< " 5 - INCREASE 4X the program_memory (up to 10000) "
<< " 6 - DECREASE 1/4 the program_memory (down to 1) "
<< " q - quit "
<< " Enter your choice: ";
}
int main()
{
int user_array_size = 10, requested_size=0,highlowcount=0;
int re_allocated_size=0, allocated_size=25;
int *iReallocatePtr=0; // for re-allocation array
int *itPtr, *itPtr2; // traversal pointers
// to manage the dynamic memory allocation
/* Replace all the C++ array subscription in this file with pointer method, e.g.
* int *iUserPtr=0; // to replacing the user_array[]
*/
int *iProgMemPtr = new int[allocated_size];
itPtr = iProgMemPtr; // use the traversal pointer
for(int i=0; i<allocated_size-1; i++)
{*(itPtr+i) = 0;}
*itPtr = -1; // mark the last item
// initialize the user_array as a test driver
for(int i=0; i<user_array_size; i++) *(iProgMemPtr+i) = 100 - i*10;
int location = 0; // command option 2 user entered a location to modify
int input_size = 0; // command option 3 user entered a new array size
// stay sentinel/flag to stay in menu loop!
bool stay = true;
// main menu while loop
while(stay) { // main menu while starts
string choice; // user choice input
string user_input;
int searchPos; // item position
int searchNum; // item value
menu(user_array_size, allocated_size);
std::cin >> choice;
std::cin.ignore();
if(choice.size() == 1) {
char ch = choice[0]; // only process the first character user input
switch(ch) { // main menu switch starts
case '1': // display user_array and its size
cout << "The user_array has " << user_array_size
<< " elements. And it contains: ";
for(int i=0; i < user_array_size - 1; i++)
cout << *(iProgMemPtr + i) << ", ";
cout << *(iProgMemPtr + (user_array_size -1)) << " ";
break;
case '2': // modify user_array content
cout << "C++ code to modify ONE integer inside the user_array here! ";
break;
case '3': // modify user_array size
cout << "C++ code to modify the user_array SIZE here! ";
break;
case '4': // mean of the user_array
cout << "The mean of user array (size of "
<< user_array_size << ") is " << meanOfArray(iProgMemPtr, user_array_size) << endl;
break;
case '5': // INCREASE ALLOCATION by 4X
{
/* steps to re-allocate the user array:
* a) allocate new;
* b) tranfer content;
* c) release old;
*/
if(allocated_size*4 >=10000) {
cout << "Can not allocate more, the upper limit reached! ";
break;
}
// step a) allocate new 4X the old allocated
//cout << "entered the 4x" << endl;
re_allocated_size = allocated_size*4;
iReallocatePtr = new int[re_allocated_size];
// initialize new arrays
itPtr = iReallocatePtr;
for(int i=0; i<re_allocated_size; i++) *itPtr++ = 0;//re_allocated_size -i;
itPtr = iReallocatePtr;
// step b) transfer old to new
itPtr = iReallocatePtr; // traversal pointer for new
itPtr2 = iProgMemPtr; // traversal pointer for old
for(int i=0; i<user_array_size; i++) *itPtr++ = *itPtr2++;
// step c) release old
delete iProgMemPtr;
iProgMemPtr = iReallocatePtr;
allocated_size = re_allocated_size;
cout << "The allocated size is " << allocated_size << endl;
highlowcount = highlowcount + 1;
//cout << " The count is " << highlowcount << endl;
}
case '6': // DECREASE ALLOCATION by 1/4
cout << "C++ code to DECREASE the (*iProgMemPtr) program_memory SIZE here! ";
break;
case 'q': // Sentinel to EXIT the main menu
stay = false;
break;
default:
cout << " Invalid Selection! .... Try again! ";
} // end of switch
} // end of menu for single character input
else
cout << " Only one character command Please! "
<< ".... Try again! ";
} // end of while
}
// prompt for the user input
int prompt4Size(int user_array_size, int allocated_size) {
string user_input;
cout << "The current size is "
<< user_array_size << "; Enter the new size between 1 and "
<< (allocated_size) << ": ";
cin >> user_input;
cin.ignore();
return str2Int(user_input);
}
int prompt4Value() {
string user_input;
cout << "What is the value? ";
cin >> user_input;
cin.ignore();
return str2Int(user_input);
}
int meanOfArray(const int *array, int array_size) {
double array_sum = 0.00;
for(int i = 0; i < array_size; i++) array_sum += *array++;
return array_sum/array_size;
}
Explanation / Answer
Dropbox Link: https://dl.dropboxusercontent.com/u/41585969/lab3a.cpp
Code:
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int prompt4Size(int, int);
int prompt4Value();
/* meanOfArray prototype using array notation
int meanOfArray(int [], int);
*/
int meanOfArray(const int *, int); // meanOfArray prototype using pointer notation
/* Startup allocation uses a pre-defined constant
const int INIT_ALLOCATED_SIZE = 25;
The run-time user re-allocation uses a local variable inside the main()
*/
// string to integer conversion method
double str2Int(string s) {
int i;
stringstream ss(s); //turn the string into a stream
ss >> i; //convert
return i;
}
void menu(int user_array_size, int allocated_size) {
std::cout << " ----- LAB3A COMMAND MENU ------------- "
<< " 1 - display user_array, size of: " << user_array_size << " "
<< " 2 - modify user_array content "
<< " 3 - modify user_array size (between 1 - " << allocated_size<< ") "
<< " 4 - display mean of user_array "
<< " 5 - INCREASE 4X the program_memory (up to 10000) "
<< " 6 - DECREASE 1/4 the program_memory (down to 1) "
<< " q - quit "
<< " Enter your choice: ";
}
int main()
{
int user_array_size = 10, requested_size=0,highlowcount=0;
int re_allocated_size=0, allocated_size=25;
int *iReallocatePtr=0; // for re-allocation array
int *itPtr, *itPtr2; // traversal pointers
// to manage the dynamic memory allocation
/* Replace all the C++ array subscription in this file with pointer method, e.g.
* int *iUserPtr=0; // to replacing the user_array[]
*/
int *iProgMemPtr = new int[allocated_size];
itPtr = iProgMemPtr; // use the traversal pointer
for(int i=0; i<allocated_size-1; i++)
{*(itPtr+i) = 0;}
*itPtr = -1; // mark the last item
// initialize the user_array as a test driver
for(int i=0; i<user_array_size; i++) *(iProgMemPtr+i) = 100 - i*10;
int location = 0; // command option 2 user entered a location to modify
int input_size = 0; // command option 3 user entered a new array size
// stay sentinel/flag to stay in menu loop!
bool stay = true;
// main menu while loop
while(stay) { // main menu while starts
string choice; // user choice input
string user_input;
int searchPos; // item position
int searchNum; // item value
int location,size,value;
menu(user_array_size, allocated_size);
std::cin >> choice;
std::cin.ignore();
if(choice.size() == 1) {
char ch = choice[0]; // only process the first character user input
switch(ch) { // main menu switch starts
case '1': // display user_array and its size
cout << " The user_array has " << user_array_size
<< " elements. And it contains: ";
for(int i=0; i < user_array_size - 1; i++)
cout << *(iProgMemPtr + i) << ", ";
cout << *(iProgMemPtr + (user_array_size -1)) << " ";
break;
case '2': // modify user_array content
cout << " Enter a location between 1 and " << user_array_size<<": ";
cin >> location;
cout << " The current value is " << *(iProgMemPtr+location-1) << "; ";
value = prompt4Value();
*(iProgMemPtr+location-1) = value;
break;
case '3': // modify user_array size
size = prompt4Size(user_array_size, allocated_size);
re_allocated_size = size;
if(size > user_array_size){
for(int i=user_array_size; i<size;i++)
*(iProgMemPtr+i) = 0;
}
cout << " resize from: " << user_array_size << " to: " << size << endl;
user_array_size = size;
break;
case '4': // mean of the user_array
cout << " The mean of user array (size of "
<< user_array_size << ") is " << meanOfArray(iProgMemPtr, user_array_size) << endl;
break;
case '5': // INCREASE ALLOCATION by 4X
{
/* steps to re-allocate the user array:
* a) allocate new;
* b) tranfer content;
* c) release old;
*/
if(allocated_size*4 > 10000) {
cout << " Can not allocate more, the upper limit reached! ";
break;
}
// step a) allocate new 4X the old allocated
re_allocated_size = allocated_size*4;
iReallocatePtr = new int[re_allocated_size];
// initialize new arrays
itPtr = iReallocatePtr;
for(int i=0; i<re_allocated_size; i++) *itPtr++ = 0;//re_allocated_size -i;
itPtr = iReallocatePtr;
// step b) transfer old to new
itPtr = iReallocatePtr; // traversal pointer for new
itPtr2 = iProgMemPtr; // traversal pointer for old
for(int i=0; i<user_array_size; i++) *itPtr++ = *itPtr2++;
// step c) release old
delete iProgMemPtr;
iProgMemPtr = iReallocatePtr;
allocated_size = re_allocated_size;
cout << " The allocated size is " << allocated_size << endl;
highlowcount = highlowcount + 1;
break;
}
case '6': // DECREASE ALLOCATION by 1/4
{
if(allocated_size/4 < 1) {
cout << " Can not allocate less, the lower limit reached! ";
break;
}
// step a) allocate new 4X the old allocated
re_allocated_size = allocated_size/4;
iReallocatePtr = new int[re_allocated_size];
// initialize new arrays
itPtr = iReallocatePtr;
for(int i=0; i<re_allocated_size; i++) *itPtr++ = 0;//re_allocated_size -i;
itPtr = iReallocatePtr;
// step b) transfer old to new
itPtr = iReallocatePtr; // traversal pointer for new
itPtr2 = iProgMemPtr; // traversal pointer for old
user_array_size = min(user_array_size, re_allocated_size);
for(int i=0; i<user_array_size; i++) *itPtr++ = *itPtr2++;
// step c) release old
delete iProgMemPtr;
iProgMemPtr = iReallocatePtr;
allocated_size = re_allocated_size;
cout << " The allocated size is " << allocated_size << endl;
highlowcount = highlowcount + 1;
break;
}
case 'q': // Sentinel to EXIT the main menu
stay = false;
break;
default:
cout << " Invalid Selection! .... Try again! ";
} // end of switch
} // end of menu for single character input
else
cout << " Only one character command Please! "
<< ".... Try again! ";
} // end of while
}
// prompt for the user input
int prompt4Size(int user_array_size, int allocated_size) {
string user_input;
cout << " The current size is "
<< user_array_size << "; Enter the new size between 1 and "
<< (allocated_size) << ": ";
cin >> user_input;
cin.ignore();
return str2Int(user_input);
}
int prompt4Value() {
string user_input;
cout << "What is the value? ";
cin >> user_input;
cin.ignore();
return str2Int(user_input);
}
int meanOfArray(const int *array, int array_size) {
double array_sum = 0.00;
for(int i = 0; i < array_size; i++) array_sum += *array++;
return array_sum/array_size;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.