回答編集履歴

3

追記

2018/11/09 09:30

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -25,3 +25,95 @@
25
25
 
26
26
 
27
27
  ところで、**これ例外を利用する意味はあるんです?**
28
+
29
+
30
+
31
+ コメントを受けて
32
+
33
+ ---
34
+
35
+ 例外を利用せよ、ってのはおそらくそういう意味では無いです。
36
+
37
+ ついでに判定処理も手直しして書いてみました。
38
+
39
+ ```C++
40
+
41
+ #include <algorithm>
42
+
43
+ #include <cstring>
44
+
45
+ #include <iostream>
46
+
47
+ #include <string>
48
+
49
+
50
+
51
+ class Password {
52
+
53
+ public:
54
+
55
+ Password(const std::string& p) {
56
+
57
+ using namespace std::literals::string_literals;
58
+
59
+
60
+
61
+ if(p.size() < 8) {
62
+
63
+ throw "Your password must be at least 8 characters long."s;
64
+
65
+ }
66
+
67
+ if(!std::any_of(std::cbegin(p), std::cend(p), ::isupper)) {
68
+
69
+ throw "Your password should contain at least one upper case."s;
70
+
71
+ }
72
+
73
+ if(!std::any_of(std::cbegin(p), std::cend(p), ::islower)) {
74
+
75
+ throw "Your password should contain at least one lower case."s;
76
+
77
+ }
78
+
79
+ if(!std::any_of(std::cbegin(p), std::cend(p), ::isdigit)) {
80
+
81
+ throw "Your password should contain at least one numeric digit."s;
82
+
83
+ }
84
+
85
+ if(!std::any_of(std::cbegin(p), std::cend(p), ::ispunct)) {
86
+
87
+ throw "Your password should contain at least one of these special characters: !@#$%&*:; ."s;
88
+
89
+ }
90
+
91
+ }
92
+
93
+ };
94
+
95
+
96
+
97
+ int main() {
98
+
99
+ try {
100
+
101
+ Password password{"buvuTGB3547&"};
102
+
103
+ std::cout << "Your password is valid.\n";
104
+
105
+ }
106
+
107
+ catch(const std::string& e_message) {
108
+
109
+ std::cerr << "Your password is not valid.\n" << e_message << "\n";
110
+
111
+ }
112
+
113
+ }
114
+
115
+ ```
116
+
117
+
118
+
119
+ 何かしら見落としや不勉強があるかもしれません。

2

確認が取れたので

2018/11/09 09:30

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -20,9 +20,7 @@
20
20
 
21
21
 
22
22
 
23
- 単に1.5と書いてしまうと、double型のリテラルと見做されるからでしょう
23
+ 単に1.5と書いてしまうと、double型のリテラルと見做されます1.5fと書いてください。
24
-
25
- 1.5fと書けば良いはず。
26
24
 
27
25
 
28
26
 

1

追記

2018/11/09 08:59

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -23,3 +23,7 @@
23
23
  単に1.5と書いてしまうと、double型のリテラルと見做されるからでしょう。
24
24
 
25
25
  1.5fと書けば良いはず。
26
+
27
+
28
+
29
+ ところで、**これ例外を利用する意味はあるんです?**