Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C + + program whose main function is merely a collection of variable declarations and function calls. This program reads in text and
Write a C program whose main function is merely a collection of variable declarations and function calls. This program reads in text and outputs the letters, together with their counts. You are not allowed to use global variables. All information must be passed in and out of the functions. You will use an array to keep a count for all of the letters. Both the input file and output file must be given by the user. Your program will be broken up into functions, in four different files. Because they are in different files, you are being forced to not use global variables. One of the files is given to you maincpp
You will be given other files, that are all hpp files. Your job is to write the functions, openFiles, count, and printResults in the three different files.
InputOutput openFiles
Opens the input and output files. It will throw an error if something is wrong. There are three edge cases:
If it there are an incorrect amount of input parameters, it will throw an IncorrectParameters error.
If it fails to open the input file, throw a InvalidInputFile error
It if fails to open the output file, throw an InvalidOutputFile error
count
Counts every occurrence of capital letters AZ and small letters az in the text file opened in the function openFile.
printResult
Prints the number of capital letters and small letters, as well as the percentage of both. Don't include non letters in the count for getting the percentage
The format of each line needs to line up to the right
Few other key logistics:
The program takes in two command line arguments, input and output
Examplextxt corresponds with outputxtxt
There are test cases you are not given, but the are described in the rubric.
A computer is grading this. Just as compilers are unforgiving, so too will the computer be unforgiving.
You get half credit for windows, and half credit for linux. If it doesnt compile on linux, you will get no credit for that half of the assignment.
Dont commit anything other than the cpp or cc files
Example: Consider a file with content as below:
C is an object oriented programming language. It used to be called c with classes. Soon we will make a class for our programming assignment. We turn every assignment in with git. I wish that Linux Torvalds could have made it more user friendly.
Here is the output file generated by the code:
Letter Count Percentage
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
a
b
c
d
e
f
g The main.cpp file is #include
#include "count.hpp
#include "openFiles.hpp
#include "printResults.hpp
int mainint argc, char argv
try
auto io a::openFilesargc argv;
std::array counts a::countiofin;
a::printResultsiofout, counts;
catch a::IncorrectParameters& ex
std::cerr exwhat;
return exgetCode;
catch a::InvalidInputFile& ex
std::cerr exwhat;
return exgetCode;
catch a::InvalidOutputFile& ex
std::cerr exwhat;
return exgetCode;
return ;
The openFiles.hpp file is #ifndef OPENFILESHPP
#define OPENFILESHPP
#include
namespace a
class IncorrectParameters : public std::runtimeerror
public:
IncorrectParameters : std::runtimeerrorInvalid input parameters";
int getCode return ;
;
class InvalidInputFile : public std::runtimeerror
public:
InvalidInputFile : std::runtimeerrorInvalid input file";
int getCode return ;
;
class InvalidOutputFile : public std::runtimeerror
public:
InvalidOutputFile : std::runtimeerrorInvalid output file";
int getCode return ;
;
struct InputOutput
InputOutputstd::ifstream& in std::ofstream& out
: finstd::movein foutstd::moveout
std::ifstream fin;
std::ofstream fout;
;
InputOutput openFilesint argc, char argv;
namespace a
#endif The printResults.hpp file is #ifndef PRINTRESULTSHPP
#define PRINTRESULTSHPP
#include
#include "count.hpp
namespace a
void printResultsstd::ofstream& fout,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started