Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is part one,the following photos are part two: the following photos are part three: this is the last photo. how can i send you

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

this is part one,the following photos are part two:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

the following photos are part three:

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

this is the last photo. how can i send you the text files? thank you

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=1, string label="", int color=GREE // getters int getLength() const string getLabel() const int getColor() const // setters void setLength(int) void setLabel(string) void setColor(int) // prints the bar to the screen after scaling it void print(float factor=1); 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.h" #include using namespace std; int main() { print_colored (RED, "This is a test "); print_colored (DARK_MAGENTA, "This is another print_colored (GREY, "This is also a test "); print_colored (GREEN, "This is a last test ") return 0; } On a black console, the output would look like this: This is a test This is another test This is also a test This is a last test On a white console, the output would look like this: This is a test This is another test This is also a test This is a last test Printing a Bar The print function must print a number of spaces ("") that is equal to the length of the bar multiplied by the given factor. The factor is used to rescale the bar to make it larger (if factor > 1) or smaller (if 0 arr[j+1]) swap(arr[j], 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 create an object of type Chart and set the following: o Title: "Title: A Random Chart." o 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 console): 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 0 and then use Sleep (delay). - On Mac/Unix, you can include and then use usleep(delay). o Delete the created array of bars. 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 main() 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_2

Step: 3

blur-text-image_3

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

ficat .ili 4

Answered: 1 week ago