Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program whose main function is merely a collection of variable declarati

ID: 3642344 • Letter: W

Question

Write a program whose main function is merely a collection of variable declarations and function calls. This program reads a text and outputs the letters, together with their counts, as explained below in the function printResult. (There can be no global variables! All information must be passed in and out of the functions. Use a structure to store the information.)

Your program must consist of at least the following functions:

Function openFile: Opens the input and output files. You must pass the file streams as parameters (by reference, of course). If the file does not exist, the program should print an appropriate message and exit. The program must ask the user for the names of the input and output files.

Function count: Counts every occurrence of capital letters A-Z and small letters a-z in the text file opened in the function openFile. This information must go into an array of structures. The array must be passed as a parameter, and the file identifier must also be passed as a parameter.

Function printResult: Prints the number of capital letters and small letters, as well as the percentage of capital letters for every letter A-Z and should look like this: "25%". This information must come from an array of structures, and this array must be passed as a parameter.

Explanation / Answer

001 //Header File 002 #include 003 #include 004 #include 005 #include 006 #include 007 #include 008 009 using namespace std; 010 011 //Structs 012 const int MAX_LETTERS = 26 ; 013 014 struct letterCount 015 { 016 char letter; 017 int count; 018 int count_caps; 019 }; 020 021 //Function Prototypes 022 int openFile(ifstream& infile, ofstream& outfile); 023 void count(letterCount letters[], ifstream& infile); 024 void printResult(letterCount letters[], ofstream& outfile); 025 026 //Main Program 027 int main() 028 { 029 letterCount counts[MAX_LETTERS]; 030 031 ifstream infile; 032 ofstream outfile; 033 034 openFile(infile, outfile); 035 count(counts, infile); 036 printResult(counts, outfile); 037 038 return 0 ; 039 040 } 041 042 //User-defined Function 1 043 int openFile(ifstream& inFile, ofstream& outFile) 044 { 045 ifstream infile; 046 ofstream outfile; 047 048 string inputFile; 049 string outputFile; 050 051 cout > inputFile; 053 cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote