summaryrefslogtreecommitdiffstats
path: root/ue5/mean_mark.hpp
blob: ba5a2309fd83e60205201bd95310ebbb47a76e71 (plain)
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
51
52
53
54
55
56
57
#ifndef MEAN_MARK_H
#define MEAN_MARK_H

#undef SOLVED_3
#define SOLVED_3

namespace Ti
{

  template <typename Iter>
    double mean_mark(Iter first, Iter last)
    {
      double result = 0;
      unsigned count = 0;
      for(; first != last; ++first)
      {
        result += (*first)->mark();
        ++count;
      }
      return (count == 0) ? 0 : result / count;
    }

  template <typename Iter>
    double mean_mark_student(Iter first, Iter last)
    {
      double result = 0;
      unsigned count = 0;
      for(; first != last; ++first)
      {
        if (typeid(*(*first)) != typeid(Student))
          continue;
        result += (*first)->mark();
        ++count;
      }
      return (count == 0) ? 0 : result / count;
    }

  template <class ForwardIterator>
    ForwardIterator remove_greater (ForwardIterator first, ForwardIterator last, int mark)
    {
      ForwardIterator result = first;
      for (; first != last; ++first)
      {
        if ((*first)->mark() <= mark)
        {
          *result = *first;
          ++result;
        }
      }
      return result;
    }

}

#endif

/* vim: set et sw=2 ts=2: */