добавлен исходный код и ссылки

This commit is contained in:
Alexander Zhirov 2023-01-22 15:43:59 +03:00
parent c83ed6cf42
commit 4be7b9c4ce
15 changed files with 438 additions and 1 deletions

View file

@ -0,0 +1,26 @@
import std.stdio : writeln, stdin;
import std.exception : enforce;
import stats;
void main(string[] args)
{
Stat[] stats;
foreach (arg; args[1 .. $])
{
auto newStat = cast(Stat) Object.factory("stats." ~ 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,48 @@
module stats;
interface Stat
{
void accumulate(double x);
void postprocess();
double result();
}
class Min : Stat
{
private double min = double.max;
void accumulate(double x)
{
if (x < min)
{
min = x;
}
}
void postprocess() {} // Ни­че­го не де­лать
double result()
{
return min;
}
}
class Max : Stat
{
private double max = double.min_normal;
void accumulate(double x)
{
if (x > max)
{
max = x;
}
}
void postprocess() {} // Ни­че­го не де­лать
double result()
{
return max;
}
}