Good Afternoon,
I'm having difficulties with a program that deal getting the letters frequencies from an input text file.
So far I have this code.
Cpp file:
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include "lab_19_head.h"
using namespace std;
int main( )
{
//define a const array size
const int SIZE = 26;
//array declaration
int stats[SIZE]; //letter stat array
//file var
ifstream inFile; //input file
int i; //loop var
//open file
inFile.open("lab_19_data.txt");
if(!inFile)
{
cout<<"Fail to open lab_19_data.txt, and stop ."<<endl;
return 1;
}
//initialize array letterStata
for (i=0; i<SIZE; i++)
stats[i] = 0;
//call function get letter stats in the file
getStats(stats, inFile, SIZE);
//close the file
inFile.close();
//call function showStats to display the results
showStats(stats, SIZE);
//well done and exit
return 0;
}
Header file:
#include <iostream>
#include <cstring>
using namespace std;
#ifndef LAB_19_HEAD_H
#define LAB_19_HEAD_H
/****************************************************************
This function gets letters frequencies from the input file.
You need to implement this function.
****************************************************************/
void getStats(int stats[ ], ifstream & inFile, const int size)
{
//Write your code here
char ch;
while(inFile)
{
inFile>>ch;
ch = toupper (ch);
if (ch >= 'A' && ch <= 'Z')
}
}
/****************************************************************
This function displays the stats inform in some good format.
You need to implement this function.
****************************************************************/
void showStats(const int stats[ ], const int size)
{
//Write your code here
for (int i =0; i < size; i++)
{
cout << "The frequency of letter" << static_cast<char>(stats[ch - 'A'] && ['A' + i)
<< " is " <<stats[i]<<endl;
}
}
#endif
Any help that I can get is appreciated it.
Thank you