Write a program to analyze a text file. Read each character from the file, and keep track of the following:
The total number of characters
The total number of alpha characters (a-z, A-Z)
The total number of numerals (0-9)
The total number of a single specified character. (Ask the user which character they wish to search for).
The total number of lines. (Think about this)
Output results to the screen, and also to a file. Use setw(), right, left, setfill() etc. to format your output in a table format. Create your own text file for testing. I'm totally lost on this. Please help.
/*************
Program Name:
Programmer:
Description:
Date Written:
**************/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
usingnamespace std;
// Declare constants
// Function Prototypes
int main()
{
// Declare variables below here
string fileName;
char x;
int charCount, alphaCount, numCount, spefCount, lineCount;
ifstream infile;
ofstream outfile;
// Initialization Section for real number output. DO NOT MOVE!
cout <<setiosflags(ios::fixed | ios::showpoint);
cout <<setprecision(2);
// Begin your "main processing" below here
cout<<"Please enter the file name >> ";
cin>>fileName;
infile.open(fileName);
cout<<"Please enter a single specific character to search for: "<<endl;
cin>>x;
cout<<"Number of characters: "<<charCount;
cout<<"Number of alpha characters (a-z): "<<alphaCount;
cout<<"Number of numeric characters (0-9): "<<numCount;
cout<<"Number of user specified characters: "<<spefCount;
cout<<"Number of lines: "<<lineCount;
return 0;
}
// function definitions below here