Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Discover reliable solutions to your questions from a wide network of experts on our comprehensive Q&A platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

At the beginning of the semester, we studied partially filled arrays. This is when the number of elements stored may be less than the maximum number of elements allowed. There are two different ways to keep track of partially filled arrays: 1) use a variable for the numberElements or 2) use a sentinel (terminating} value at the end of elements (remember c-strings?). In the code below, please fill in the details for reading the values into the an array that uses a sentinel value of -1. Complete the showArray function as well.
#include
using namespace std;
void showArray(int array[]);
// ToDo: Code showArray function with one array parameter
int main()
{
const int MAX_SIZE=16;
int array[MAX_SIZE]; // store positive values, using -1 to end the values.
cout <<"Enter up to " << MAX_SIZE-1 << " positive whole numbers, use -1 to stop\n";
//To do: Read the int values and save them in the static array variable.
// When the user enters -1 or the array has no more room, leave the loop..
//To do: store -1 at the end of elements in the array
// Show array function
showArray(array);
return 0;
}
// To do: print out for the array
void showArray(int array[])
{
}

Sagot :

Answer:

Complete the main as follows:

int num;

cin>>num;

int i = 0;

while(num!=-1 && i <16){

array[i] = num;

cin>>num;

i++;  }

array[i+1] = -1;

The showArray() as follows:

int i =0;

while(array[i]!=0){

   cout<<array[i]<<" ";

   i++;

}

Explanation:

See attachment for complete program where comments are used to explain difficult lines

View image MrRoyal