Code:
#include <ctype.h>
#include <iomanip.h>
#include <fstream.h>
#include <string>
#include <iostream.h>
void printdata(char, double);
int main (void)
{
int freqcount[26] = {0}; //array to hold letter values
int totalcount = 0; //initializes total count to value '0'
string InFileName;
cout <<"\nEnter name of file to process: "; //prompts user for input filename
getline(cin,InFileName);
ifstream inStream;inStream.open(InFileName.data());
if (!inStream.is_open())
{
cerr << "\nError opening " << InFileName << endl;
return -1;
}
double percent;
double i;
char Ch;
inStream >> Ch;
while (!inStream.eof())
{
Ch = toupper(Ch);
if ((Ch <= 'Z') && (Ch >= 'A'))
{
totalcount++;
freqcount[Ch - 65]++;
}
inStream >> Ch;
}
cout << "\n" << "Char %" << endl
<< "===================================================================\n";
for (int k=0; k<=25; k++)
{
percent = freqcount[k]*100.0/totalcount;
printdata(char(k+65), percent);
}
cout << endl << endl << "Number of letters = " << totalcount << endl;
}
void printdata(char Ch, double percent)
{
double i;
cout << " "<< Ch << " " << setiosflags(ios::showpoint | ios::fixed
| ios::right) << setprecision(1) << setw(5) << percent;
for (i=2*percent; i>0.5; i--) cout << '*'; cout << endl;
}
and my errors are as follows
test.c: In function 'int main()':
test.c:13: error: 'string' undeclared (first use this function)
test.c:13: error: (Each undeclared identifier is reported only once for each function it appears in.)
test.c:13: error: parse error before ';' token
test.c:15: error: 'InFileName' undeclared (first use this function)
any help would be appreciated.