Struggling with current file input/output. I know to use cctype to distinguish between the different groups but I have no idea how to get the total of each. Any help would be super appreciated Here's the assignment. Write a program to gather the number of times particular groups of characters appear in a file.
- Allow the user to specify which file to process.
- Count how often the following types of characters occur:
- Alphabetic characters
- Numeric characters
- Control characters
- Upper case characters
- Lower case characters
- Punctuation characters
- Total number of characters in the file
- Have the program output the gathered results to a file name “stats.txt”.
- Display the information (left justified) in the order shown above.
- For each group of character types add a column that shows how often these characters appear.
- Add an additional column that shows what percentage that this groups comprises of the total number of characters in the file. Display this number with one decimal point. (Note: The percentage is not required on the line that display the total number of character processed.
- Please ensure all numerical columns are right justified, display appropriate precision and form a nice vertical table.
Here's my code so far:
enter code here
#include <iostream>
#include <cctype>
#include <fstream>
#include <iomanip>
#include <string>
//included libraries//
using namespace std;
//function definitions//
int main() {
int count;
int character;
string filename;
int alpha = 0, num = 0, con = 0, UC = 0, LC = 0, pun = 0, total = 0;
cout << "Enter file name and extension to process.\n";
cin >> filename;
ofstream fileout;
ifstream filein;
//input file//
filein.open(filename);
if (filein.fail()) {
cerr << "Failed to open the file: " << filename << endl;
}
//open file//
fileout.open("stats.txt");
if (fileout.fail()) {
cout << "Error, unable to open output file\n";
system("pause");
exit(1);
}
fileout.setf(ios::fixed);
fileout.setf(ios::showpoint);
fileout.precision(3);
filein.close();
fileout.close();
system("pause");
return 0;
}