I need help turning a histogram into a vertical histogram. I looked at some code
ID: 3622534 • Letter: I
Question
I need help turning a histogram into a vertical histogram. I looked at some code but the solution evaded me. I pray someone can help.
[code]
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
//start main 1s
int i;
int count[26]={0};
int star;
char c,str[256];
ifstream is;
cout<< "enter filename: ";
cin.get(str,256);
is.open(str);
while (is.good())
do
{
c=cin.get();
c=tolower(c);
if(isalpha(c))
{//4s
for (i=97;i<123;i++)
{//5s
if (c==i)
{//6s
count[c-'a']++;
}//6e
cout<<<""<<(char)i<<" "<
for (star=0; star
{
cout<<"*";
}
cout<
}//5e
}//4e
}//end do 2e
while (c = EOF);
is.close();
}
[code]
Explanation / Answer
your input had some problems which I fixed
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <locale>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{int count[26]={0};
int j,k,max;
char c,str[256],i;
ifstream is;
cout<< "enter filename: ";
cin.get(str,256);
is.open(str);
if(is.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
c=is.get();
while(is)
{if(isalpha(c))
{//4s
c=tolower(c);
count[c-'a']++;
}
c=is.get();
}
max=count[0];
for(j=1;j<26;j++)
if(count[j]>max)
max=count[j];
for(j=max+5;j>0;j--)
{cout<<setw(2)<<j<<"|";
for(k=0;k<26;k++)
if(count[k]>=j)
cout<<"* ";
else
cout<<" ";
cout<<endl;
}
cout<<" ";
for(i=0;i<=26;i++)
cout<<"__";
cout<<endl<<" ";
for(i='a';i<='z';i++)
cout<<i<<" ";
cout<<endl;
is.close();
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.