Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ part 1 bar.cpp part2 bar.cpp/chart.cpp part3 recer.cpp/bar.cpp/chart.cpp Part 1: A Bar for Charts! Points: 25% Required API Implement class Bar, to represent a

in c++
part 1 bar.cpp
part2 bar.cpp/chart.cpp
part3 recer.cpp/bar.cpp/chart.cpp
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
image text in transcribed
image text in transcribed
image text in transcribed
Part 1: A Bar for Charts! Points: 25% Required API Implement class Bar, to represent a Bar in a Bar Chart. Each bar has: a length (a non-negative integer). a label (a string describing the bar). a color (an integer between 1 and 16 inclusive) The class must have the following public API: // public constructor Bar (int length, string label**, int color-GREEN) // getters int getLength() const string getlabel() const int getColor() const 1 setters void setLength(int) void setLabel (string) void setColor (int) // prints the bar to the screen after scaling it using "factor" void print (float factor:) const; Colors We will use colors.h for printing with colors. This header file provides 16 different colors that can be used as background colors for the printed text. Here is am example for using the header file: include "colors." include 1) or smaller (if e arr[j+1]) swap(arr[i], arr[j+1]); Displaying the Chart The function show(string caption, int m) 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 MAX_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 50 / 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 (100) 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 randon 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. I.e., 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 0. Use assertions also to ensure in show(string caption, int m) that a c= m and then use usleep delay) Delete the created array of bars

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago