-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomposite.cc
More file actions
136 lines (124 loc) · 2.23 KB
/
Copy pathcomposite.cc
File metadata and controls
136 lines (124 loc) · 2.23 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <vector>
using namespace std;
class IShow
{
public:
virtual void Show() = 0;
};
class Player : public IShow
{
string name;
public:
Player(string nm) : name(nm)
{}
void Show()
{
cout<<"\t\t\t\t\t"<<name<<endl;
}
};
class PlayersList : public vector<Player*>
{
public:
PlayersList()
{
}
};
class Team : public IShow
{
PlayersList player_vector;
string name;
public:
Team(string nm) : name(nm)
{
}
void Show()
{
cout<<"\t\t\t\t"<<name<<endl;
auto it = player_vector.begin();
auto end = player_vector.end();
while(it != end)
{
(*it)->Show();
it++;
}
}
void AddPlayer(string plname)
{
player_vector.push_back(new Player(plname));
}
};
class TeamList : public vector<Team*>
{
public:
TeamList()
{}
};
class Division : public IShow
{
TeamList teamList;
string name;
public:
Division(string name) : name(name)
{}
void Show()
{
cout<<"\t\t"<<name<<endl;
auto it = teamList.begin();
auto end = teamList.end();
while(it != end)
{
(*it)->Show();
it++;
}
}
void AddTeam(string team_name)
{
teamList.push_back(new Team(team_name));
}
Team& operator[](int index)
{
return *teamList[index];
}
};
class DivisionList : vector<Division*>
{
public:
void AddDivision( string name)
{
push_back(new Division(name));
}
void Show()
{
cout<<"\t\t"<<endl;
auto it = begin();
auto en = end();
while(it != en)
{
(*it)->Show();
it++;
}
}
Division& operator[](int index)
{
return *at(index);
}
};
int main()
{
DivisionList divList;
divList.AddDivision("Alpha");
divList.AddDivision("Gamma");
Division& d1 = divList[0];
d1.AddTeam("RCB");
d1.AddTeam("KKR");
Team& t1 = d1[0];
t1.AddPlayer("Virat");
t1.AddPlayer("ABD");
Team& t2 = d1[1];
t2.AddPlayer("Karthik");
t2.AddPlayer("Robin");
divList.Show();
return 0;
}
//code should be corrected to make use of map instead of vector