Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me out with this problem please! Create a class histogram and u

ID: 3676016 • Letter: C

Question

Can someone help me out with this problem please!

Create a class histogram and unit tests for that class. The class must have the following methods: • histogram ( int values [], size t nvalues , size t scale ) – where values has nvalues integers

• ostream& operator <<(ostream& outs, const histogram &h) – draw this histogram as described below. Note: This operator may be a friend function or you may add “getter” methods to avoid having a friend.

Drawing a histogram means displaying one line per value in the values array. Each line i should contain values [ i ]/ scale asterisks. For example:

int v[] = {5, 3, 10, 9, 4}; histogram h(v, 5, 2);
c o u t << h << e n d l ;

should produce

0: **

1: *

2: *****

3: ****

Each row begins with a label indicating the row number (starting at 0). The labels must not interfere with the spacing of the histogram so if you have, for example, more than 10 but less than 101 values in your input array you need each row number to occupy two spaces.

Include a complete and thorough set of unit tests for your histogram class.

Explanation / Answer

public void Histogram(Map<Integer, Integer> userHistogramInfo)
{
int v[] = {5,3,10,9,4};
histogram h(v,5,2);
cout<< h << end l ;

long[] buckets = new long[definitionInBytes.length];

System.out.println("0: ** 1: *2: ***** 3: **** 4: ** ");
  

SortedSet<Integer> keys = new TreeSet<Integer>(userHistogramInfo.keySet());
for (Integer key : keys) {
Integer value = userHistogramInfo.get(key);
System.out.println(key + " " + value);
}

System.out.println();
for (Integer time : userHistogramInfo.keySet())
{
for (int i = definitionInBytes.length - 1; i >= 0; i--) {
if (time >= definitionInBytes[i]) {
buckets[i] += userHistogramInfo.get(time);
break;
}
}
}
for (int i = 0; i < definitionInBytes.length; i++)
{
String period = "";
if (i == definitionInBytes.length - 1) {
period = "greater than " + definitionInBytes[i] + " bytes";
} else {
period = "between " + (definitionInBytes[i] + 1) + " and " + definitionInBytes[i + 1] + " bytes";
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote