Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- using namespace std;
- //Players Class
- class Player
- {
- private:
- // Variables
- int Id;
- string Name;
- string Nationality;
- int Number;
- public:
- static int PlayerID;
- Player(){
- Id = PlayerID++;
- Name = "Default";
- Nationality = "Unknown";
- Number = 1;
- }
- Player(string name, string nationality, int number)
- {
- Id = PlayerID++;
- Name = name;
- Nationality = Nationality;
- Number = 1;
- }
- //Destructer
- ~Player() {}
- int Run()
- {
- return rand() % 100;
- }
- };
- //ID Reset
- int Player::PlayerID = 0;
- //Teams Class
- class Team
- {
- private:
- // Variables
- int Id;
- string Name;
- int Ranking;
- int Points;
- //set of players
- Player* Players;
- public:
- static int TeamID;
- Team()
- {
- Id = TeamID++;
- Name = "Player";
- Ranking = 0;
- Points = 0;
- Players = NULL;
- }
- Team(string name, int ranking, int points, Player* players)
- {
- Id = TeamID++;
- Name = name;
- Ranking = ranking;
- Points = points;
- Players = players;
- }
- //Destructer
- ~Team() {}
- void RegisterPlayer(Player p)
- {
- *Players = p;
- }
- int returnPoints() {
- return Points;
- }
- };
- //ID Reset
- int Team::TeamID = 0;
- //League Class
- class League
- {
- private:
- // Variables
- int Id;
- string Name;
- string Nationality;
- int Number;
- Team* Teams;
- public:
- static int LeagueID;
- League()
- {
- Id = LeagueID++;
- Name = "Player";
- Nationality = "Unknown";
- Number = 0;
- Teams = NULL;
- }
- League(string name, string nationality, int number, Team* teams)
- {
- Id = LeagueID++;
- Name = name;
- Nationality = nationality;
- Number = number;
- Teams = teams;
- }
- //Destructer
- ~League() {}
- Team* GetTeams()
- {
- return Teams;
- }
- };
- //ID Reset
- int League::LeagueID = 0;
- /*Linked List *Failed attempt to sort teams and players*
- class node {
- public:
- int data;
- node* next;
- };
- class linked_list {
- private:
- public:
- node* head, * tail;
- linked_list() {
- head = NULL;
- tail = NULL;
- }
- void add_node(int n)
- {
- node* tmp = new node;
- tmp->data = n;
- tmp->next = NULL;
- if (head == NULL)
- {
- head = tmp;
- tail = tmp;
- }
- else
- {
- tail->next = tmp;
- tail = tail->next;
- }
- }
- };*/
- void main()
- {
- //Arrays sizes
- int sizeOfLeagues;
- int sizeOfTeam;
- int sizeOfPlayers;
- cout << "How many leagues do you want to create?" << endl;
- cin >> sizeOfLeagues;
- cout << "How many Teams in this league :" << endl;
- cin >> sizeOfTeam;
- cout << "How many Players in this team :" << endl;
- cin >> sizeOfPlayers;
- //Defining Variables
- League* ptrLeagues = new League[sizeOfLeagues];
- Player* ptrPlayers = new Player[sizeOfTeam];
- Team* ptrTeams = new Team[sizeOfPlayers];
- string name;
- string teamName;
- string playerName;
- string nationality;
- string playerNationality;
- int number;
- int playerNumber;
- int teamRank;
- int teamPoints;
- //Start the magic
- //Leagues Loop
- for (int i = 0; i < sizeOfLeagues; i++)
- {
- cout << "League name :" << endl;
- cin >> name;
- cout << "League nationailty :" << endl;
- cin >> nationality;
- cout << "League number :" << endl;
- cin >> number;
- //Teams Loop
- for (int j = 0; j < sizeOfTeam; j++)
- {
- cout << "Team name :" << endl;
- cin >> teamName;
- cout << "Team ranking :" << endl;
- cin >> teamRank;
- cout << "Team points :" << endl;
- cin >> teamPoints;
- //Players Loop
- for (int k = 0; k < sizeOfPlayers; k++)
- {
- cout << "Player name :" << endl;
- cin >> playerName;
- cout << "Player nationality :" << endl;
- cin >> playerNationality;
- cout << "Player number :" << endl;
- cin >> playerNumber;
- Player player(playerName, playerNationality, playerNumber);
- *(ptrPlayers + k) = player;
- }
- Team team(teamName, teamRank, teamPoints, ptrPlayers);
- *(ptrTeams + j) = team;
- }
- League League(name, nationality, number, ptrTeams);
- *(ptrLeagues + i) = League;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement