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
vodomira [7]
3 years ago
9

Write a complete C++ program that do following. Read a positive integer from the user with proper prompt. Assume that this user

is nice and he/she would not start the integer with digit 0. Create a size 10 array as counters for digits 0 - 9 Use a while loop for processing

Computers and Technology
1 answer:
exis [7]3 years ago
5 0

Answer:

The cpp program for the given scenario is shown below.

#include <stdio.h>

#include <iostream>

using namespace std;

int main()

{

//variable for while loop

   int n=0;

   //size of array declared

   int size=10;

   //integer array declared

   int num[size];

   //user enters elements for the array inside while loop

   while(n<size)

   {

       std::cout << "Enter a positive number: ";

       cin>>num[n];

n++;

   }

   std::cout << "Thanks for entering the numbers. Program ends." << std::endl;

   return 0;

}

Explanation:

1. The integer variable, size, is declared and initialized to hold the size of the array.

int size=10;

2. Another integer variable, n, is declared to be used in the while loop.

int n=0;

3. An integer array, num, is declared having the capacity of integer variable, size.

int num[size];

4. Inside the while loop, the user is prompted to enter a positive number.

std::cout << "Enter a positive number: ";

5. The user-entered number is assigned directly to the array.

cin>>num[n]

6. After input is taken, the variable n is incremented by 1.

n++;

7. The while loop executes over variable n for the range of values from 0 to size-1,  i.e., until the array is filled. The first index of the array is 0 and increments henceforth. The variable is declared outside the loop unlike the for loop.

while(n<size)

8. In this program, all the code is written inside main().

9. Since cpp is not a purely object-oriented language, it is not mandatory to write the code inside the class for a simple program like this.

10. The program ends with a message for the user.

std::cout << "Thanks for entering the numbers. Program ends." << std::endl;

11. The return statement indicates the end of main() method.

return 0;

12. The output of the program is attached as an image.

13. The program can be tested for any value of variable size.

You might be interested in
Given the function definition below, what is the effect of thecall:
Romashka-Z-Leto [24]

Answer:

Hi!

The correct answer is E.

Explanation:

void change(int ar[], int low, inthigh)  {  

 int temp;

 if(low< high)  {  <em>// here ask if the positions low and high of the array are the same.</em>

  temp= ar[low];  <em>// first, saves the element on ar[low] in temp.</em>

  ar[low]= ar[high];  <em>// second, the element on ar[high] in ar[low]. First switch.</em>

  ar[high]= temp;  <em>// third, saves the element on temp in ar[high]. Complete switch.</em>

  change(ar,low + 1, high - 1);  <em>// Recursive call, adding one position to low, and subtracting one position to high. </em><em>Important: </em><em>When low and high have the same value, the recursive call will finish.</em>

}

}

Result: Switch the lower half of elements in the array with the upper half.

8 0
3 years ago
Read 2 more answers
Find different between manocots and dicots clarify with example​
Fantom [35]

Answer:

hope it's help you..............

7 0
2 years ago
The first tools that analyzed and extracted data from floppy disks and hard disks were MS-DOS tools for ____ PC file systems.
netineya [11]

<u>The first tools that analyzed and extracted data from floppy disks and hard disks were MS-DOS tools for </u><u>IBM</u><u> PC file systems</u>. A file system is a structured representation of data and a set of metadata describing this data. The file system of the IBM supports stream input/output and storage management, providing a structure over all information stored in the system. A floppy disk consists of a thin plastic disk coated with magnetic material (it was designed by IBM in the early 1970s). A hard disk is fixed on the system unit. It is made up of several circular disks called platters. MS-DOS (Microsoft Disk Operating System) is a licensed operating system for use on microcomputers from various manufacturers.

6 0
3 years ago
Hat are three machines or devices that depend on gravity to work?
jonny [76]
Some devices that depend on gravity to function include scales, showers, and satellites, to list a few.
6 0
3 years ago
AYYOOOO CAN YOU HELP A GIRL OUUTT???
goblinko [34]

Answer: The answer is true

8 0
2 years ago
Other questions:
  • This program will output a right triangle based on user specified height triangle_height and symbol triangle_char. (1) The given
    9·1 answer
  • A security policy is a
    11·1 answer
  • What are the basic tools for coding HTML manually?
    10·2 answers
  • What problem with internal hardware components is similar to unplugged
    6·2 answers
  • Loops are frequently used to ____; that is, to make sure it is meaningful and useful.
    12·1 answer
  • Software is nothing but a piece of code or set of instructions written in a chip to run a hardware device on the Computer. O Tru
    14·1 answer
  • An instruction book or program that takes users through a prescribed series of steps to learn how to use a program is called (a)
    10·1 answer
  • Blood Alcohol Level (BAL) is the ratio between the alcohol consumed and the blood in the body. A. True B. False
    12·2 answers
  • 6. Find the volume of the figure. Round your answers to the nearest
    11·1 answer
  • Which of the following statements describe the benefits of a career in transportation, distribution, and logistics (TDL)?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!