Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that accepts input like the program in Display 7.8and that outpu

ID: 638144 • Letter: W

Question

Write a program that accepts input like the program in Display 7.8and that outputs a bar graph like the one in that display exceptthat your program will output the bars vertically rather thanhorizontally. A two-dimensional array may be useful.

Thats the question and here is what Display 7.8 looks like

#include <iostream>

#include <cmath>

const int NUMBER_OF_PLANTS = 4;

void input_data(int a[], int last_plant_number);

void scale(int a[], int size);

void graph(const int asterisk_count[], int last_plant_number);

void get_total(int& sum);

int round(double number);

void print_asterisks(int n);

int main()

{

using namespace std;

int production[NUMBER_OF_PLANTS];

cout << "This program displays agraph showing "

<< "production foreach plant in the company. ";

input_data(production,NUMBER_OF_PLANTS);

scale(production, NUMBER_OF_PLANTS);

graph(production, NUMBER_OF_PLANTS);

return 0;

}

void input_data(int a[], int last_plant_number)

void get_total(int& sum)

void scale(int a[], int size)

int round(double number)

void graph(const int asterisk_count[], int last_plant_number)

{

using namespace std;

cout << " Units produced inthousands of units: ";

for (int plant_number = 1;

plant_number <= last_plant_number; plant_number++)

{

cout << "Plant #"<< plant_number << " ";

print_asterisks (asterisk_count[plant_number - 1]);

cout << endl;

}

}

void print_asterisks(int n)

{

using namespace std;

for (int count = 1; count <= n;count++)

cout << "*";

}

I guess the problem is, that I cant even get this to work. I have typed it in several times and was wondering if there is something obvious I am missing.

Explanation / Answer

i tried in differnt way..but its working it may help you

#include <iostream>
#include <iomanip>
using namespace std;


void printStars(int numStars ) {
for ( int i = 0; i < numStars; i++ ) {
cout << "*" ;
}
cout << endl;
}


int main() {
const int SIZE = 20;
int n[SIZE];
int count = 0; // keeps track of how many numbers the user has typed in.

int inputFromUser;

do {
cout << "Please enter a number between 0 and 70 (-1 to stop): ";
cin >> inputFromUser;

  
if ( inputFromUser != -1 && ((inputFromUser >= 0) && (inputFromUser <= 70))) {
// this number is valid. Put inputFromUser into array
n[count] = inputFromUser;
count++;
}

} while ( inputFromUser != -1 ) ;
  

for ( int i = 0; i < count; i++ ) {
  
cout << i + 1 << " - " << setw(2) << n[i] << ": " ; printStars ( n[i] );

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote