forked from Ak0s/zerda-exam-cpp-orientation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument.cpp
More file actions
85 lines (74 loc) · 1.6 KB
/
argument.cpp
File metadata and controls
85 lines (74 loc) · 1.6 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
#include <iostream>
#include "argument.h"
using namespace std;
Argument::Argument(int argc, char* argv[], string input_filename) {
this->argc = argc;
this->argv = argv;
this->input_filename = input_filename;
}
void Argument::run() {
if (argc == 1) {
string _input;
set_input_filename(_input);
}
else if (argc > 1) {
select_function();
}
}
void Argument::select_function() {
string _output,
int _shift_num;
if (is_valid_selector()) {
if (argv[1] == "-s") {
cin >> _shift_num;
set_shift_num(_shift_num);
}
else if (argv[1] == "-o") {
cin >> _output;
set_output_filename(_output);
}
else {
cerr << "Unsupported argument.\n";
}
if (argv[2] == "-o") {
cin >> _output;
set_output_filename(_output);
}
else if (argv[2] == "-s") {
cin >> _shift_num;
set_shift_num(_shift_num);
}
else {
cerr << "Unsupported argument.\n";
}
}
}
bool Argument::is_valid_selector() {
string selector = argv[1];
if (selector != "a.out" && selector != "-s" && selector != "-o") {
cerr << "Unsupported argument.\n";
return false;
}
else {
return true;
}
}
string Argument::get_input_filename() {
return input_filename;
}
string Argument::set_input_filename(string _input) {
input_filename = _input;
}
string Argument::get_output_filename() {
return output_filename;
}
string Argument::set_output_filename(string _output) {
output_filename = _output;
}
int Argument::get_shift_num() {
return shift_num;
}
int Argument::set_shift_num(int _num) {
shift_num = _num;
}
Argument::~Argument() {}