Question: using c + + graphics ( graphlib 2 0 2 2 , graph.h ) I need my progam to constuct a bar graph like in

using c++ graphics (graphlib2022, graph.h) I need my progam to constuct a bar graph like in the image. In the function void displayResults(int sales[], int no_months, int max, int min, double avg);
For this example, month #1 corresponds to January, month #2 corresponds to February, and so on up to June corresponding to month #6. This program will next display the sales data in the form of a bar chart. The bar chart that this program generates consists of the following:
1. An x/y axis
2. Rectangles representing the percentage of sales for a given month
3. The given months abbreviation displayed above its rectangle
4. An image and text used as the bar charts heading/title
5. An informational box containing a summary of the sales data statistics
Note that the height of each rectangle is based on the sales for that given month. The equation for computing the height for each rectangle is:
height =((double)sales[i]/max)*100.0;
where sales[i] is the ith sales value, and max is the maximum sales value (for this example its 13000). The variable height is measured in pixels and should be declared as an int. The minimum value for height is set to 1(not 0). In other words, if height 1, reset it to exactly 1. The suggested width of each rectangle is 50. The suggested horizontal distance between each rectangle is 25. The suggested length of the vertical axis is 150px while the suggested length of the horizontal axis is 440px.
Note: For this example, the height for Feb is computed as
height =(100/13000)*100
which results in an integer value of 0. Since the minimum allowable value for height is 1, reset height to 1(not 0).
Observe that there is a very small green rectangle under the Feb heading that has a height of only 1 pixel. This is due to the sales for the month of Feb is 1.
Each months rectangle should be colored as follow:
January - Red (255,0,0)
February - Green (0,255,0)
March - Blue (0,0,255)
April - Yellow (255,255,0)
May - Magenta (255,0,255)
June - Turquoise (0,255,255)
This is what I have so far
#include
#include "graph1.h"
#include
using namespace std;
int getNoMonths();
void getSales(int sales[], int no_months);
int getMax(int sales[], int no_months);
int getMin(int sales[], int no_months);
double getAverage(int sales[], int no_months);
void displayResults(int sales[], int no_months, int max, int min, int avg);
const int MAX_MONTHS =6;
int main(){
int no_months =0;
int sales[MAX_MONTHS];
int maxSale;
int minSale;
double avg;
int intAvg;
displayGraphics();
no_months = getNoMonths();
getSales(sales, no_months);
maxSale = getMax(sales, no_months);
minSale = getMin(sales, no_months);
avg = getAverage(sales, no_months);
intAvg = int(avg);
displayResults(sales, no_months, maxSale, minSale, intAvg);
return 0;
}
int getNoMonths(){
int months;
// Prompt user until a valid input is entered
do {
std::cout "Enter the number of months to process (between 3 and 6): ";
std::cin >> months;
// Check if the input is valid
if (months 3|| months >6){
std::cout "Invalid entry. Please enter a number between 3 and 6.
";
}
} while (months 3|| months >6);
return months;
}
void getSales(int sales[], int no_months){
for (int i =0; i no_months; ++i){
cout "Enter sales data for month "(i +1)": ";
cin >> sales[i];
}
}
int getMax(int sales[], int no_months){
int max = sales[0];
for(int i =1; i no_months; ++i)
if (sales[i]> max){
max = sales[i];
}
return max;
}
int getMin(int sales[], int no_months){
int min = sales[0];
for(int i =1; i no_months; ++i)
if (sales[i] min){
min = sales[i];
}
return min;
}
double getAverage(int sales[], int no_months){
double total =0;
double average =0;
cout fixed setprecision(3) endl;
for (int i =0; i no_months; i++){
total += sales[i];
}
average = static_cast(total)/ no_months;
double roAvg = pow(10,2);
average = round(average * roAvg)/ roAvg;
return average;
}
void displayResults(int sales[], int no_months, int max, int min, int avg){
const int RECT_WIDTH =50;
const int DISTANCE_BETWEEN =25;
const char* monthNames[MAX_MONTHS]={ "Jan", "Feb", "Mar", "Apr", "May", "Jun" };
for (int i =0; i no_months; ++i){
int height = static_cast(((double)sales[i]/ max)*100.0);
if (height 1){
height =1;
}
}
gout setPos(205,380) "Max Sales: $" max endg;
gout setPos(205,410) "Min Sales: $" min endg;
gout setPos(205,440) "Avg Sales: $" avg endg;
gout setPos(205,338) "Sales Statistics" endg;
using c + + graphics ( graphlib 2 0 2 2 , graph.h

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!