You are to create a C++ program that opens an input file, reads and process the
ID: 3785581 • Letter: Y
Question
You are to create a C++ program that opens an input file, reads and process the data in that file, and then writes the (possibly modified) data to a new output file. Your program should:
Accept arguments that are presented on the command line (see Usage box below).
Use the Templatized C++ Command Line Parser for argument processing (See the “Templatized C++ Command Line Parser” below). Illegal or missing options should be handled properly.
Store the parsing results into a C++ STL map. The map file must be indexed by a C++ enumerated list (enum) and should hold strings for values.
Within your code, you must query your map to get the values of the parsed command line arguments. Finally, your program must present the correct behavior.
Your program should open the input file for reading and the output file for writing. It should
copy all data from the input file to the output file while optionally converting case as directed by
the command line arguments. -u and -l are mutually exclusive. Only one may be given but
neither is required. If the output file is not specified (it is optional), you should write to a file
with the default name of "output.txt".
Deliverables
You must submit your homework through ELearning. You must include your .cc files and any
header files you create (not TCLAP header files)
Templatized C++ Command Line Parser
It is often the case that you will want to use third party code. For Program 2, we will use a library
from a well-known open source repository. Specifically, we will utilize the Templatized C++
Command Line Parser (TCLAP).
TCLAP is a SourceForge project. SourceForge is a web-based source code repository. It acts as a
centralized location for software developers to control and manage free and open-source software
development. All information about the parser may be found at:
http://tclap.sourceforge.net
Explanation / Answer
Some of the important features need to be known before the coding.
C++ provides the following classes to perform output and input of characters to/from files:
These classes are derived directly or indirectly from the classes istream and ostream.
We have already used objects whose types were these classes: cin is an object of class istream and cout is an object of class ostream.
we can use our file streams the same way we are already used to use cin and cout.
In order to open a file with a stream object we use its member function open:
open (filename, mode);
Where filename is a string representing the name of the file to be opened, and mode is an optional parameter with a combination of the following flags:
ios::in
Open for input operations.
ios::out
Open for output operations.
ios::binary
Open in binary mode.
ios::ate
Set the initial position at the end of the file.
If this flag is not set, the initial position is the beginning of the file.
ios::app
All output operations are performed at the end of the file, appending the content to the current content of the file.
ios::trunc
If the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
Each of the open member functions of classes ofstream, ifstream and fstream has a default mode that is used if the file is opened without a second argument:
class
default mode parameter
ofstream
ios::out
ifstream
ios::in
fstream
ios::in | ios::out
class InputParser{
#include <string>
ios::in
Open for input operations.
ios::out
Open for output operations.
ios::binary
Open in binary mode.
ios::ate
Set the initial position at the end of the file.
If this flag is not set, the initial position is the beginning of the file.
ios::app
All output operations are performed at the end of the file, appending the content to the current content of the file.
ios::trunc
If the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.