-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpa_lab_6_4_4_(1)-B.cpp
47 lines (38 loc) · 1.03 KB
/
cpa_lab_6_4_4_(1)-B.cpp
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
#include <iostream>
using namespace std;
class StringValidator{
public:
virtual ~StringValidator() {};
virtual bool isValid(string input) = 0;
};
class ExactValidator : public StringValidator {
private:
string exactString;
public:
ExactValidator(string str);
virtual bool isValid(string input);
};
ExactValidator::ExactValidator(string str) : exactString(str) {}
bool ExactValidator::isValid(string input)
{
return input == this->exactString;
}
class DummyValidator : public StringValidator {
public:
virtual bool isValid(string input);
};
bool DummyValidator::isValid(string input){
return true;
}
void printValid(StringValidator &validator, string input){
cout << "The string '" << input << "' is " << (validator.isValid(input) ? "valid" : "invalid") << endl;
}
int main(){
DummyValidator dummy;
printValid(dummy, "hello");
cout << endl;
ExactValidator exact("secret");
printValid(exact, "hello");
printValid(exact, "secret");
return 0;
}