You are on page 1of 2

1 #ifndef soccer_h_

2 #define soccer_h_
3
4 #include <algorithm>
5 #include <fstream>
6 #include <iostream>
7 #include <sstream>
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 struct Player {
13 Player() : Player("No ", "Name", 2000, false) {}
14 Player(const std::string & f, const std::string & l, const int & b, const bool & p) :
15 first(f), last(l), year(b), paid(p) {}
16 std::string first;
17 std::string last;
18 int year;
19 bool paid;
20 };
21
22 struct Stat {
23 Stat(const std::string & key) : Stat(key, 0, 0, 0) {}
24 Stat(const std::string & key, const int & number, const int & yes, const int & no) :
league(key), players(number), paid(yes), not_paid(no) {}
25
26 std::string league;
27 int players;
28 int paid;
29 int not_paid;
30 };
31
32 class Season {
33 public:
34 typedef std::map<std::string, Player> PlayerMap;
35 typedef std::map<std::string, Stat> StatMap;
36
37 Season() : Season(2000) {}
38 Season(const int & y) : current_year_(y), file_("season.txt") {}
39
40 void print_players(const std::string & FileName);
41
42 void update_stats();
43
44 void add_player(const std::string & name, const int birth_year, const bool & status);
45 void edit_player(std::string new_name, int new_year, bool new_paid);
46 void delete_player();
47
48 bool empty() {return players_.empty();}
49
50 void new_season(const int new_year);
51
52 std::string display_name();
53 std::string display_year();
54 std::string display_league();
55 std::string display_status();
56
57 StatMap::iterator get_end_stat(){return stats_.end();}
58 StatMap::iterator get_stats(){return stats_.begin();}
59 PlayerMap::iterator get_current_player() {return current_player_;}
60 size_t get_current_pos() {return current_player_pos_;}
61 size_t get_player_count() {return players_.size();}
62
63 void next_player();
64 void previous_player();
65
66 bool open();
67 bool save();
68
69 void search(const std::string & first, const std::string & last, const int year, const
bool search_paid, const bool paid);
70 int year() {return current_year_;}
71
72 private:
73 std::string get_key_(const std::string & name);
74 std::string get_first_(const std::string & name);
75 std::string get_last_(const std::string & name);
76 int get_league_(const int birth_year);
77
78 void add_stat(std::string, bool status);
79
80 int current_year_;
81 std::string file_;
82
83 StatMap stats_;
84
85 PlayerMap search_players_;
86 PlayerMap::iterator current_search_player_;
87
88 PlayerMap players_;
89 PlayerMap::iterator current_player_;
90
91 size_t current_player_pos_;
92 };
93
94 inline void Season::next_player() {
95 if (players_.size() != 0) {
96 if (current_player_ != --(players_.end())) {
97 ++current_player_;
98 ++current_player_pos_;
99 }
100 else {
101 current_player_ = players_.begin();
102 current_player_pos_ = 1;
103 }
104 }
105 }
106
107 inline void Season::previous_player() {
108 if (players_.size() != 0) {
109 if (current_player_ != players_.begin()) {
110 --current_player_;
111 --current_player_pos_;
112 }
113 else {
114 current_player_ = --(players_.end());
115 current_player_pos_ = players_.size();
116 }
117 }
118 }
119
120 #endif // soccer_h_
121

You might also like