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]
2 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:
MrMuchimi2 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
AYYOOOO CAN YOU HELP A GIRL OUUTT???
goblinko [34]

Answer: The answer is true

8 0
2 years ago
The range of an area where users can access the Internet via high frequency radio signals transmitting an Internet signal from a
Alexandra [31]
A) hotspot
Bluetooth is for short distance and pan is Personal area networks (PANs) connect an individual's personal devices
8 0
3 years ago
Read 2 more answers
A program has a infinite while loop. How can you interrupt it?
MrRa [10]

Answer:

The <em>break</em> keyword is how you interrupt a while loop.

the syntax looks like this ↓

Python ↓

while <em>true</em>:

<em>break</em>

Java script ↓

while (<em>true</em>);

<em>break</em>

6 0
2 years ago
Tools used to build a bridge<br>​
Sati [7]

Aerial Lifts,

Vertical Masts and Hydro Platforms,

Telehandlers,

Excavators,

Skid Loaders,

Backhoes,

Cranes,

Air Compressors.

If It was helpful, can you make me brainliest please?

6 0
2 years ago
Data in the form of digits is called
Flauer [41]
Numeric data because it consist of numbers
5 0
2 years ago
Other questions:
  • Write a function named shareALetter that takes one parameter, wordList – a list of words. Create and return a dictionary in whic
    13·1 answer
  • what is the primary way to access applications in windows 8? a. control panel b. start menu c. desktop tiles d. context menu
    7·1 answer
  • Which computer is the best for video cutting?
    11·2 answers
  • Which of the following menu commands would you select to make a copy of an open file and rename it?
    15·1 answer
  • What is the major benefit Smartphones and tablet computers have had on social media?
    9·1 answer
  • How do you resolve conflicts in your life??
    11·1 answer
  • What is the primary purpose of source code editor features such as keyword hi lighting and auto-completion A.to speed up the cod
    7·1 answer
  • It is where your cpu (processor) is installed
    10·2 answers
  • Write a program named as reverse.c that reads a message, then prints the reversal of the message. The output of the program shou
    7·1 answer
  • Davingould1115...................answer 2​
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!