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
Binary search requires that data to search be in order. true or false
Iteru [2.4K]
<span>Binary search requires that data to search be in order.
The answer is true
Hope this help!!</span>
5 0
3 years ago
When records are in ____ order, they are arranged one after another on the basis of the value in a particular field.?
Nat2105 [25]
When records are in ASCENDING order ...
4 0
3 years ago
Consider the packets exchanged in TCP connection setup between Host A and Host B. Assume that Host A's initial sequence number i
Rasek [7]

Answer:

I think that part C correct option

6 0
3 years ago
Describe some common types of charts.​
Mekhanik [1.2K]
Bar chart.
Pie chart.
Line chart.
4 0
3 years ago
Read 2 more answers
A typical broadcast live events and use streaming technology in which audio and video files are continuously downloaded to your
Nikitich [7]

Answer:

Webcasts

Explanation:

The rest of the options don't need to be streamed as there isn't a continuous flow of information.

7 0
3 years ago
Other questions:
  • A Web ____ is a software program that retrieves the page and displays it. Select one:
    5·1 answer
  • _________ is critical to Amazon's success.<br><br> SCM<br><br> JIT<br><br> ERP<br><br> VMI
    9·1 answer
  • Is there a relationship between cybercrime and traditional crime?
    6·1 answer
  • The variable most_recent_novel is associated with a dictionary that maps the names of novelists to their most recently published
    12·1 answer
  • Why are online payment services necessary?
    10·2 answers
  • If you wish to sign out of your Microsoft account, tap or click ____ on the ribbon to open the Backstage view and then tap or cl
    10·1 answer
  • Plz subscribe my yt gaming channel <br>FIREAZZ GAMING​
    8·2 answers
  • Python will ignore any line of code that begins with hashtag true or false​
    13·2 answers
  • 1.Microsoft Word is a/an ........​
    8·2 answers
  • Which of the examples is part client side code
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!