Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- #include <string>
- #include <sstream>
- #include <fstream>
- using namespace std;
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- class Player{
- private:
- string firstName;
- string lastName;
- int height;
- vector<string>skills;
- public:
- static vector<Player*> PlayersAll;
- Player(string fn, string ln, int h){
- firstName = fn;
- lastName = ln;
- height = h;
- skills.push_back("Shooting");
- skills.push_back("Passing");
- skills.push_back("Dribbling");
- skills.push_back("Defence");
- skills.push_back("Heading");
- PlayersAll.push_back(this);
- }
- Player(const Player &p){
- firstName = p.firstName;
- lastName = p.lastName;
- height = p.height;
- skills = p.skills;
- }
- string GetFirstName(){
- return firstName;
- }
- string GetLastName(){
- return lastName;
- }
- void changeFirstName(string s){
- firstName = s;
- }
- void changeLastName(string s){
- lastName = s;
- }
- void changeHeight(int i){
- height = i;
- }
- void AddSkill(string s){
- skills.push_back(s);
- }
- string showInfo(){
- ostringstream ss;
- ss << height;
- string skillsToReturn = "\n";
- for(int i =0;i<skills.size();i++){
- skillsToReturn+= skills[i]+"\n";
- }
- return "My name is: " + firstName + " " + lastName + "\nHeight: " + ss.str() +"\nSkills: "+skillsToReturn;
- }
- };
- vector<Player*> Player::PlayersAll; //????????????
- class Team{
- static int maxPlayersInTeam;
- static int teamsAlreadyCreated;
- string teamName;
- public:
- vector<Player*> playersInTeam;
- Team(string tn){
- teamName = tn;
- for(int i = (teamsAlreadyCreated*5);i<maxPlayersInTeam+(5*teamsAlreadyCreated);i++){
- playersInTeam.push_back(Player::PlayersAll[i]);
- }
- teamsAlreadyCreated++;
- }
- Team(string tn, ifstream& f){
- teamName = tn;
- vector<int> semicolonPositions;
- string line;
- while(getline(f,line)){
- for(int i=0;i<line.length();i++){
- if(line[i]==';'){
- semicolonPositions.push_back(i);
- }
- }
- int height;
- istringstream iss(line.substr(semicolonPositions[1]+1));
- iss >> height;
- Player *p = new Player(line.substr(0, semicolonPositions[0]),line.substr(semicolonPositions[0]+1,semicolonPositions[1]-semicolonPositions[0]-1), height);
- playersInTeam.push_back(p);
- string firstName = line.substr(0, semicolonPositions[0]);
- string lastName = line.substr(semicolonPositions[0]+1,semicolonPositions[1]-semicolonPositions[0]-1);
- string height2 = line.substr(semicolonPositions[1]+1);
- // cout << "First Name: " << firstName << endl;
- // cout << "Last Name: " << lastName << endl;
- // cout << "Height: " << height2 << endl;
- cout << "\n\n";
- semicolonPositions.clear();
- }
- }
- Team(const Team &t){
- teamName = t.teamName;
- playersInTeam = t.playersInTeam;
- }
- void changeTeamName(string tn){
- teamName = tn;
- }
- string TeamInfo(){
- string stringToReturn;
- stringToReturn += "\n\nOur name is: "+ teamName + "! \nOur players: ";
- for(int i = 0; i<playersInTeam.size();i++){
- stringToReturn+="\n" +playersInTeam[i] -> GetFirstName()+" " +playersInTeam[i] ->GetLastName();
- //stringToReturn+="\n" +playersInTeam[i].GetFirstName()+" " +playersInTeam[i].GetLastName();
- }
- return stringToReturn;
- }
- };
- int Team::maxPlayersInTeam = 5;
- int Team::teamsAlreadyCreated = 0;////????????????????????//////////////
- int main(int argc, char** argv) {
- //Player* p2 = &p1;
- // cout << p2 << endl;
- //cout << &p1 << endl;
- // cout << (*p2).GetFirstName() << endl;
- //cout << p1 << endl;
- /* Player p1("A", "A", 181);
- cout << p1.showInfo();
- Player p2("B", "B", 131);
- Player p3("C", "C", 151);
- Player p4("D", "D", 131);
- Player p5("F", "F", 131);
- Player p6("G", "G", 181);
- Player p7("H", "H", 131);
- Player p8("J", "J", 151);
- Player p9("K", "K", 131);
- Player p10("L", "L", 131);
- Team t1("T1");
- Team t2("T2");
- Team t3 = t2;
- t3.changeTeamName("T3");
- cout << t1.TeamInfo();
- cout << "\n" << endl;
- cout << t2.TeamInfo();
- cout << "\n" << endl;
- cout << t3.TeamInfo() << endl;
- cout << "------------" << endl;
- p10.changeFirstName("DDDD");
- cout << t1.TeamInfo();
- cout << "\n" << endl;
- cout << t2.TeamInfo();
- cout << "\n" << endl;
- cout << t3.TeamInfo();*/
- // Player p("a","b",120);
- ifstream f("example.txt");
- Team t1("T1",f);
- cout << Player::PlayersAll.size();
- cout << Player::PlayersAll[0] -> showInfo();
- cout << t1.TeamInfo();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement