Been struggling with input/output in my programming class, my assignment is due tomorrow at midnight(Nov 7), have gotten something started however me or a couple of the other guys can't figure out where to go next.
Here's the assignment.
Write a program to gather the number of times particular groups of characters appear in a file.
1. Allow the user to specify which file to process.
2. 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
3. Have the program output the gathered results to a file name “stats.txt”.
4. Display the information (left justified) in the order shown above.
5. For each group of character types add a column that shows how often these characters appear.
6. 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.
7. Please ensure all numerical columns are right justified, display appropriate precision and form a nice vertical table.
Here's my code so far:
#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()) {
cout << "Error, nable to open output file\n";
system("pause");
exit(1);
}
//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);