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 of these is a placeholder in a document into which variable data is inserted during the process of a mail merge?
Margarita [4]

Answer: C. Merge Field.

The Merge Field is a placeholder that holds the variable data that will be inserted into the main document during a mail merge procedure. The columns in a document may represent the categories of information. The Rows represent the records of the different columns. The computer counts a row of data to be a single record.

7 0
3 years ago
Read 2 more answers
9. which of the following cities is not considered one of the top game development hotbeds?
Kitty [74]

Answer:

9. C

10. C

Explanation:

I hope it can help

3 0
3 years ago
What indicator displays in a cell that contains a comment? red indicator triangle blue indicator triangle green triangle red squ
mixer [17]
Are you talking about like a notification??

if so it is a red square
3 0
3 years ago
When actual hardware, network, and system software components are acquired and installed, they make up a(n) ____ for one or more
Kobotan [32]
Description i think i remember
7 0
3 years ago
Insurance can help you:
Scorpion4ik [409]
Hello,

Here is your answer:

The proper answer to this question is that insurance can help you..."recover something that was damaged or loss." For example if your vehicle gets damage insurance helps you fix it or if your home gets robbed insurance will help you get your things back!

If you need anymore help feel free to ask me!

Hope this helps!
6 0
4 years ago
Other questions:
  • By generating and delivering timely and relevant information supported by networks, _____ creates new opportunities for conducti
    15·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    10·1 answer
  • Houston want to have a quick conversion with his friend about an upcoming school activity. which type of website would be most u
    12·2 answers
  • What is the primary way to access applications in window 10
    7·1 answer
  • I'd: 9872093250, password: qqqqq, join the meeting​
    11·1 answer
  • Explain the four misconceptions about entrepreneurship.
    7·1 answer
  • Hi good morning how are you all
    12·2 answers
  • Which memory can be removed from motherboard? RAM OR ROM?​
    7·1 answer
  • Define the following:-<br><br>1) cryptography<br><br>2) Quantum Cryptography​
    10·2 answers
  • When scriptwriters are writing scripts, why do they have to write them in accordance with industry standards?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!