回答編集履歴
3
追記
answer
CHANGED
@@ -11,4 +11,50 @@
|
|
11
11
|
|
12
12
|
単に1.5と書いてしまうと、double型のリテラルと見做されます。1.5fと書いてください。
|
13
13
|
|
14
|
-
ところで、**これ例外を利用する意味はあるんです?**
|
14
|
+
ところで、**これ例外を利用する意味はあるんです?**
|
15
|
+
|
16
|
+
コメントを受けて
|
17
|
+
---
|
18
|
+
例外を利用せよ、ってのはおそらくそういう意味では無いです。
|
19
|
+
ついでに判定処理も手直しして書いてみました。
|
20
|
+
```C++
|
21
|
+
#include <algorithm>
|
22
|
+
#include <cstring>
|
23
|
+
#include <iostream>
|
24
|
+
#include <string>
|
25
|
+
|
26
|
+
class Password {
|
27
|
+
public:
|
28
|
+
Password(const std::string& p) {
|
29
|
+
using namespace std::literals::string_literals;
|
30
|
+
|
31
|
+
if(p.size() < 8) {
|
32
|
+
throw "Your password must be at least 8 characters long."s;
|
33
|
+
}
|
34
|
+
if(!std::any_of(std::cbegin(p), std::cend(p), ::isupper)) {
|
35
|
+
throw "Your password should contain at least one upper case."s;
|
36
|
+
}
|
37
|
+
if(!std::any_of(std::cbegin(p), std::cend(p), ::islower)) {
|
38
|
+
throw "Your password should contain at least one lower case."s;
|
39
|
+
}
|
40
|
+
if(!std::any_of(std::cbegin(p), std::cend(p), ::isdigit)) {
|
41
|
+
throw "Your password should contain at least one numeric digit."s;
|
42
|
+
}
|
43
|
+
if(!std::any_of(std::cbegin(p), std::cend(p), ::ispunct)) {
|
44
|
+
throw "Your password should contain at least one of these special characters: !@#$%&*:; ."s;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
int main() {
|
50
|
+
try {
|
51
|
+
Password password{"buvuTGB3547&"};
|
52
|
+
std::cout << "Your password is valid.\n";
|
53
|
+
}
|
54
|
+
catch(const std::string& e_message) {
|
55
|
+
std::cerr << "Your password is not valid.\n" << e_message << "\n";
|
56
|
+
}
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
何かしら見落としや不勉強があるかもしれません。
|
2
確認が取れたので
answer
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
> ```
|
10
10
|
|
11
11
|
|
12
|
-
単に1.5と書いてしまうと、double型のリテラルと見做され
|
12
|
+
単に1.5と書いてしまうと、double型のリテラルと見做されます。1.5fと書いてください。
|
13
|
-
1.5fと書けば良いはず。
|
14
13
|
|
15
14
|
ところで、**これ例外を利用する意味はあるんです?**
|
1
追記
answer
CHANGED
@@ -10,4 +10,6 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
単に1.5と書いてしまうと、double型のリテラルと見做されるからでしょう。
|
13
|
-
1.5fと書けば良いはず。
|
13
|
+
1.5fと書けば良いはず。
|
14
|
+
|
15
|
+
ところで、**これ例外を利用する意味はあるんです?**
|