It overrides selectPlayer method to select the designed players for goalkeeper position
It defines the budget for goalkeepers as static const
Defender class:
This is a derived class of class Player
It overrides selectPlayer method to select the designed players for defender position
It defines the budget for defender as static const
Midfielder class:
This is a derived class of class Player
This is a derived class of class Player
It overrides selectPlayer method to select the designed players for midfielder position
It defines the budget for midfielder as static const
Forward class:
This is a derived class of class Player
It overrides selectPlayer method to select the designed players for forward position
It defines the budget for forward as static const
You are given in “Players.txt” the list of player names, teams, positions, price and points in previous season. You have to parse this file to populate the vectors of players of type goalkeeper, defender, midfielder and forward.
When overriding selectPlayer method at each derived class, you must count the available budget for that position and substract the amount of money you spent for previous players taking into consideration that you can select exactly only 2 goalkeepers, 5 defenders, 5 midfielders and 3 forwards.
You are given some handouts of sample code to read from/write to a file and to insert to/ delete from vectors.
A sample of the final squad choice into file “Squad.txt” is shown below:
*****************************
The selected Goalies are:
*****************************
Hugo Lloris (Spurs)
Heurelho Gomes (Watford)
*****************************
The selected Defenders are:
*****************************
Kyle Walker (Man City)
Daley Blind (Man Utd)
Hector Bellerin (Arsenal)
Alberto Moreno (Liverpool)
Seamus Coleman (Everton)
*****************************
The selected Midfielders are:
*****************************
Dimitri Payet (West Ham)
Oscar (Chlesea)
Sadio Mane (Liverpool)
Anthony Martial (Man Utd)
Christian Eriksen (Spurs)
*****************************
The selected Forwards are:
*****************************
Sergio Aguero (Man City)
Jermain Defoe (Sunderland)
Harry Kane (Spurs)
Here is my code. please notice that my friend used vector while I need a stack function
#include <iostream>
#include <fstream>
using namespace std;
class Player //It is an abstract base class
{
private:
string name;
string team;
string position;
double price;
int ptsPrevSeason;
public: //the getters and setters of each private data field
void setName(string n)
{
name=n;
}
string getName()
{
return name;
}
void setTeam(string t)
{
team=t;
}
string getTeam()
{
return team;
}
void setPosition(string p)
{
position=p;
}
string getPosition()
{
return position;
}
void setPrice(double p)
{
price=p;
}
double getPrice()
{
return price;
}
void setPtsPrevSeason(int p)
{
ptsPrevSeason=p;
}
int getPtsPrevSeason()
{
return ptsPrevSeason;
}
//An abstract function selectPlayer
virtual vector<Player*> selectPlayer(vector<Player*> players)=0;
};
//derived class of class Player
class Goalkeeper : public Player
{
//It defines the budget for goalkeepers as static const
static budgetForGoalKeepers=10; //£10 to get 2 goal keepers
//It overrides selectPlayer method to select the designed players for goalkeeper position
vector<Player*> selectPlayer(vector<Player*> players)
{
}
};
//derived class of class Player
class Defender : public Player
{
//It defines the budget for defenders as static const
static budgetForDefender=25; //£25 to get 5 defenders
//It overrides selectPlayer method to select the designed players for defender position
vector<Player*> selectPlayer(vector<Player*> players)
{
}
};
//derived class of class Player
class Midfielder : public Player
{
//It defines the budget for midfielders as static const
static budgetForMidfielders=35; //£35 to get 5 midfielders
//It overrides selectPlayer method to select the designed players for midfielders position
vector<Player*> selectPlayer(vector<Player*> players)
{
}
};
//This is a derived class of class Player
class Forward : public Player
{
//It defines the budget for forward as static const
static budgetForForwards=30; //£30 to get 3 forwards
//It overrides selectPlayer method to select the designed players for forward position
vector<Player*> selectPlayer(vector<Player*> players)
{
}
};
int main()
{
/*“Players.txt” the list of player names, teams, positions, price and points in previous season. */
ifstream infile("Players.txt");
if(!infile)
{
cout<<"Please provide input file Players.txt";
exit(0);
}
//vectors of players of type goalkeeper, defender, midfielder and forward.
Here is my code. please notice that my friend used vector while I need a stack function
Your code, really? It looks more like your friend's code. So where is your code? What do you mean by a "stack function"? If you need a stack why can't you just use std::stack?
Edit: By the way the instructions you supplied state to use a std::vector, and makes no mention of using a stack. Perhaps you need to post your instructions as well?