Page 1 of 1

**C++ Problem** The program should have 5 files, named; //BarTester.cpp //This file tests the Bar class of your DIY work

Posted: Mon Jun 06, 2022 5:46 pm
by answerhappygod
**C++ Problem**
The program should have 5 files, named;
//BarTester.cpp
//This file tests the Bar class of your DIY workshop
#include "Bar.h"
using namespace sdds;
int main() {
Bar b;
for (int i = 1; i <= 5; i++) {
b.set("the bar", '=', i*20);
b.draw();
}
b.set("Bad Bar", '=', -200);
b.draw();
b.set("Bad Bar", '=', 200);
b.draw();
return 0;
}
//main.cpp
//This file tests the BarChart section of your DIY workshop
#include <iostream>
#include "BarChart.h"
using namespace sdds;
using namespace std;
int main() {
BarChart bc;
bc.init("How much students like this lab.", 5, '=');
bc.add("Best Lab Ever", 2);
bc.add("Good Lab", 10);
bc.add("Doable Lab", 63);
cout << "Premature draw call:"<< endl;
bc.draw(); // will not draw; it will print an error instead
bc.add("Bad Lab", 10);
bc.add("Worst Lab Ever", 5);
cout << "Proper draw call after all samples are entered:" << endl;
bc.draw();
bc.deallocate();
return 0;
}
The C++ problem is:
Please get the output exactly as "Execution Sample"
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 1
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 1 (69 KiB) Viewed 40 times
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 2
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 2 (40.6 KiB) Viewed 40 times
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 3
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 3 (62.92 KiB) Viewed 40 times
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 4
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 4 (20.97 KiB) Viewed 40 times
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 5
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 5 (26.67 KiB) Viewed 40 times
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 6
C Problem The Program Should Have 5 Files Named Bartester Cpp This File Tests The Bar Class Of Your Diy Work 6 (51.8 KiB) Viewed 40 times
Please write a Bar Chart program that receives several sample values and creates a bar chart based on the values of the samples received. A BarChart is a collection of valid Bars that are drawn horizontally on the screen: Bar Chart Title First sample title.. Second Sample. Third Sample. Fourth.. Fifth. And Six. A Bar object illustrates a sample that consists of a title and an integer value between 0 and 100. The BarChart is initialized (using init() method) by the title of the survey, the number of the samples (ie. Bars to be drawn) and the fill character to draw the bars. Note: The Title of the chart and the Bars in the BarChart are to be held dynamically; Which means a BarChart class has a dynamic array of Bar class objects. Each sample is added to the chart by the title and the value of the sample to be represented by a Bar in the BarChart. Note: The length of the bar will be "the value divided by 2", which means, a value of 10 will be displayed by a bar that is 5 characters long or a value of 41 will be displayed by a bar that is 20 characters long and so on... When displaying the BarChart, If the number of added samples is not the same as the number of samples in the BarChart, or if any of the Bars in BarChart is invalid, then the Chart will be considered invalid and a proper error message will be displayed. (see main and execution sample below)

Here is a sample of the main program using the BarChart Class and its execution result: #include <iostream> #include "BarChart.h" using namespace sdds; using namespace std; int main() { BarChart bc; bc.init("How much students like this lab.", 5, '='); bc.add("Best Lab Ever", 2); bc.add("Good Lab", 10); bc.add("Doable Lab", 63); cout << "Premature draw call:"<< endl; bc.draw(); // will not draw; it will print an error instead bc.add("Bad Lab", 10); bc.add("Worst Lab Ever", 5); cout << "Proper draw call after all samples are entered:" << endl; bc.draw(); bc.deallocate(); return 0; } Execution sample: Premature draw call: Invalid Chart! Proper draw call after all samples are entered: How much students like this lab. Best Lab Ever.. ยท|= Good Lab... Doable Lab.. Bad Lab... Worst Lab Ever. ===

Bar Module Suggested member variables a Cstring to hold a maximum of 20 characters for the title a char variable to hold the fill character an integer variable to hold the sample value of the Bar Suggested public member functions a function to set the Bar to the empty state a function to set the title, fill character and value of the bar and set the function to an invalid state if the value is not acceptable (less than zero or more than 100) a function that returns "if the Bar is valid or not" Mandatory public member function Write a member function called draw that does not accept any parameters and can not modify the bar. This function should draw a bar as follows. For example, if the title of the bar is "Number of cakes", the fill character is an asterisk (***) and the value is 51; the Bar should be drawn exactly like this: Number of cakes... *<NEWLINE> Print the title in 20 characters and fill the spaces with dot characters ('.'). print a pipe character ('|') print the fill character to the value divided 2 (ie. 51/2 -> 25) If the value of the Bar is invalid (less than zero or more than 100) this function takes no action.

barTester program: #include "Bar.h" using namespace sdds; int main() { Bar b; for (int i = 1; i <= 5; i++) { b.set("the bar", =', i*20); b.draw(); } b.set("Bad Bar", '=', -200); b.draw(); b.set("Bad Bar", '=', 200); b.draw(); return 0; bar tester output the bar.. the bar. the bar. the bar. the bar.

BarChart Module Mandatory member variables a character pointer to hold the dynamically allocated "title of the chart" a Bar pointer to hold the dynamically allocated array of Bars. a character variable to hold the fill character an integer variable to hold the size of the dynamically allocated array of Bars an integer variable to keep track of the number of added samples to set the Bars. Suggested member variables

Suggested member function a function to return if all the Bars are in a valid state or not. Mandatory member functions void init(const char* title, int noOfSampels, char fill); Initializes the Chart as explained before. void add(const char* bar_title, int value); Sets the next available Bar (in the dynamic Bar array), or does nothing if they are all already set. void draw() const; If The BarChar is valid and if all the Bars in the Chart are valid it draws the bar exactly as follows: prints the title of the Chart and goes to new line prints 71 dashes ('-') and goes to a new line prints all the Bars prints 71 dashes ('-') and goes to a new line Otherwise, it will print: Invalid Chart! <NEWLINE> void deallocate(); Deallocates all the dynamically allocated memory. Modify the tester program to test the different circumstances of the application and note that the professor's tester may have many more samples than the tester program here.