summaryrefslogtreecommitdiffstats
path: root/ue5/mean_mark.hpp
blob: e07aedcf22f8f3b918c4bc1ed11a4ff083574dd9 (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
58
59
60
61
62
63
#ifndef MEAN_MARK_H
#define MEAN_MARK_H

#include <typeinfo>
#include <iostream>

#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;*/
        Student *s = dynamic_cast<Student *>(&(*(*first)));
        if (s == NULL)
          continue;
        result += s->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: */