
Alter the attached code so that the bar chart can be up to 25 categories, and can be sorted ascending or descending. In this assignment an array of Category structs are used to store both the category name (label) and the category value. The Category struct is provided below along with changes to the prototypes from assignment 3. The get_longest_category_name function has been removed because after sorting, the last or first element in the cats array will be the longest length label. Use this information in create_bar_chart and the asc Boolean value where true is sort ascending and false is sort descending.
struct Category
{
std::string label;
double value;
};
- Update the attached code to include the following in global scope:
#define CATEGORIES 25
int num_categories = 5;
- Change the attached code's functions to the following:
//Ask user how many categories, up to a max of 25
int how_many_categories();
void get_category(Category cats[CATEGORIES]);
void get_values(Category cats[CATEGORIES]);
double compute_total(Category cats[CATEGORIES]);
//
// sort the cats array of Category structs
// do not use selection sort or STL's sort
// use: bubblesort, insertion-sort, etc.
void sort(Category cats[CATEGORIES], bool asc=true);
// can get the longest_category_length from the sorted cats array
void create_bar_chart(Category categories[CATEGORIES], double total, bool asc=true);
- Sample main for new code
int main()
{
double total{ 0.0 };
bool asc = true;
while (true) {
std::cout << "Enter 1 or 0 for ascending (1) or descending order (0)?";
std::cin >> asc;
while (std::cin.fail())
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
std::cout << "Enter 1 or 0 for ascending (1) or descending order (0)?";
std::cin >> asc;
}
num_categories = how_many_categories();
get_category(cats);
get_values(cats);
total = compute_total(cats);
//sort categories, if ascending last element for longest, first for descending
sort(cats, num_categories, asc);
std::cout << "\nCategories as a Percentage of the Total (category_amount/" << total << ")\n";
std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
create_bar_chart(cats, total, asc);
std::cout << "\nEnter y to create another bar chart, or any other key to exit : ";
std::string response; std::cin >> response; std::cout << "\n";
if (response != "y")
break;
total = 0.0;
}
}
![for (int i = 0; i<5; i++) {
}
}
if (cat[i].length() > longest) {
longest = cat[i].length();
}
void create_bar_chart(std::string cat [CATEGORIES], double values [CATEGORIES], int
lcl, double total) {
for (int i = 0; i<5; i++) {
std::cout << cat[i] << "\t\t";
lcl = (values[i]/total)*100;
for(int j = 0; j<lcl; j++) {
std::cout << "*";
}
std::cout << lcl << "\n";](https://content.bartleby.com/qna-images/question/e4e826cb-c133-47e8-aeaa-858e7b3a09da/a9a40315-cbf0-428b-ac5c-08fac65adb50/7u9ce8r_thumbnail.png)
![#include <iostream>
#include <string>
#define CATEGORIES 5
void get_category(std::string cat [CATEGORIES]);
void get values (double values [CATEGORIES], std::string cat [CATEGORIES]);
void compute_total(double& total, double values [CATEGORIES]);
void get_longest_category_name
(int& longest, std::string cat [CATEGORIES]);
void create_bar_chart(std::string cat [CATEGORIES], double values [CATEGORIES], int
lcl, double total);
int main() {
std::string categories [CATEGORIES];
double values [CATEGORIES]; double total; int lcl;
while(true) {
get_longest_category_name(lcl, categories);
std::cout << "\nCategories as a percentage of the total
(category_amount/" << total <<")\n";
std::cout <<
to exit: ";
}
void
}
}
void
get_category(categories);
get_values (values, categories);
compute_total(total, values);
}
create_bar_chart (categories, values, lcl, total);
std::cout << "\nEnter y to create another bar chart, or any other key
char response;
std::cin>> response;
std::cout << "\n";
if (response != 'y')
break;
lcl = 0; total = 0.0;
get_category(std::string cat [CATEGORIES]) {
std::cout<<"Enter in the category names for your five-bar bar chart: \n";
for (int i = 0; i<5; i++) {
std::cin>> cat[i];
}
void get_values (double values [CATEGORIES], std::string cat [CATEGORIES]) {
for (int i = 0; i<5; i++) {
std::cout << "How many in the " << cat[i] << "category? ";
std::cin>> values[i];
-\n";
void compute_total (double& total, double values [CATEGORIES]) {
total = 0;
for (int i = 0; i<5; i++) {
total values[1];
}
get_longest_category_name (int& longest, std::string cat [CATEGORIES]) {
longest = 0;](https://content.bartleby.com/qna-images/question/e4e826cb-c133-47e8-aeaa-858e7b3a09da/a9a40315-cbf0-428b-ac5c-08fac65adb50/s8pdxy5_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- Consider the array below please provide the intermediate array applying the Count Sort Algorithm (Hint: not the Output Array or Input Array but Buffer Array that holds the counts of array elements). What should be the length of Count Array? 1. Input Array: 3 2 3 3 2 5 4 4 8.arrow_forwardPlease help Create a txt file where five grade for five course are shown And then calculate what the average grade isarrow_forwardWrite syntax to declare an array.arrow_forward
- Using question 4 to declare an array Daley with 10 elements of type StudentRec, Using for . loop to write code to read data for the 10 students' ID, name, and gradeScore.arrow_forwardWhen scanning an array for the first occurrence of a particular character, which repeat prefix would be best?arrow_forwardCampground reservations, part 3: Available campsites Excellent job! This next one's a little more challenging. Which campsites are available to reserve? We want to be able to quickly find which campsites are available. Can you help us? Given a campgrounds array, return an array with the campsite numbers of all currently unreserved (isReserved === false) campsites. Call the function availableCampsites. Dataset As a reminder, our data looks like this. It's an array with a bunch of campsite objects in it. Here is a small subset of the data to give you an idea: const campgrounds = [ { number: 1, view: "ocean", partySize: 8, isReserved: false }, { number: 5, view: "ocean", partySize: 4, isReserved: false }, { number: 12, view: "ocean", partySize: 4, isReserved: true }, { number: 18, view: "forest", partySize: 4, isReserved: false }, { number: 23, view: "forest", partySize: 4, isReserved: true }, ];arrow_forward
- As part of this assignment, the program that you will be writing will store current grades in a dictionary using course codes as keys and with values consisting of percent grades in lists. The main functions of this program are to print a student's gradebook, to drop the lowest grade in each course, print the student's gradebook again, drop the course with lowest average, and finally printing the student's gradebook again. This program requires a main function and a custom value-returning function. In the main function, code these basic steps in this sequence (intermediate steps may be missing): start with an empty dictionary that represents a gradebook and then use a while loop to allow the input of course codes from the keyboard. End the while loop when the user presses enter without entering data.within the while loop:for each course entered, use a list comprehension to generate five random integers in the range of 70 through 100. These random integers in a list represent the…arrow_forwardThe strStates and strCapitals arrays are parallel arrays. If Illinois is stored in the second element in the strStates array, where is its capital (Springfield) stored?strCapitals(0)strCapitals(1)strCapitals(2)strCapitals(3)arrow_forwardUse the following array for questions 16 – 18. Dim intTemperatures() As Integer = {100,86,77,74,77,90,99,99,32,101,56,67,77} Write the code that will find the coldest temperature in the list. (OPTIONAL) Create an array that will store the frequency of each temperature. Populate the array with the correct data. Sort the array in ascending order.arrow_forward
- Python question please include all steps and screenshot of code. Also please provide a docstring, and comments throughout the code, and test the given examples below. Thanks. Write function week() that takes no arguments. It will repeatedly ask the user to enter anabbreviation for a day of the week (Mo, Tu, We, Th, Fr, Sa, or Su) and then print thecorresponding day. Use a dictionary to implement this result.>>> week() Enter day abbreviation: TuTuesdayEnter day abbreviation: SuSundayEnter day abbreviation: SaSaturdayEnter day abbreviationarrow_forwardOverview This is a review assignment where you will use multiple tools you have picked up so far throughout the course. If you're confused about how to do something make sure you look back at earlier assignments. In this program you will start by declaring an empty dictionary named population_dict. Then you will use a while-loop to prompt a user for a series of cities and their populations, storing the input in population_dict). After this you will prompt the user to decide what is the maximum population for a city to be considers a small down. Finally, you will open a file called populationdata.txt where you will write the results. Expected Output Example of standard out (the console): What is next city? (enter q to quit) Long Beach What is the population of Long Beach? 362000 What is next city? (enter q to quit) Los Angeles What is the population of Los Angeles? 382000000 What is next city? (enter q to quit) San Diego What is the population of San Diego? 136000000 What is next city?…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





