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
Gelneren [198K]
3 years ago
11

Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a num

ber (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...".The program will ask the user to enter a non-zero positive number. Using a while loop, validate that the number is not greater than 40, and if so, re-ask for the number. Put the entire program into a sentinel-controlled loop so that the user can enter either zero (0) or a negative number to end the program.Create constants for 1 (the minimum number for the histogram), and 40 (the maximum number for the histogram), and use these constants in the prompts, the validation condition and error message, and the sentinel-controlled loop and the histogram loop.
Engineering
1 answer:
lilavasa [31]3 years ago
6 0

Answer:

// CPP program to make histogram of an array

#include <bits/stdc++.h>

using namespace std;

void printHistogram(int arr[], int n)

{

int maxEle = *max_element(arr, arr + n);

for (int i = maxEle; i >= 0; i--) {

cout.width(2);

cout << right << i << " | ";

for (int j = 0; j < n; j++) {

// if array of element is greater

// then array it print x

if (arr[j] >= i)

cout << " x ";

// else print blank spaces

else

cout << " ";

}

cout << "\n";

}

// print last line denoted by ----

for (int i = 0; i < n + 3; i++)

cout << "---";

cout << "\n";

cout << " ";

for (int i = 0; i < n; i++) {

cout.width(2); // width for a number

cout << right << arr[i] << " ";

}

}

// Driver code

int main()

{

int arr[10] = { 10, 9, 12, 4, 5, 2,

8, 5, 3, 1 };

int n = sizeof(arr) / sizeof(arr[0]);

printHistogram(arr, n);

return 0;

}

Explanation:

The idea is to print the given histogram row by row. For every element, we check if it is greater than or equal to current row. If yes, put a ‘x’ for that element. Else we put a space.

You might be interested in
The blade tension is correct when you can hear a<br>O Thunk<br>O Twang<br>O Neither​
Anastaziya [24]

Answer:

maybe it's twang because of the blade tension

3 0
3 years ago
A mass of 5 kg of saturated liquid-vapor mixture of water is contained in a piston-cylinder device at 125 kPa. Initially, 2 kg o
Likurg_2 [28]

Answer:

See attached pictures.

Explanation:

See attached pictures for detailed explanation.

8 0
4 years ago
A rigid tank having 25 m3 volume initially contains air having a density of 1.25 kg/m3, then more air is supplied to the tank fr
Hoochie [10]

Answer:

\Delta m = 102.25\,kg

Explanation:

The mass inside the rigid tank before the high pressure stream enters is:

m_{o} = \rho_{air}\cdot V_{tank}

m_{o} = (1.25\,\frac{kg}{m^{3}} )\cdot (25\,m^{3})

m_{o} = 31.25\,kg

The final mass inside the rigid tank is:

m_{f} = \rho \cdot V_{tank}

m_{f} = (5.34\,\frac{kg}{m^{3}} )\cdot (25\,m^{3})

m_{f}= 133.5\,kg

The supplied air mass is:

\Delta m = m_{f}-m_{o}

\Delta m = 133.5\,kg-31.25\,kg

\Delta m = 102.25\,kg

4 0
3 years ago
HELP I NEED HELP!!!111!11!111 WILL GIVE BRAINLIEST AND 69 POINTS
Dafna1 [17]
It would be Animals break down food molecules to obtain energy, the remains of producers are broken down by decomposers, and producers make sugar and starches.
A, B, and E.
8 0
3 years ago
You recall an algorithm from elementary school for factoring a number N: Divide out all factors of 2, then of 3, then of 4, then
Contact [7]

Answer:

let number = 0

while number < 1

  begin

     print "Enter a positive integer: "

     read number

  end

end_while

find and print number's factors:

let prime = TRUE

let currentFactor = 2

let lastFactor = the square root of number truncated

  to an integer value

while currentFactor <= lastFactor

  begin

     if number is evenly divisible by currentFactor

        begin

           print currentFactor

           let number = number / currentFactor

        end

     else

        let currentFactor = currentFactor + 1

     end_if

  end

end_while

print a message if number is prime:

if prime == TRUE

  print "Your number is prime"

end_if

Explanation:

4 0
3 years ago
Other questions:
  • A water jet that leaves a nozzle at 95 m/s at a flow rate of 120 kg/s is to be used to generate power by striking the buckets lo
    14·1 answer
  • A cylindrical specimen of a hypothetical metal alloy is stressed in compression. If its original and final diameters are 19.636
    7·1 answer
  • Cavitation in pump assemblies can be avoided by decreasing tank pressure. a)-True b)-False
    10·1 answer
  • You are using a Geiger counter to measure the activity of a radioactive substance over the course of several minutes. If the rea
    6·1 answer
  • What is clearance? What is backlash? What is interference? Explain briefly.
    6·1 answer
  • A carbon resistor has a resistance of 976 ohms at 0 degrees C. Determine its resistance at 89 degrees C​
    6·1 answer
  • The worst time you have had with a mechanical issue
    7·2 answers
  • Explain when single-stranded or multistranded wire should be used.
    13·1 answer
  • Five identical keys are suspended from a balance, which is held horizontally as shown. The two keys on the left are attached to
    11·1 answer
  • As part of its commitment to sustainability, a company is looking for a way to track the source of purchased goods and how they
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!