The goal of today's meeting is to understand what makes a program or library well designed. These are somewhat subjective criteria but constitute the consensus of a large number of good programmers. You should strive to follow these principles and recommendations.
Links:
Command-line applications often allow user input at program startup, using the argument to main:
int main(int argc, char *argv[])
where argc is the number of space-separated strings type after the executable name. For example, suppose we have an executable named do.exe
. It might take several different arguments (> is the command prompt)
> do.exe -flag -setting=12 afilename1 afilename2
where
flag
is an option, if argv[1]="-flag"
is present the flag it considered set by the program, else notsetting
is a parameter with the text after the = parsed as a numberafilename1
and afilename2
are just strings representing filenamesThe first two arguments are optional and by convention start with a dash. Their ordering on the command-line does not matter. The last two are called a positional arguments, are required, and their order matters. So the following would start the program the same way:
> do.exe -setting=12 afilename1 -flag afilename2
Generally if a required argument is missing or an unexpected argument is present then an error is printed along with usage information, e.g.
> do.exe -flag myfile.txt
Error: missing positional argument
Usage: do.exe [-flag] [-setting=N] file1 file 2
* flag is an optional flag
* setting is an optional parameter where N is a positive integer
* file1 is the input file
* file2 is the output file
Consider a class named CommandLineArguments
that helps the programmer deal with command-line arguments. Design a class to do this by creating a header file command_line_arguments.hpp
that defines the public part of the class interface.
You do not have to implement any of the methods and you can create other abstractions (classes, functions) as needed without explicitly defining them.
This code does not have to compile.
GitHub Invitation URL: exercise6
Steps:
Clone the assignment for today after accepting the GitHub invitation at the link above.
git clone https://github.com/VTECE3574/exercise06-USER.git
where USER is your GitHub username. You may have to enter your GitHub username and password.
In the file named command_line_arguments.hpp
design your class as instructed above.
Finally, use git push to synchronize the repository with that on GitHub
You have completed the Exercise.