Write a program that accepts input like the program in Display 7.8and that outpu
ID: 3616760 • 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.//DISPLAY 7.8 Production Graph Program //Reads data and displays a bar graph showing productivity foreach plant. #include <iostream> #include <cmath> const int NUMBER_OF_PLANTS = 4;
void input_data(int a[], int last_plant_number); //Precondition: last_plant_number is the declared size of thearray a. //Postcondition: For plant_number = 1 throughlast_plant_number: //a[plant_number-1] equals the total production for plantnumber plant_number.
void scale(int a[], int size); //Precondition: a[0] through a[size-1] each has a nonnegativevalue. //Postcondition: a[i] has been changed to the number of 1000s(rounded to //an integer) that were originally in a[i], for all i suchthat 0 <= i <= size -1. void graph(const int asterisk_count[], intlast_plant_number); //Precondition: asterisk_count[0] throughasterisk_count[last_plant_number-1] //have nonnegative values. //Postcondition: A bar graph has been displayed saying thatplant //number N has produced asterisk_count[N-1] 1000s of units,for each N such that //1 <= N <= last_plant_number
void get_total(int& sum); //Reads nonnegative integers from the keyboard and //places their total in sum.
int round(double number); //Precondition: number >= 0. //Returns number rounded to the nearest integer.
void print_asterisks(int n); //Prints n asterisks to the screen.
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; }
//Uses iostream: void input_data(int a[], int last_plant_number) //The rest of the definition of input_data is given in Display7.6.
//Uses iostream: void get_total(int& sum) //The rest of the definition of get_total is given in Display7.6.
void scale(int a[], int size) //The rest of the definition of scale is given in Display7.7.
//Uses cmath: int round(double number) //The rest of the definition of round is given in Display7.7. //Uses iostream: void graph(const int asterisk_count[], intlast_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; } }
//Uses iostream: void print_asterisks(int n) { using namespace std; for (int count = 1; count <= n;count++) cout << "*"; }
//DISPLAY 7.8 Production Graph Program //Reads data and displays a bar graph showing productivity foreach plant. #include <iostream> #include <cmath> const int NUMBER_OF_PLANTS = 4;
void input_data(int a[], int last_plant_number); //Precondition: last_plant_number is the declared size of thearray a. //Postcondition: For plant_number = 1 throughlast_plant_number: //a[plant_number-1] equals the total production for plantnumber plant_number.
void scale(int a[], int size); //Precondition: a[0] through a[size-1] each has a nonnegativevalue. //Postcondition: a[i] has been changed to the number of 1000s(rounded to //an integer) that were originally in a[i], for all i suchthat 0 <= i <= size -1. void graph(const int asterisk_count[], intlast_plant_number); //Precondition: asterisk_count[0] throughasterisk_count[last_plant_number-1] //have nonnegative values. //Postcondition: A bar graph has been displayed saying thatplant //number N has produced asterisk_count[N-1] 1000s of units,for each N such that //1 <= N <= last_plant_number
void get_total(int& sum); //Reads nonnegative integers from the keyboard and //places their total in sum.
int round(double number); //Precondition: number >= 0. //Returns number rounded to the nearest integer.
void print_asterisks(int n); //Prints n asterisks to the screen.
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; }
//Uses iostream: void input_data(int a[], int last_plant_number) //The rest of the definition of input_data is given in Display7.6.
//Uses iostream: void get_total(int& sum) //The rest of the definition of get_total is given in Display7.6.
void scale(int a[], int size) //The rest of the definition of scale is given in Display7.7.
//Uses cmath: int round(double number) //The rest of the definition of round is given in Display7.7. //Uses iostream: void graph(const int asterisk_count[], intlast_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; } }
//Uses iostream: void print_asterisks(int n) { using namespace std; for (int count = 1; count <= n;count++) cout << "*"; } //DISPLAY 7.8 Production Graph Program //Reads data and displays a bar graph showing productivity foreach plant. #include <iostream> #include <cmath> const int NUMBER_OF_PLANTS = 4;
void input_data(int a[], int last_plant_number); //Precondition: last_plant_number is the declared size of thearray a. //Postcondition: For plant_number = 1 throughlast_plant_number: //a[plant_number-1] equals the total production for plantnumber plant_number.
void scale(int a[], int size); //Precondition: a[0] through a[size-1] each has a nonnegativevalue. //Postcondition: a[i] has been changed to the number of 1000s(rounded to //an integer) that were originally in a[i], for all i suchthat 0 <= i <= size -1. void graph(const int asterisk_count[], intlast_plant_number); //Precondition: asterisk_count[0] throughasterisk_count[last_plant_number-1] //have nonnegative values. //Postcondition: A bar graph has been displayed saying thatplant //number N has produced asterisk_count[N-1] 1000s of units,for each N such that //1 <= N <= last_plant_number
void get_total(int& sum); //Reads nonnegative integers from the keyboard and //places their total in sum.
int round(double number); //Precondition: number >= 0. //Returns number rounded to the nearest integer.
void print_asterisks(int n); //Prints n asterisks to the screen.
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; }
//Uses iostream: void input_data(int a[], int last_plant_number) //The rest of the definition of input_data is given in Display7.6.
//Uses iostream: void get_total(int& sum) //The rest of the definition of get_total is given in Display7.6.
void scale(int a[], int size) //The rest of the definition of scale is given in Display7.7.
//Uses cmath: int round(double number) //The rest of the definition of round is given in Display7.7. //Uses iostream: void graph(const int asterisk_count[], intlast_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; } }
//Uses iostream: void print_asterisks(int n) { using namespace std; for (int count = 1; count <= n;count++) cout << "*"; }
Explanation / Answer
please rate - thanks I had to change the variable name round to roundd--my compilercomplained about a conflict with the math library //DISPLAY 7.8 Production Graph Program //Reads data and displays a bar graph showing productivity for eachplant. #include #include #include const int NUMBER_OF_PLANTS = 4; void input_data(int a[], int last_plant_number); //Precondition: last_plant_number is the declared size of the arraya. //Postcondition: For plant_number = 1 throughlast_plant_number: //a[plant_number-1] equals the total production for plant numberplant_number. void scale(int a[], int size); //Precondition: a[0] through a[size-1] each has a nonnegativevalue. //Postcondition: a[i] has been changed to the number of 1000s(rounded to //an integer) that were originally in a[i], for all i such that 0Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.