26 August 2009

letters in AlQuran

//Author: Ahmed Sayed
//This powerful program gets the frequencies of the distinct words which ALLAH used in the Quran  
#include <iostream>
#include <fstream>
#include <string> 
#include <map> 
using namespace std;
const int N = 20000;
char word[N]; 
int k = 0;
//
bool found (char S)
{
   for (int i=0; i<k; i++)
     if ( word[i] == S)
         return true;
                
return false; };
//sorting the array alphabetically
void sort(){
char temp; 
while (k!=0)
{
for (int i=0; i<k; i++)
   if (word[i] > word[i+1]) 
     {temp = word[i];
      word[i] = word[i+1];
      word[i+1] = temp;}
   k--;
 }
};
//1
int main ()
{
map<char, int> wordcounts; 
char s; 
ifstream source; source.open("AlQuran.txt");
ofstream target; target.open("Letters.txt");

while (source >> s)  
   {++wordcounts[s]; 
       if (! found (s))
          {word[k] = s;
          k++;}
  } 
target << "بسم الله الرحمن الرحيم .... اللهم بارك في السيد احمد سيد عطيه" << endl;
target << " عدد الحروف و التشكيل و الرموز في القران" << ": " << k << endl;
target << "هنا عدد استخدام كل حرف من قبل الله -سبحانه و تعالي " << endl;
sort(); //don't sort
// first appeared first written
//First come first served
for (int j=0; j<wordcounts.size(); j++)
  target << "'" << word[j] << "'" << "......." << wordcounts[word[j]] << endl; 

system ("pause");
return 0;
}