Write a program that uses the following template functions: populate_array() takes as arguments the name of an array of type T values and an array size in int. It prompts the user to enter type T values to be entered in the array. It ceases taking input when the array is full. display_array() takes as arguments the name of an array of type T values and an array size and displays the contents of the array. invert_array() takes as arguments the name of an array of type T values and an array size and reverses the order of the values stored in the array. max_element() takes as arguments the name of an array of type T values and an array size and finds max element of the array. min_element() takes as arguments the name of an array of type T values and an array size and finds max element of the array. sum_array() takes as arguments the name of an array of type T values and an array size and return the sum of all the elements of the array. The program should use these functions for data type int and then for data type double, Fill an array, Show the array, Sum the elements of the array, Reverse the array, Show the array, Sum the elements of the inverted array, Max element of array Minimum element of array |
|
|
|
|
In function 'void sum_array(T*, int)': 21:37: error: 'array_size' was not declared in this scope |
const int array_size = 100; // could use std::size_t
sum_array(array, array_size);
|
|
using namespace std;
it will bite you one day. You already have array
which exists in std as std::array
, it's not a problem at the moment because there is no #include <array>
There are other header files - especially <algorithm> which has a lot of things with common names that will likely cause a conflict.
//does not work std::reverse(std::begin(arr), std::end(arr)); |