Repository navigation
Expand file tree
/
Copy pathmpags-cipher-work.cpp
More file actions
117 lines (102 loc) · 3.29 KB
/
Copy pathmpags-cipher-work.cpp
File metadata and controls
117 lines (102 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <cctype>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
std::string transformChar(const char in_char)
{
std::string out_str{""};
if (std::isalpha(in_char)){
out_str += std::toupper(in_char);
return out_str;
}
// Transliterate digits to English words
switch (in_char) {
case '0':
out_str = "ZERO";
break;
case '1':
out_str = "ONE";
break;
case '2':
out_str = "TWO";
break;
case '3':
out_str = "THREE";
break;
case '4':
out_str = "FOUR";
break;
case '5':
out_str = "FIVE";
break;
case '6':
out_str = "SIX";
break;
case '7':
out_str = "SEVEN";
break;
case '8':
out_str = "EIGHT";
break;
case '9':
out_str = "NINE";
break;
}
return out_str;
}
bool processCommandLine( const std::vector<std::string>& args, bool& helpRequested, bool& versionRequested, std::string& inputFileName, std::string& outputFileName )
{
// Check for help option
if (std::find(args.begin(), args.end(), "-h") != args.end() ||
std::find(args.begin(), args.end(), "--help") != args.end()) {
helpRequested = true;
std::cout << "Usage: mpags-cipher [OPTIONS]\n"
<< "Options:\n"
<< " -h, --help Show this help message\n"
<< " --version Show version information\n"
<< " -i <file> Specify input file\n"
<< " -o <file> Specify output file\n";
}
// Check for version option
if (std::find(args.begin(), args.end(), "--version") != args.end()) {
versionRequested = true;
std::cout << "Version 0.0.1" << std::endl;
}
// Parse input and output file names
for (std::size_t i{0}; i < args.size(); ++i) {
if (args.at(i) == "-i" && i + 1 < args.size()) {
inputFileName = args.at(i + 1);
std::cout << "Input file name: " << inputFileName << std::endl;
}
if (args.at(i) == "-o" && i + 1 < args.size()) {
outputFileName = args.at(i + 1);
std::cout << "Output file name: " << outputFileName << std::endl;
}
}
return true;
}
int main(int argc, char* argv[])
{
// Create vector of arguments
const std::vector<std::string> cmdLineArgs { argv, argv + argc };
bool helpRequested{false};
bool versionRequested{false};
std::string inputFileName{""};
std::string outputFileName{""};
processCommandLine( cmdLineArgs, helpRequested, versionRequested, inputFileName, outputFileName );
// Read input one line at a time
std::string inputLine;
while (std::getline(std::cin, inputLine)) {
// Store the transliterated text
std::string inputText;
// Loop over each character in the input line
for (char inputChar : inputLine) {
// Transform the character and append to the output string
inputText += transformChar(inputChar);
}
// Print out the transliterated text
std::cout << inputText << std::endl;
}
return 0;
}