Compare commits

...
This repository has been archived on 2021-11-27. You can view files and clone it, but cannot push or open issues or pull requests.

1 Commits

Author SHA1 Message Date
Alexander Zhirov 59e66c4231 example_8 2021-11-21 15:07:41 +03:00
5 changed files with 81 additions and 0 deletions

15
src/example_8/.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
.dub
docs.json
__dummy.html
docs/
/example_8
example_8.so
example_8.dylib
example_8.dll
example_8.a
example_8.lib
example_8-test-*
*.exe
*.o
*.obj
*.lst

9
src/example_8/dub.json Normal file
View File

@ -0,0 +1,9 @@
{
"authors": [
"Alexander"
],
"description": "Интерфейсы и классы",
"license": "proprietary",
"name": "example_8",
"targetPath": "bin"
}

View File

@ -0,0 +1,26 @@
import std.stdio : writeln, stdin;
import std.exception : enforce;
import min_, stat_;
void main(string[] args)
{
Stat[] stats;
foreach (arg; args[1 .. $])
{
auto newStat = cast(Stat) Object.factory("min_." ~ arg);
enforce(newStat, "Invalid statistics function: " ~ arg);
stats ~= newStat;
}
for (double x; stdin.readf(" %s ", &x) == 1;)
{
foreach (s; stats)
{
s.accumulate(x);
}
}
foreach (s; stats)
{
s.postprocess();
writeln(s.result());
}
}

View File

@ -0,0 +1,23 @@
module min_;
import stat_;
class Min : Stat
{
private double min = double.max;
void accumulate(double x)
{
if (x < min)
{
min = x;
}
}
void postprocess() {}
double result()
{
return min;
}
}

View File

@ -0,0 +1,8 @@
module stat_;
interface Stat
{
void accumulate(double x);
void postprocess();
double result();
}