Welcome to E8 :: [eon8]

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll also be able to use the shoutbox, customize your profile, change themes, gain reputation points for submitting content, while also communicating with other members via your own private messenger, plus much more!

 

This message will be removed once you have signed in.

Sign in to follow this  
kxrxoxnxixc

If anyone knows any c++ Please, help.

1 post in this topic

So my assignment is to take a file, read it in, and than count each character, store the character and print a graph vertically, using a ratio to scale it, and print the character and amount of each character on the bottom, but the only trouble im having is printing the graph...I can't figure it out. If someone would like to help me out, greatly appreciated.

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <string>



using namespace std;

int main()
{
char letters[26] = {'a', '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'};
int count[26] = {0};
string IPFile;
int k = 0;
int most = count[0];
int lines = 40;
int length = 26;
char letter, graph;
//just separating Variables from main code with this comment.
cout << "Please enter the file name inwhich you would\n";
cout << " like the characters a-z to be counted." << endl;
cin >> IPFile;
ifstream infile(IPFile.c_str());
if (infile.is_open())
{
while (!infile.eof()) //checks to make sure the cin is not eof

{
infile.get(letter);

if (isalpha(letter))

{ letter = tolower(letter); //converts the line of input to lowercase
letter = letter - 97;
count[letter] = count[letter]++;
}
}
for ( k = 0; k < length ; k++)
{
if (count[k] > length)
{
most = count[k];
}
}
for (int l = lines; l >= 0; l--)
{ graph = (l * most) / lines ;
for (int i = 0; i < 26; i++)
{ if(count[i] >= graph)
{ putchar('*'); }
else
{ putchar(' '); }
}
}
cout << '\n';
for (int d = 0; d < 78; d++)
{ putchar('.'); }
cout << "\n";
for (int i = 0; i < 26; i++)
{ printf("%2c",letters[i]);}
cout << '\n';
}
infile.close();
return 0;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this