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
Consider a new peer Alice that joins BitTorrent without possessing any chunks. Without any chunks,she cannot become a top-four u
Airida [17]

Answer:She will be selected by "Optimistic Unchoking".

Explanation:BitTorrent is a communication protocol for peer-to-peer file sharing (P2P) it is used to distribute data and electronic files over the Internet.

Optimistic unchoking is an important factor in BitTorrent peer-to-peer (P2P) file sharing networks, with optimistic unchocking there is always one peer that is unchocked.

BitTorrent Peers use optimistic unchoking to find the upload bandwidth details concerning other peers.

However, free users have been known to also make use of optimistic unchoking and download from the network without uploading anything.

7 0
3 years ago
To reduce the global emission of greenhouse gases, which of the following would be theMOST effective and practical lifestyle cha
Anestetic [448]

Answer:

C. Decrease your consumption of beef.

Explanation:

The production of beef needs lots of land, which leads to trees being cut down, releasing carbon dioxide. Also, the ruminant animals used to produce beef end up farting a lot from their diets, and these farts are of high metane, which leads to greenhouse gases being emitted in the athmosphere.

Common plant proteins, otherwise, produce way less of these gases.

So the correct answer is:

C. Decrease your consumption of beef.

4 0
3 years ago
Two automobiles A and B, of mass mA and mB, respectively are traveling in opposite directions when they collide head on. The imp
Novosadov [1.4K]

Answer:

EA = 180KJ

EB = 320KJ

Where EA and EB, are the energy absorbed by automobile A and by automobile B

Explanation:

The concept of momentum and energy is applied here as it relates to elastic and inelastic collision.

The detailed steps, mathematical manipulation and appropriate substitution is as shown in the attached file.

8 0
4 years ago
Read 2 more answers
What is the base unit in standard measurement
Stella [2.4K]

Answer:

Explanation:SI is the base unit for standard measurement

7 0
3 years ago
Read 2 more answers
An air-standard dual cycle has a compression ratio of 9.1 and displacement of Vd = 2.2 L. At the beginning of compression, p1 =
jok3333 [9.3K]

Answer:

a) T₂ is 701.479 K

T₃ is 1226.05 K

T₄ is 2350.34 K

T₅ is 1260.56 K

b) The net work of the cycle in kJ is 2.28 kJ

c) The power developed is 114.2 kW

d) The thermal efficiency, \eta _{dual} is 53.78%

e) The mean effective pressure is 1038.25 kPa

Explanation:

a) Here we have;

\frac{T_{2}}{T_{1}}=\left (\frac{v_{1}}{v_{2}}  \right )^{\gamma -1} = \left (r  \right )^{\gamma -1} = \left (\frac{p_{2}}{p_{1}}  \right )^{\frac{\gamma -1}{\gamma }}

Where:

p₁ = Initial pressure = 95 kPa

p₂ = Final pressure =

T₁ = Initial temperature = 290 K

T₂ = Final temperature

v₁ = Initial volume

v₂ = Final volume

v_d = Displacement volume =

γ = Ratio of specific heats at constant pressure and constant volume cp/cv = 1.4 for air

r = Compression ratio = 9.1

Total heat added = 4.25 kJ

1/4 × Total heat added = c_v \times (T_3 - T_2)

3/4 × Total heat added = c_p \times (T_4 - T_3)

c_v = Specific heat at constant volume = 0.718×2.821× 10⁻³

c_p = Specific heat at constant pressure = 1.005×2.821× 10⁻³

v₁ - v₂ = 2.2 L

\left \frac{v_{1}}{v_{2}}  \right =r  \right = 9.1

v₁ = v₂·9.1

∴ 9.1·v₂ - v₂ = 2.2 L  = 2.2 × 10⁻³ m³

8.1·v₂ = 2.2 × 10⁻³ m³

v₂ = 2.2 × 10⁻³ m³ ÷ 8.1 = 2.72 × 10⁻⁴ m³

v₁ = v₂×9.1 = 2.72 × 10⁻⁴ m³ × 9.1 = 2.47 × 10⁻³ m³

Plugging in the values, we have;

{T_{2}}= T_{1} \times \left (r  \right )^{\gamma -1}  = 290 \times 9.1^{1.4 - 1} = 701.479 \, K

From;

\left (\frac{p_{2}}{p_{1}}  \right )^{\frac{\gamma -1}{\gamma }}= \left (r  \right )^{\gamma -1} we have;

p_{2} = p_{1}} \times \left (r  \right )^{\gamma } = 95 \times \left (9.1  \right )^{1.4} = 2091.13 \ kPa

1/4×4.25 =  0.718 \times 2.821 \times  10^{-3}\times (T_3 - 701.479)

∴ T₃ = 1226.05 K

Also;

3/4 × Total heat added = c_p \times (T_4 - T_3) gives;

3/4 × 4.25 = 1.005 \times 2.821 \times  10^{-3} \times (T_4 - 1226.05) gives;

T₄ = 2350.34 K

\frac{T_{4}}{T_{5}}=\left (\frac{v_{5}}{v_{4}}  \right )^{\gamma -1} = \left (\frac{r}{\rho }  \right )^{\gamma -1}

\rho = \frac{T_4}{T_3} = \frac{2350.34}{1226.04} = 1.92

T_{5} =  \frac{T_{4}}{\left (\frac{r}{\rho }  \right )^{\gamma -1}}= \frac{2350.34 }{\left (\frac{9.1}{1.92 }  \right )^{1.4-1}} =1260.56 \ K

b) Heat rejected =  c_v \times (T_5 - T_1)

Therefore \ heat \ rejected =  0.718 \times 2.821 \times  10^{-3}\times (1260.56 - 290) = 1.966 kJ

The net work done = Heat added - Heat rejected

∴ The net work done = 4.25 - 1.966 = 2.28 kJ

The net work of the cycle in kJ = 2.28 kJ

c) Power = Work done per each cycle × Number of cycles completed each second

Where we have 3000 cycles per minute, we have 3000/60 = 50 cycles per second

Hence, the power developed = 2.28 kJ/cycle × 50 cycle/second = 114.2 kW

d)

Thermal \ efficiency, \, \eta _{dual} =  \frac{Work \ done}{Heat \ supplied} = \frac{2.28}{4.25} \times 100 = 53.74 \%

The thermal efficiency, \eta _{dual} = 53.78%

e) The mean effective pressure, p_m, is found as follows;

p_m = \frac{W}{v_1 - v_2} =\frac{2.28}{2.2 \times 10^{-3}} = 1038.25 \ kPa

The mean effective pressure = 1038.25 kPa.

3 0
4 years ago
Other questions:
  • Consider a very long, slender rod. One end of the rod is attached to a base surface maintained at Tb, while the surface of the r
    8·1 answer
  • Women make up about 20% of the workforce in the aviation industry. With such a small percentage of female employees, JetBlue mus
    8·2 answers
  • As a talented grad of CMPEN 270, your new job as a digital designer is to design a "greedy" vending machine that accepts only ni
    6·1 answer
  • A 25-W compact fluorescent lightbulb (CFL) produces the light equivalent of a 100-W incandescent bulb. The population of North A
    14·1 answer
  • What are some common ways of converting fuel to useful energy? Check all that apply.
    9·2 answers
  • What are the potential hazards relating to materials handling injuries?
    12·2 answers
  • A schizophrenic disorder is characterized mostly by disturbed __________, while a mood disorder is characterized mostly by distu
    6·2 answers
  • Thanks for the help!
    11·1 answer
  • two students were talking student a was examining the lettuce leaves in a salad he was eating . he said, did you know im eating
    12·1 answer
  • Arm coverings can NOT protect you from cuts or puncture wounds. Is this statement<br> TRUE or FALSE?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!