Write a C++ program as if you were a beginning programmer whose main function is merely…
- User
Write a C++ program as if you were a beginning programmer 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 the percentage of small letters for every letter a-z. The percentages should look like this: "25%". This information must come from an array of structures, and this array must be passed as a parameter.
Few Other Logistics:
The input and output files are regular text file. Please submit a zip file with only your CODE (.cpp file) and a Makefile We will test on various text files, not just on the given input file. A Sample Run
Consider a file content as below:
The person I intend to interview is known as Koushik Chakraborty. My goal is to perform a rigorous technical interview with focus on Artificial Intelligence Hardware design.
Here is the output file generated by the code:
Letter Count Pecentage of Occurrence
A 1 0.69%
B 0 0.00%
C 1 0.69%
D 0 0.00%
E 0 0.00%
F 0 0.00%
G 0 0.00%
H 1 0.69%
I 2 1.38%
J 0 0.00%
K 1 0.69%
L 0 0.00%
M 1 0.69%
N 0 0.00%
O 0 0.00%
P 0 0.00%
Q 0 0.00%
R 0 0.00%
S 0 0.00%
T 1 0.69%
U 0 0.00%
V 0 0.00%
W 0 0.00%
X 0 0.00%
Y 0 0.00%
Z 0 0.00%
a 9 6.21%
b 1 0.69%
c 5 3.45%
d 3 2.07%
e 14 9.66%
f 3 2.07%
-
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.