Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ please solve part 2 and part 3 -->chart.cpp and racer.cpp here is the link for colors.h and Bar.cpp ---> https://onlinegdb.com/KerUmn3Vn Part 2: A

in c++ please solve part 2 and part 3 -->chart.cpp and racer.cpp
here is the link for colors.h and Bar.cpp --->
https://onlinegdb.com/KerUmn3Vn
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Part 2: A Bar Chart Points: 35% Required API Implement class Chart, to represent a Bar Chart. Each Chart has: An array of objects of type Bar. This is provided by the user of the class through the constructor. A title. This is a string that describes the chart. A maximum size. This is a constant positive integer that controls the size of the chart. You must implement the following public functions: // constructor in is the size of the array). Chart (Bar bo, int n, string title, int MAX_SIZE); W copy constructor Chart(const Charte other); 1 destructor -Chart(): // sorts the bars in the chart in descending order based on their length. void sort(); 1/ displays the top bars in the chart. vold show(string caption, int m) consta Constructors and Destructors Use dynamic memory allocation in the constructor to create the array of Bar objects and copy into it the elements of the received array. Each Chart object must store and manage its own array of Bar objects, such that the array is not modifiable through any reference outside the class. Implement the copy constructor also such that the object gets its own independent copy of the array of Bar objects in the other Chart. The destructor must deallocate any dynamically allocated memory. Sorting The function sort() must sort the bars in the chart in decreasing order based on their lengths. Modify the following implementation of Bubble Sort to achieve this: for (int i = 0; i arr[j+1) swap(arr0], arr[j+1]); Displaying the Chart The function show(string caption, int ) must print out the chart as follows: Print the title of the chart on a separate line. Print the first m Bar objects in the array of bars using the print function in the Bar class. Use a scaling factor as described below. Print the given caption on a separate line. To compute the rescaling factor, you need to find the length of the longest bar in the chart. Assume the length of the longest bar is max_length, the scaling factor is then HAX_SIZE / max_length Example: Assume the chart has 3 bars with: lengths 10, 50 and 100. labels "label 1". "Label 2" and "label 3". colors DARK_RED, DARK_BLUE and DARK_GREEN Assume also that MAX_SIZE = 50 and the title is "This is a test title" The scaling factor sent to the print() function should be 59 / 100 = 0.5 Calling show("This is a test caption", 3) should produce the following 25 spaces with a blue background This is a test Title label 1 (10) label 2 (50) label 3 (108) This is a test caption 50 spaces with a green background Note the blank lines between the bars. Test Client In order to test your implementation of class Chart, write a program to perform the following Create an array of 16 objects of type Bar. For each object, perform the following Assign a random length between 100 and 300 inclusive Assign a random color between 1 and 16 inclusive. Assign the label "test" Use the created array of Bar objects to create an object of type Chart and set the following: Title: "Title: A Random Chart." Maximum Size = 60 Show the chart (all the bars) with the caption "A random chart". Sort the chart and then show the top 10 bars with the caption "A random chart after sorting" The output of the program should look something like this colors differ based on the used consoles Title: A Random Chart. Test (119) Test (247) Test (255) Test (167) Test (205) Test (153) Test (234) Test (243) Test (298) Test (191) Test (156) Test (286) Test (123) Test (282) Test (260) Test (261) A random chart Title: A Random Chart. Test (298) Test (286) Test (282) Test (261) Test (260) Test (255) Test (247) Test (243) Test (234) Test (205) A random chart after sorting Implementation Requirements Separate the interface from the implementation, but both must be in the same file.le, all of your code (header + implementation + main) must be in Chart.cpp. You will need to copy your implementation of class Bar into Bar.cpp without the main() function, as Chart.cpp will have the main() function. Use assertions to ensure that the array received in the constructor is not NULL and the length of the array and MAX_SIZE are greater than o. Use assertions also to ensure in show(string caption, int m) that @ and then use Sleep(delay) - On Mac/Unix, you can include and then use usleep(delay). Delete the created array of bars. The following videos are examples for how running the program should look like: Using cities.txt: video link. . Using baby-names.txt: video link. Using countries.txt: video link. Using brands.txt: video link. The colors are arbitrary. You can pick any color you like Running the program on Ed, Reptit, OnlineGDB, or any other online ide will cause flickering. The above videos are smooth because they were produced by running the program locally on the machine (you can do that tool) Implementation Requirements All of your code must in the file named Racer.cpp. You must also copy your implementation for parts 1 and 2 into Bar.cpp and Chart.cpp (without the main functions). . You are allowed to define functions beside mainO in Racer.cpp Part 2: A Bar Chart Points: 35% Required API Implement class Chart, to represent a Bar Chart. Each Chart has: An array of objects of type Bar. This is provided by the user of the class through the constructor. A title. This is a string that describes the chart. A maximum size. This is a constant positive integer that controls the size of the chart. You must implement the following public functions: // constructor in is the size of the array). Chart (Bar bo, int n, string title, int MAX_SIZE); W copy constructor Chart(const Charte other); 1 destructor -Chart(): // sorts the bars in the chart in descending order based on their length. void sort(); 1/ displays the top bars in the chart. vold show(string caption, int m) consta Constructors and Destructors Use dynamic memory allocation in the constructor to create the array of Bar objects and copy into it the elements of the received array. Each Chart object must store and manage its own array of Bar objects, such that the array is not modifiable through any reference outside the class. Implement the copy constructor also such that the object gets its own independent copy of the array of Bar objects in the other Chart. The destructor must deallocate any dynamically allocated memory. Sorting The function sort() must sort the bars in the chart in decreasing order based on their lengths. Modify the following implementation of Bubble Sort to achieve this: for (int i = 0; i arr[j+1) swap(arr0], arr[j+1]); Displaying the Chart The function show(string caption, int ) must print out the chart as follows: Print the title of the chart on a separate line. Print the first m Bar objects in the array of bars using the print function in the Bar class. Use a scaling factor as described below. Print the given caption on a separate line. To compute the rescaling factor, you need to find the length of the longest bar in the chart. Assume the length of the longest bar is max_length, the scaling factor is then HAX_SIZE / max_length Example: Assume the chart has 3 bars with: lengths 10, 50 and 100. labels "label 1". "Label 2" and "label 3". colors DARK_RED, DARK_BLUE and DARK_GREEN Assume also that MAX_SIZE = 50 and the title is "This is a test title" The scaling factor sent to the print() function should be 59 / 100 = 0.5 Calling show("This is a test caption", 3) should produce the following 25 spaces with a blue background This is a test Title label 1 (10) label 2 (50) label 3 (108) This is a test caption 50 spaces with a green background Note the blank lines between the bars. Test Client In order to test your implementation of class Chart, write a program to perform the following Create an array of 16 objects of type Bar. For each object, perform the following Assign a random length between 100 and 300 inclusive Assign a random color between 1 and 16 inclusive. Assign the label "test" Use the created array of Bar objects to create an object of type Chart and set the following: Title: "Title: A Random Chart." Maximum Size = 60 Show the chart (all the bars) with the caption "A random chart". Sort the chart and then show the top 10 bars with the caption "A random chart after sorting" The output of the program should look something like this colors differ based on the used consoles Title: A Random Chart. Test (119) Test (247) Test (255) Test (167) Test (205) Test (153) Test (234) Test (243) Test (298) Test (191) Test (156) Test (286) Test (123) Test (282) Test (260) Test (261) A random chart Title: A Random Chart. Test (298) Test (286) Test (282) Test (261) Test (260) Test (255) Test (247) Test (243) Test (234) Test (205) A random chart after sorting Implementation Requirements Separate the interface from the implementation, but both must be in the same file.le, all of your code (header + implementation + main) must be in Chart.cpp. You will need to copy your implementation of class Bar into Bar.cpp without the main() function, as Chart.cpp will have the main() function. Use assertions to ensure that the array received in the constructor is not NULL and the length of the array and MAX_SIZE are greater than o. Use assertions also to ensure in show(string caption, int m) that @ and then use Sleep(delay) - On Mac/Unix, you can include and then use usleep(delay). Delete the created array of bars. The following videos are examples for how running the program should look like: Using cities.txt: video link. . Using baby-names.txt: video link. Using countries.txt: video link. Using brands.txt: video link. The colors are arbitrary. You can pick any color you like Running the program on Ed, Reptit, OnlineGDB, or any other online ide will cause flickering. The above videos are smooth because they were produced by running the program locally on the machine (you can do that tool) Implementation Requirements All of your code must in the file named Racer.cpp. You must also copy your implementation for parts 1 and 2 into Bar.cpp and Chart.cpp (without the main functions). . You are allowed to define functions beside mainO in Racer.cpp<><>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

computer system and cyber security exam

Answered: 1 week ago