-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cpp
50 lines (42 loc) · 1.29 KB
/
controller.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
48
49
50
#include <controller.h>
#include <string>
Controller::Controller(): Controller(std::shared_ptr<OutStream> (new FileOutStream("main.txt")),
std::shared_ptr<Number> (new IntNumber)) {}
Controller::Controller(std::shared_ptr<OutStream> out,
std::shared_ptr<Number> num) :
out(out),
num(num),
numbersender(NumberSender(out, num)),
fizzsender(FizzSender(out, num)),
buzzsender(BuzzSender(out, num)),
fizzbuzzsender(FizzBuzzSender(out, num)) { }
void Controller::process_to(int n) {
for(int i = 1; i <= n; i ++) {
num->set(i);
if(i % 15 == 0) {
fizzbuzzsender.send();
} else if (i % 3 == 0) {
fizzsender.send();
} else if (i % 5 == 0) {
buzzsender.send();
} else {
numbersender.send();
}
out->sendString("\n");
}
}
void Controller::process_period(int start, int end){
for(int i = start; i <= end; i ++) {
num->set(i);
if(i % 15 == 0) {
fizzbuzzsender.send();
} else if (i % 3 == 0) {
fizzsender.send();
} else if (i % 5 == 0) {
buzzsender.send();
} else {
numbersender.send();
}
out->sendString("\n");
}
}