Trouble getting my code through a test

I'm having trouble getting my code through my instructors test program. Can anyone help tell me what's wrong? This is my code and header:

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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
UserInputHandler::UserInputHandler(){
  set_invalid_char_input("Failure: Too many characters");
  set_char_not_allowed("Failure: Invalid character.");
  set_invalid_int("Failure: Input is not an integer.");
  set_low_int("Failure: Integer is too low.");
  set_high_int("Failure: Integer is too high.");
  set_invalid_double("Failure: Input is not a double.");
  set_invalid_bool("Failure: Please enter 'T', 'F', 'true', or 'false'.");
  set_too_long_string("Failure: Too many characters."); 
  set_empty_string("Failure: String is empty.");
}

void UserInputHandler::set_invalid_char_input(std::string error) {
  invalid_char_input_= error;
}
void UserInputHandler::set_char_not_allowed(std::string error) {
  char_not_allowed_ = error;
}
void UserInputHandler::set_invalid_int(std::string error) {
  invalid_int_ = error;
}
void UserInputHandler::set_low_int(std::string error) {
  low_int_ = error;
}
void UserInputHandler::set_high_int(std::string error) {
  high_int_ = error;
}
void UserInputHandler::set_invalid_double(std::string error) {
  invalid_double_ = error;
}
void UserInputHandler::set_invalid_bool(std::string error) {
  invalid_bool_ = error;
}
void UserInputHandler::set_too_long_string(std::string error) {
  too_long_string_ = error;
}
void UserInputHandler::set_empty_string(std::string error) {
  empty_string_ = error;
}
std::string UserInputHandler::invalid_char_input() const {
  return invalid_char_input_;
} 
std::string UserInputHandler::char_not_allowed() const {
  return char_not_allowed_;
} 
std::string UserInputHandler::invalid_int() const {
  return invalid_int_;
} 
std::string UserInputHandler::low_int() const {
  return low_int_;
} 
std::string UserInputHandler::high_int() const {
  return high_int_;
} 
std::string UserInputHandler::invalid_double() const {
  return invalid_double_;
} 
std::string UserInputHandler::invalid_bool() const {
  return invalid_bool_;
} 
std::string UserInputHandler::too_long_string() const {
  return too_long_string_;
} 
std::string UserInputHandler::empty_string() const {
  return empty_string_;
} 
char UserInputHandler::GetSingleCharacter(std::string limit = "") {
  std::string str;
  char letter;
  bool loopend = false;
  while (loopend == false) {
    std::getline(std::cin, str);
    size_t i = str.length();
    if (i > 1) {
      std::cout << invalid_char_input() << std::endl;
    } else {
      if (limit == "") {
        letter = str[0];
        std::cout << "Character Entered: " << letter << endl;
        loopend = true;
      } else if (std::string::npos == limit.find(str)) {
        std::cout << char_not_allowed() << std::endl;
      } else {
        letter = str[0];
        std::cout << "Character Entered: " << letter << endl;
        loopend = true;
      }
    }
  }
  return letter;
}
int UserInputHandler::GetInteger(const int& min, const int& max) {
  int result;
  bool loopend = false;
  while (loopend == false) {
    std::string line;
    if (getline(std::cin, line)) {
      std::stringstream ss(line);
      if (ss >> result && ss.eof()) {
        if (result < min) {
          std::cout << low_int() << std::endl;
        } else if (result > max) {
          std::cout << high_int() << std::endl;
        } else {
          std::cout << "Integer Entered is: " << result << endl;
          loopend = true;
        }
      } else {
        std::cout << invalid_int() << std::endl;
      }
    }
  }
return result;
}
double UserInputHandler::GetDouble() {
  double result;
  std::string line;
  bool loopend = false;
  while (loopend == false) {
    if (getline(std::cin, line)) {
      std::stringstream ss(line);
      if (!(ss >> result && ss.eof())) {
        std::cout << invalid_double() << std::endl;
      } else {
        std::cout << "Double Entered is: " << result << endl;
        loopend = true;
      }
    }
  }
  return result;
}
  bool UserInputHandler::GetBoolean() {
  std::string str;
  bool test;
  string result;
  bool loopend = false;
  while (loopend == false) {
    std::getline(std::cin, str);
    if (str == "T") {
      test = true;
      result = "true";
      loopend = true;
    } else if ( str == "F") {
      test = false;
      result = "false";
      loopend = true;
    } else if (str == "true") {
      test = true;
      result = "true";
      loopend = true;
    } else if (str == "false") {
      test = false;
      result = "false";
      loopend = true;
    } else {
      std::cout << invalid_bool() << std::endl;
    }
  }
  std::cout << "Boolean: " << result << endl;
  return test;
}
string UserInputHandler::GetString(int charnumber = -1, bool empty = true) {
  int i;
  bool infinite;
  if (charnumber == -1) {
    infinite = true;
  } else {
    infinite = false;
  }
  std::string str;
  bool loopend = false;
  while (loopend == false) {
    std::getline(std::cin, str);
    i = (int)str.length();
    if (i == 0) {
      if (empty == false) {
        std::cout << empty_string() << endl;
      } else {
        std::cout << "String Entered: " << str << endl;
        loopend = true;
      }
    } else if (i > charnumber) {
      if (infinite == false) {
        std::cout << too_long_string() << std::endl;
      } else {
        std::cout << "String Entered: " << str << endl;
        loopend = true;
      }
    } else {
      std::cout << "String Entered: " << str << endl;
      loopend = true;
    }
  }
  return str;
}

int main() {
  UserInputHandler handler;
  handler.GetSingleCharacter("abcd");
  handler.GetInteger(0,100);
  handler.GetDouble();
  handler.GetBoolean();
  handler.GetString(5, false);
}


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
class UserInputHandler {
public:
  UserInputHandler();
  char GetSingleCharacter(std::string limit);
  int GetInteger(const int& min, const int& max);
  double GetDouble();
  bool GetBoolean();
  std::string GetString(int charnumber, bool empty);
  void set_invalid_char_input(std::string error);
  void set_char_not_allowed(std::string error);
  void set_invalid_int(std::string error);
  void set_low_int(std::string error);
  void set_high_int(std::string error);
  void set_invalid_double(std::string error);
  void set_invalid_bool(std::string error);
  void set_too_long_string(std::string error);
  void set_empty_string(std::string error);
  std::string invalid_char_input() const;
  std::string char_not_allowed() const;
  std::string invalid_int() const;
  std::string low_int() const;
  std::string high_int() const;
  std::string invalid_double() const;
  std::string invalid_bool() const;
  std::string too_long_string() const;
  std::string empty_string() const;
private:
  std::string invalid_char_input_;
  std::string char_not_allowed_;
  std::string invalid_int_;
  std::string low_int_;
  std::string high_int_;
  std::string invalid_double_;
  std::string invalid_bool_;
  std::string too_long_string_;
  std::string empty_string_;
};

This is the test code.

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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
int main() {
  // Create UserInputHandler Object and test variables
  UserInputHandler uih;
  char char_var;
  int int_var;
  double double_var;
  bool bool_var;
  string string_var;

  // Testing Accessors
  cout << "Testing Accessors\n" << "----------------------------\n";
  cout.setf(std::ios::left);
  cout << setw(22) << "invalid_char_input_:" << uih.invalid_char_input()
       << endl;
  cout << setw(22) << "char_not_allowed_:" << uih.char_not_allowed() << endl;
  cout << setw(22) << "invalid_int_:" << uih.invalid_int() << endl;
  cout << setw(22) << "low_int_:" << uih.low_int() << endl;
  cout << setw(22) << "high_int_:" << uih.high_int() << endl;
  cout << setw(22) << "invalid_double_:" << uih.invalid_double() << endl;
  cout << setw(22) << "invalid_bool_:" << uih.invalid_bool() << endl;
  cout << setw(22) << "too_long_string_:" << uih.too_long_string() << endl;
  cout << setw(22) << "empty_string_:" << uih.empty_string() << endl << endl;

  // Testing Mutators
  cout << "Testing Mutators\n" << "----------------------------\n";
  cout.setf(std::ios::left);
  uih.set_invalid_char_input("invalid_char_input_");
  uih.set_char_not_allowed("char_not_allowed_");
  uih.set_invalid_int("invalid_int_");
  uih.set_low_int("low_int_");
  uih.set_high_int("high_int_");
  uih.set_invalid_double("invalid_double_");
  uih.set_invalid_bool("invalid_bool_");
  uih.set_too_long_string("too_long_string_");
  uih.set_empty_string("empty_string_");
  cout << setw(22) << "invalid_char_input_:" << uih.invalid_char_input()
       << endl;
  cout << setw(22) << "char_not_allowed_:" << uih.char_not_allowed() << endl;
  cout << setw(22) << "invalid_int_:" << uih.invalid_int() << endl;
  cout << setw(22) << "low_int_:" << uih.low_int() << endl;
  cout << setw(22) << "high_int_:" << uih.high_int() << endl;
  cout << setw(22) << "invalid_double_:" << uih.invalid_double() << endl;
  cout << setw(22) << "invalid_bool_:" << uih.invalid_bool() << endl;
  cout << setw(22) << "too_long_string_:" << uih.too_long_string() << endl;
  cout << setw(22) << "empty_string_:" << uih.empty_string() << endl << endl;

  // Tests GetSingleCharacter()
  cout << "Testing GetSingleCharacter()\n" << "----------------------------\n"
       << "Correct Input: A, b, %, 8\n"
       << "Incorrect Input (invalid_char_input_): (empty string), hello, 12345"
       << "\nTry a character: ";
  char_var = uih.GetSingleCharacter();

  cout << char_var << " is indeed a single character!\n\n" << endl;

  // Tests GetSingleCharacter(allowed_characters)
  cout << "Testing GetSingleCharacter(\"ABC123!$\")\n"
       << "----------------------------\n" << "Correct Input: A, B, 1, 2, $\n"
       << "Incorrect Input (invalid_char_input_): (empty string), hello, 12345"
       << "\nIncorrect Input (char_not_allowed_): %, 8, a, D"
       << "\nTry a character: ";
  char_var = uih.GetSingleCharacter("ABC123$");

  cout << char_var << " is indeed a single character!\n\n" << endl;

  // Tests GetInteger()
  cout
      << "Testing GetInteger()\n"
      << "----------------------------\n"
      << "Correct Input: -1000, 0, 1000\n"
      << "Incorrect Input (invalid_int_): (empty string), hello, abc123, 123abc, 1.0, 5.5, -"
      << "\nTry an integer: ";
  int_var = uih.GetInteger();

  cout << int_var << " is indeed an integer!\n\n" << endl;

  // Tests GetInteger(0)
  cout
      << "Testing GetInteger(0)\n"
      << "----------------------------\n"
      << "Correct Input: 0, 1000\n"
      << "Incorrect Input (invalid_int_): (empty string), hello, abc123, 123abc, 1.0, 5.5, -\n"
      << "Incorrect Input (low_int_): -1, -1000\n" << "Try an integer: ";
  int_var = uih.GetInteger(0);

  cout << int_var << " is indeed an integer!\n\n" << endl;

  // Tests GetInteger(0, 10)
  cout
      << "Testing GetInteger(0, 10)\n"
      << "----------------------------\n"
      << "Correct Input: 0, 5, 10\n"
      << "Incorrect Input (invalid_int_): (empty string), hello, abc123, 123abc, 1.0, 5.5, -\n"
      << "Incorrect Input (low_int_): -1, -1000\n"
      << "Incorrect Input (high_int_): 11, 1000\n" << "Try an integer: ";
  int_var = uih.GetInteger(0, 10);

  cout << int_var << " is indeed an integer!\n\n" << endl;

  // Tests GetDouble()
  cout
      << "Testing GetDouble()\n"
      << "----------------------------\n"
      << "Correct Input: -10, 0, 10, -10.5, 10.0, 0.5, .5\n"
      << "Incorrect Input (invalid_double_): (empty string), hello, abc123, 123abc, 1.0., .5-, -, .\n"
      << "Try a double: ";
  double_var = uih.GetDouble();

  cout << double_var << " is indeed a double!\n\n" << endl;

  // Tests GetBoolean()
  cout
      << "Testing GetBoolean()\n"
      << "----------------------------\n"
      << "Correct Input: T, F, t, f, TRUE, false, TrUe, fAlSe\n"
      << "Incorrect Input (invalid_bool_): (empty string), hello, abc123, 123abc, 1.0, 1, truea, zfalse\n"
      << "Try a boolean: ";
  bool_var = uih.GetBoolean();

  cout << std::boolalpha << bool_var << " is indeed a boolean!\n\n" << endl;

  // Tests GetString()
  cout
      << "Testing GetString()\n"
      << "----------------------------\n"
      << "Correct Input: ABCDEFGHIJKLMNOPQRSTUVWXYZ, 123, &^%, (empty string), Hello World!\n"
      << "Try a string: ";
  string_var = uih.GetString();
  cout << ((string_var.empty()) ? "(empty string)" : string_var)
       << " is indeed a string!\n\n" << endl;

  // Tests GetString(0)
  cout
      << "Testing GetString(0)\n"
      << "----------------------------\n"
      << "Correct Input: (empty string)\n"
      << "Incorrect Input (too_long_string_): a, %, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 123, &^%, Hello World!\n"
      << "Try a string: ";
  string_var = uih.GetString(0);
  cout << ((string_var.empty()) ? "(empty string)" : string_var)
       << " is indeed a string!\n\n" << endl;

  // Tests GetString(5)
  cout
      << "Testing GetString(5)\n"
      << "----------------------------\n"
      << "Correct Input: (empty string), a, abc, 12345, 12 45\n"
      << "Incorrect Input (too_long_string_): ABCDEFGHIJKLMNOPQRSTUVWXYZ, Hello World!\n"
      << "Try a string: ";
  string_var = uih.GetString(5);
  cout << ((string_var.empty()) ? "(empty string)" : string_var)
       << " is indeed a string!\n\n" << endl;

  // Tests GetString(-1, false)
  cout << "Testing GetString(-1, false)\n" << "----------------------------\n"
       << "Correct Input: ABCDEFGHIJKLMNOPQRSTUVWXYZ, 123, &^%, Hello World!\n"
       << "Incorrect Input (empty_string_): (empty string)\n"
       << "Try a string: ";
  string_var = uih.GetString(-1, false);
  cout << ((string_var.empty()) ? "(empty string)" : string_var)
       << " is indeed a string!\n\n" << endl;

  // Tests GetString(1, false)
  cout
      << "Testing GetString(1, false)\n"
      << "----------------------------\n"
      << "Correct Input: 1, A, %\n"
      << "Incorrect Input (too_long_string_): ABCDEFGHIJKLMNOPQRSTUVWXYZ, 123, &^%, Hello World!\n"
      << "Incorrect Input (empty_string_): (empty string)\n"
      << "Try a string: ";
  string_var = uih.GetString(1, false);
  cout << ((string_var.empty()) ? "(empty string)" : string_var)
       << " is indeed a string!\n\n" << endl;

  // Tests GetString(5, false)
  cout
      << "Testing GetString(5, false)\n"
      << "----------------------------\n"
      << "Correct Input: a, abc, 12345, 12 45\n"
      << "Incorrect Input (too_long_string_): ABCDEFGHIJKLMNOPQRSTUVWXYZ, Hello World!\n"
      << "Incorrect Input (empty_string_): (empty string)\n"
      << "Try a string: ";
  string_var = uih.GetString(5, false);
  cout << ((string_var.empty()) ? "(empty string)" : string_var)
       << " is indeed a string!\n\n" << endl;
}
And this is the compile error I'm getting.

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
$ g++ -Wall -Wextra -pedantic -o assignment_2 user_input_handler.cpp user_input_handler_unit_test.cpp
user_input_handler_unit_test.cpp: In function ‘int main()’:
user_input_handler_unit_test.cpp:68:37: error: no matching function for call to ‘UserInputHandler::GetSingleCharacter()’
   char_var = uih.GetSingleCharacter();
                                     ^
user_input_handler_unit_test.cpp:68:37: note: candidate is:
In file included from user_input_handler_unit_test.cpp:11:0:
user_input_handler.h:15:8: note: char UserInputHandler::GetSingleCharacter(std::string)
   char GetSingleCharacter(std::string limit);
        ^
user_input_handler.h:15:8: note:   candidate expects 1 argument, 0 provided
user_input_handler_unit_test.cpp:89:28: error: no matching function for call to ‘UserInputHandler::GetInteger()’
   int_var = uih.GetInteger();
                            ^
user_input_handler_unit_test.cpp:89:28: note: candidate is:
In file included from user_input_handler_unit_test.cpp:11:0:
user_input_handler.h:16:7: note: int UserInputHandler::GetInteger(const int&, const int&)
   int GetInteger(const int& min, const int& max);
       ^
user_input_handler.h:16:7: note:   candidate expects 2 arguments, 0 provided
user_input_handler_unit_test.cpp:100:29: error: no matching function for call to ‘UserInputHandler::GetInteger(int)’
   int_var = uih.GetInteger(0);
                             ^
user_input_handler_unit_test.cpp:100:29: note: candidate is:
In file included from user_input_handler_unit_test.cpp:11:0:
user_input_handler.h:16:7: note: int UserInputHandler::GetInteger(const int&, const int&)
   int GetInteger(const int& min, const int& max);
       ^
user_input_handler.h:16:7: note:   candidate expects 2 arguments, 1 provided
user_input_handler_unit_test.cpp:144:30: error: no matching function for call to ‘UserInputHandler::GetString()’
   string_var = uih.GetString();
                              ^
user_input_handler_unit_test.cpp:144:30: note: candidate is:
In file included from user_input_handler_unit_test.cpp:11:0:
user_input_handler.h:19:15: note: std::string UserInputHandler::GetString(int, bool)
   std::string GetString(int charnumber, bool empty);
               ^
user_input_handler.h:19:15: note:   candidate expects 2 arguments, 0 provided
user_input_handler_unit_test.cpp:155:31: error: no matching function for call to ‘UserInputHandler::GetString(int)’
   string_var = uih.GetString(0);
                               ^
user_input_handler_unit_test.cpp:155:31: note: candidate is:
In file included from user_input_handler_unit_test.cpp:11:0:
user_input_handler.h:19:15: note: std::string UserInputHandler::GetString(int, bool)
   std::string GetString(int charnumber, bool empty);
               ^
user_input_handler.h:19:15: note:   candidate expects 2 arguments, 1 provided
user_input_handler_unit_test.cpp:166:31: error: no matching function for call to ‘UserInputHandler::GetString(int)’
   string_var = uih.GetString(5);
                               ^
user_input_handler_unit_test.cpp:166:31: note: candidate is:
In file included from user_input_handler_unit_test.cpp:11:0:
user_input_handler.h:19:15: note: std::string UserInputHandler::GetString(int, bool)
   std::string GetString(int charnumber, bool empty);
               ^
user_input_handler.h:19:15: note:   candidate expects 2 arguments, 1 provided
Topic archived. No new replies allowed.