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

C++ full project SOLUION Needed asap Rules: String Histogram A Histogram (http:/

ID: 3570918 • Letter: C

Question

C++ full project SOLUION Needed asap

Rules: String Histogram
A Histogram (http://en.wikipedia.org/wiki/Histogram) is a visual way of representing frequency counts. Most computer programs that produce histograms show the output horizontally rather than vertically. The goal of this assignment is to create a class that produces histograms from string data using some of the string functions outlined above. The output will occur when the output operator is invoked as shown below.

Histogram

enum LETTER { A=1,B,C,D,E,F,G,H,I,J,K,L,M,N,O, P,Q,R,S,T,U,V,W,X,Y,Z };

void acceptString( string data );
void acceptCString( char * data );
void reset( );

ostream& operator<<( ostream& outs, const Histogram& h );

string my_DataSoFar;
int my_FrequencyCount[ 27 ];

void incrementFrequency( LETTER l );

Histogram h;

string s;
cout << "Enter Data:"
cin >> s;

h.acceptString( );

cout << h << endl;

h.reset( );

char * cstr = "Hello";

h.acceptCString( cstr );

cout << h << endl;

Enter Data: supercalifragilisticexpialadocious
A - 4 - ****
C - 3 - ***
D - 1 - *
E - 2 - **
F - 1 - *
G - 1 - *
I - 6 - ******
L - 3 - ***
O - 2 - **
P - 2 - **
R - 2 - **
S - 3 - ***
T - 1 - *
U - 2 - **
X - 1 - *

E - 1 - *
H - 1 - *
L - 2 - **
O - 1 - *

Implementation Details Sample Driver

Histogram

Histogram( );

enum LETTER { A=1,B,C,D,E,F,G,H,I,J,K,L,M,N,O, P,Q,R,S,T,U,V,W,X,Y,Z };

void acceptString( string data );
void acceptCString( char * data );
void reset( );

ostream& operator<<( ostream& outs, const Histogram& h );

string my_DataSoFar;
int my_FrequencyCount[ 27 ];

void incrementFrequency( LETTER l );

Histogram h;

string s;
cout << "Enter Data:"
cin >> s;

h.acceptString( );

cout << h << endl;

h.reset( );

char * cstr = "Hello";

h.acceptCString( cstr );

cout << h << endl;

Sample Output

Enter Data: supercalifragilisticexpialadocious
A - 4 - ****
C - 3 - ***
D - 1 - *
E - 2 - **
F - 1 - *
G - 1 - *
I - 6 - ******
L - 3 - ***
O - 2 - **
P - 2 - **
R - 2 - **
S - 3 - ***
T - 1 - *
U - 2 - **
X - 1 - *

E - 1 - *
H - 1 - *
L - 2 - **
O - 1 - *

Explanation / Answer

I am reposting this answer. This time you can give multiple inputs. Link: http://ideone.com/w7ljQn

---------------------------- CODE ----------------------------

#include<iostream>
#include<string>

using namespace std;


class Histogram
{
enum LETTER { A=1,B,C,D,E,F,G,H,I,J,K,L,M,N,O, P,Q,R,S,T,U,V,W,X,Y,Z };

string my_DataSoFar;
public:
int my_FrequencyCount[ 27 ];
void acceptString( string data )
{
for(int i=0 ; i < 27 ; i++){
my_FrequencyCount[i]=0;
}
my_DataSoFar = data;   
int len = data.length();
for(int i = 0; i < len ; i++) {
incrementFrequency(static_cast<LETTER>(toupper(data[i]) - 64));
}

}
friend ostream& operator<<( ostream& outs, const Histogram& h );
void incrementFrequency( LETTER l )
{
my_FrequencyCount[l]++;
}
};

ostream& operator<<( ostream& outs, const Histogram& h )
{
for(int i = 1 ; i< 27 ; i++)
{
if(h.my_FrequencyCount[i] !=0)
{
outs<<((char)(i+64))<<" - "<<h.my_FrequencyCount[i]<<" - ";
for(int j = 0 ; j < h.my_FrequencyCount[i]; j++){
outs<<"*";
}
outs<<endl;
}
}
return outs;
}


int main()
{
string s;
cout <<"Enter string. Enter -1 to exit"<<endl;
cin >> s;
while (s.compare("-1") != 0){
   Histogram h;
   h.acceptString(s);
   cout << h << endl;
   cout <<"Enter string. Enter -1 to exit"<<endl;
   cin >> s;
}
return 0;
}

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