Write a program which reads a text from a file declared by the user.
If the file does not exist a message should state this and the program
should be terminated.
If the file opens with success the program should read the text and then output the uppercase letters A-Z and each of their counts and same of the lowercase letters a-z.
The program will then print the percentages of capital letters for every letter A-Z and small letters for every letter a-z to the output file also declared the user.
This program's main function should be a bunch of function calls and declarations. and the information for the count function should be put into an array of structures, and the information should be passed as reference also the input and output files should be passed as reference.
Also there are to be no global variables.Please help me someone. thanks in advance.
Below is what I have done so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct letters
{
char ch;
int lcount;
};
void main()
{
void Explanation();
int OpenFile(ifstream&, ofstream&);
int Count(ifstream&, letters[], int);
void PrintResult(letters[], int);
const int Size = 52;
letters List;
ifstream infile;
ofstream outfile;
Explanation();
OpenFile(infile, outfile);
Initialize(List, Size);
Count(infile, List, Size);
PrintResult(List, Size);
}
void Explanation()
{
cout << "This program reads a text from a file declared by you the user." << endl;
cout << "If the file does not exist a message will state this and the program\n"
<< "will be terminated." << endl << endl;
cout << "If the file opens with success the program will read the text and then\n"
<< "output the letters in that file, both upper and lower case and the count\n"
<< "of each letters appearance in the file." << endl << endl;
cout << "The program will then print the total number as well as the percentages of\n"
<< "capital letters for every letter A-Z and small letters for every letter a-z\n"
<< "to the output file also declared by you the user." << endl << endl << endl;
}
int OpenFile(ifstream& infile, ofstream& outfile)
{
string inputfile;
string outputfile;
cout << "Please enter the name for the input file: ";
cin >> inputfile;
cout << endl;
infile.open(inputfile.c_str());
if (!infile)
{
cout << "Cannot open the input file!" << endl;
return 1;
}
cout << "Now enter the name for the output file: ";
cin >> outputfile;
cout << endl;
outfile.open(outputfile.c_str());
}