Remember partially filled arrays where the number of elements stored in the array can be less than its capacity (the maximum number of elements allowed). We studied two different ways to represent partially filled arrays: 1) using anintvariable for the numElems and 2) using a terminating value to indicate the end of elements called the sentinel value. In the code below, please fill in the details for reading values into the latter type of array that uses a sentilnel value. Don't forget to complete the printArray function.
#include using namespace std;void printArray(int array[]);// Implement printArray as defined with one array parameterint main(){const int CAPACITY=21;int array[CAPACITY]; // store positive/negative int values, using 0 to indicate the end of partially filled arraycout <"enter up="" to="" "="">"enter>< capacity-1="">< "="" non-zero="" integers,="" enter="" 0="" to="" end="" when="" you="" are="">//To do: Write a loop to read up the int values and store them into array a.// Stop reading if the user enters 0 or the array a is full.//To do: store 0 to indicate the end of values in the array//Display array functionprintArray(array);return 0;}// To do: implement display for the given arrayvoid printArray(int array[]){}
void printArray(int array[]);// Implement printArray as defined with one array parameter
int main(){const int CAPACITY=21;int array[CAPACITY]; // store positive/negative int values, using 0 to indicate the end of partially filled arraycout <"enter up="" to="" "="">"enter>< capacity-1="">< "="" non-zero="" integers,="" enter="" 0="" to="" end="" when="" you="" are="">
//To do: Write a loop to read up the int values and store them into array a.// Stop reading if the user enters 0 or the array a is full.
//To do: store 0 to indicate the end of values in the array
//Display array functionprintArray(array);return 0;}
// To do: implement display for the given arrayvoid printArray(int array[]){}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here