frequency counter through filling

please give feedback on
https://www.facebook.com/invigorating.arslaan

/*
You have a character array of size 100. Array contains letters ranging between A-Z and a-z. You are required to tell the frequency of each letter in the array. You can ignore punctuation marks.

Example
I am A proud Pakistani.

Sample Output:

A=4,B=0,……I = 3…P =2 ,…..,Z=0.


*/
#include "iostream"
#include "stddef.h"
#include <math.h>
#include<fstream>
#include<string>
using namespace std;


int main()
{
const int n = 100;
char array[n] = "I am A Proud pakistani...,Are you?";
int length = 0,i=0;
int alphabet[26] = { 0 };
string line;
ifstream myfile("text.txt");
if (myfile.is_open())
{
while (myfile.good())
{
getline(myfile, line, '\n');
cout << line << endl;
}
myfile.close();
}

//computing length
while (array[length] != 0)
length++;

int index = 0;
for (int i = 0; i <length; i++){
if (array[i] >= 'a' && array[i] <= 'z'){
index = static_cast <int> (array[i]) - static_cast <int> ('a');
alphabet[index]++;
}
else{
if (array[i] >= 'A' && array[i] <= 'Z'){
index = static_cast <int> (array[i]) - static_cast <int> ('A');
alphabet[index]++;
}

}
}
ofstream fout;
fout.open("output.txt");
while (fout.good())
{

cout << "Array after rotation" << endl;
for (int j = 0; j < 26; j++)
fout << static_cast<char> (j + 'a') << " " << alphabet[j] << endl;
fout.close();
}

system("pause");
return 0;
}

Comments

Popular Posts