1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vova2212 [387]
3 years ago
14

Remember partially filled arrays where the number of elements stored in the array can be less than its capacity (the maximum num

ber of elements allowed). We studied two different ways to represent partially filled arrays: 1) using an int variable 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 parameter
int main()
{
const int CAPACITY=21;
int array[CAPACITY]; // store positive/negative int values, using 0 to indicate the end of partially filled array
cout <<"Enter up to " << CAPACITY-1 << " non-zero integers, enter 0 to end when you are done\n";
//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 function
printArray(array);
return 0;
}
// To do: implement display for the given array
void printArray(int array[])
{
}
Computers and Technology
1 answer:
MrMuchimi3 years ago
8 0

Answer:

Complete the main method as follows:

int num;

cin>>num;

int i = 0;

while(num!=0){

array[i] = num;  

cin>>num;

i++;

}

Complete the printArray function as follows:

void printArray(int array[]){

int i =0;

while(array[i]!=0){

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

   i++;

}}

Explanation:

<u>Main method</u>

This declares a variable that gets input from the user

int num;

This gets input from the user

cin>>num;

This initializes a count variable to 0. It represents the index of the current array element

int i = 0;

while(num!=0){

This inserts the inputted number to the array

array[i] = num;

This gets another input  

cin>>num;

The counter is incremented by 1

i++;

}

The above loop is repeated until the users enters 0

<u>printArray method</u>

This declares the array

void printArray(int array[]){

This initializes a counter variable to 0

int i =0;

This is repeated until array element is 0

while(array[i]!=0){

Print array element

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

Increase counter by 1

   i++;

}}

<em>See attachment for complete program</em>

Download cpp
You might be interested in
Which Application program saves data automatically as it is entered?
Andrei [34K]
The application program that saves data automatically as it is entered is the MS Access.
4 0
3 years ago
Please, give me a comic or story idea. I will mark brainliest. ( i need 5 slides with 2 characters in the story or comic) Please
salantis [7]

Answer:

Jack and John

Explanation:

Jack called John and offered him to come with him and some other friends to go out to the mall.

.....

8 0
3 years ago
Read 2 more answers
Which of the following are the two main types of copyright relevant to the recording industry? Select all that apply
Bond [772]

Answer:

LETTER A...

CUZ ITS TRUE

6 0
3 years ago
What is one outcome of an integration point?
mylen [45]

Answer:

What is one outcome of an integration point? It provides information to a system builder to potentially pivot the course of action. It bring several Kanban processes to conclusion. It supports SAFe budgeting milestones.

5 0
3 years ago
The elements in a dictionary are not stored in a specific order. Therefore, a dictionary is not a(n) ________.
zlopas [31]

Answer:

Sequence.

Explanation:

The elements in a dictionary are not stored in a specific order. Therefore, a dictionary is not a sequence.

This ultimately implies that, the elements present in a dictionary are not organized or sorted.

5 0
3 years ago
Other questions:
  • Suppose you have two arrays of ints, arr1 and arr2, each containing ints that are sorted in ascending order. Write a static meth
    7·1 answer
  • Research and identify at least five specialized search engines and their applications.
    12·1 answer
  • Suppose you have one particular application that is trying to send data on the Internet but none of the data is making it to the
    15·2 answers
  • Which type of graph or chart measures
    15·2 answers
  • How much time per day does the average U.S. youth spend watching television, playing video games, or using a computer?
    8·1 answer
  • What is the easiest way to create a diverse set of cover pages?<br><br> Word 2016
    11·2 answers
  • How do I create a powershell script to make a Windows user account that is a non-admin user
    7·1 answer
  • 10. List three adaptations of wind-pollinated plants to promote pollination.<br>​
    12·1 answer
  • Which statement best defines the Control Pannel?
    12·1 answer
  • Which organization or agency would assist the fire department with incident scene security, crowd control, and explosives dispos
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!