Code for 2k game with 300 lines
1. NOTE: This program must have at least 300 lines.
2. Write a Player class.
3. Randomly make an a
ay of 10 players enter the locker room one by one using the cin to type in their psn name.
4. After typing in the player’s psn, display a message whereas each player is randomly assigned one at a time to the white or black teams. Also randomly assign each player a position. The output, for example: SG, So and so has been assigned to the black team.
5. Each team should have 5 players.
6. Start the game, randomly display quarter 1 and quarter 2 players stats with the team they are assigned to. Also display the generated positions next to the players name the same way in step 5 for all quarters. For example,
Quarter 1:
White:
SG So and so: Points, assists, rebounds…
Black:
PF So and so: Points, assists, rebounds…
Quarter 2:
White:
SG So and so: Points, assists, rebounds…
Black:
PF So and so: Points, assists, rebounds…
7. Halftime display the total team stats of all players from quarter 1 and quarter 2 For example,
White: points, assists, rebounds…
Black: points, assists, rebounds..
8. With the total players stats from quarter 1 and 2, combine these stats with a random quarter 3 and quarter 4 players’ stats and display the stats with their generated position. For example:
Quarter 3:
White:
SG So and so: Points, assists, rebounds…
Black:
PF So and so: Points, assists, rebounds…
Quarter 4:
White:
SG So and so: Points, assists, rebounds…
Black:
PF So and so: Points, assists, rebounds…
9. End the game with displaying the final score of all the players points by adding all their points together they have scored in each quarter. Then, add the total of all the players stats from all quarters for the winning team. For example,
Final score:
White: 130
Black: 129
White team has won!
The game’s final stats:
White team stats: Points, assists, rebounds…
Black team stats: Points, assists, rebounds…
The Final Project Grading Check List
In your final project, your code must be able to run. Otherwise, you can only get 60% at most from the total points.Â
You also need to check if you have the following concepts/variables/functions that are implemented.Â
(1) Classes and inheritance, (<=20 pt)
(2) overloading, (<=10 pt)
(3) ove
iding, (<=10 pt)
(4) public, private, protected, (<=10 pt)
(5) set(), get(), methods (<= 5 pt)
(6)Â abstract class (<=5pt)
(7) static or vector should be included (Add <=5 pt if you have both) (<=5 pt)
(8) Sorting or searching methods should be included for your job finding. ( <=5 pt) , add 5 pt extra if you did both.
The above list worth 70 pts total. If you are using file accessing and other advanced C++ coding techniques. Some points will be added to your projects.Â
Â
You will get basic points for each item listed above if you have done it in your project (80%) . Another 20% will be given to the student who will do excellent and meaningful work about the item listed above. For instance, you implement inheritance, but there is not necessary or does not have real meaning, you only get a 10*80%=8 points.Â
Overall project 20pt: <=10pt for operation smoothness, Comments and readability (<=10pt).
A short report (or menu) to tell us how you implement the project, or what is new, and/or what you learn. (<=10 pt.)Â
#include
#include
#include
#include
using namespace std;
Player class definition
class Player {
string psn;
string team;
string position;
int points;
int assists;
int rebounds;
int steals;
int turnovers;
int fouls;
public:
Player() {
psn = "";
team = "";
position = "";
points = 0;
assists = 0;
rebounds = 0;
steals = 0;
turnovers = 0;
fouls = 0;
}
Overloading constructo
Player(string psnName) {
psn = psnName;
team = "";
position = "";
points = 0;
assists = 0;
rebounds = 0;
steals = 0;
turnovers = 0;
fouls = 0;
}
Set player psn
void setPsn(string psnName) {
psn = psnName;
}
Get player psn
string getPsn() {
return psn;
}
Set player team
void setTeam(string teamName) {
team = teamName;
}
Get player team
string getTeam() {
return team;
}
Set player position
void setPosition(string pos) {
position = pos;
}
Get player position
string getPosition() {
return position;
}
Set player points
void setPoints(int pts) {
points = pts;
}
Get player points
int getPoints() {
return points;
}
Set player assists
void setAssists(int ast) {
assists = ast;
}
Get player assists
int getAssists() {
return assists;
}
Set player rebounds
void setRebounds(int reb) {
rebounds = reb;
}
Get player rebounds
int getRebounds() {
return rebounds;
}
Set player steals
void setSteals(int steal) {
XXXXXXXXXXsteals = steal;
}
Get player steals
int getSteals() {
XXXXXXXXXXreturn steals;
}
Set player turnovers
void setTurnovers(int TO) {
XXXXXXXXXXturnovers = TO;
}
Get player turnovers
int getTurnovers() {
XXXXXXXXXXreturn turnovers;
}
Set player fouls
void setFouls(int foul) {
XXXXXXXXXXfouls = foul;
}
Get player fouls
int getFouls() {
XXXXXXXXXXreturn fouls;
}
Overloading operator for sorting players based on points
friend bool operator < (const Player& p1, const Player& p2) {
return p1.points > p2.points;
}
function to print player stats
void printStats() {
cout
psn
": ";
cout
"Points: "
points
" ";
cout
"Assists: "
assists
" ";
cout
"Rebounds: "
rebounds
" ";
cout
"Steals: "
steals
" ";
cout
"Turnovers: "
turnovers
" ";
cout
"Fouls: "
fouls
endl;
}
};
Function to randomly assign player to team
void assignTeam(Player* players, int size) {
Seed random number generato
srand((unsigned)time(NULL));
Randomly assign players to team
string teams[2] = {"White", "Black"};
int teamIndex;
for (int i = 0; i < size; i++) {
teamIndex = rand() % 2;
players[i].setTeam(teams[teamIndex]);
}
}
Function to randomly assign position to playe
void assignPosition(Player* players, int size) {
Seed random number generato
srand((unsigned)time(NULL));
Randomly assign players to position
string positions[5] = {"PG", "SG", "SF", "PF", "C"};
int posIndex;
for (int i = 0; i < size; i++) {
posIndex = rand() % 5;
players[i].setPosition(positions[posIndex]);
}
}
Function to randomly generate stats for a quarte
void generateStats(Player* players, int size, string quarter) {
Seed random number generato
srand((unsigned)time(NULL));
Output message
cout
"\n"
quarter
" stats:"
endl;
Generate stats for each playe
int pts, ast, reb, steal, TO, foul;
for (int i = 0; i < size; i++) {
pts = rand() % 30;
ast = rand() % 10;
reb = rand() % 10;
steal = rand() % 10;
TO = rand() % 10;
foul = rand() % 3;
players[i].setPoints(pts);
players[i].setAssists(ast);
players[i].setRebounds(reb);
players[i].setSteals(steal);
players[i].setTurnovers(TO);
players[i].setFouls(foul);
Output stats
players[i].printStats();
}
}
Function to calculate total stats for a playe
void calculateTotalStats(Player* players, int size, string quarter) {
Output message
cout
"\n"
quarter
" total stats:"
endl;
Calculate total stats for each playe
int totalPts = 0, totalAst = 0, totalReb = 0, totalSteals = 0, totalTurnovers = 0, totalFouls = 0;
for (int i = 0; i < size; i++) {
totalPts += players[i].getPoints();
totalAst += players[i].getAssists();
totalReb += players[i].getRebounds();
totalSteals += players[i].getSteals();
totalTurnovers += players[i].getTurnovers();
totalFouls += players[i].getFouls();
}
Output total stats
cout
"Points: "
totalPts
" ";
cout
"Assists: "
totalAst
" ";
cout
"Rebounds: "
totalReb
" ";
cout
"Steals: "
totalSteals
" ";
cout
"Turnovers: "
totalTurnovers
" ";
cout
"Fouls: "
totalFouls
endl;
}
Function to calculate team stats
void calculateTeamStats(Player* players, int size) {
Output message
cout
"\nTeam stats:"
endl;
Calculate total stats for each team
int whitePts = 0, whiteAst = 0, whiteReb = 0,
whiteSteals = 0, whiteTurnovers = 0, whiteFouls = 0;
int blackPts = 0, blackAst = 0, blackReb = 0,
blackSteals = 0, blackTurnovers = 0, blackFouls = 0;
for (int i = 0; i < size; i++) {
if (players[i].getTeam() == "White") {
XXXXXXXXXXwhitePts += players[i].getPoints();
XXXXXXXXXXwhiteAst += players[i].getAssists();
XXXXXXXXXXwhiteReb += players[i].getRebounds();
XXXXXXXXXXwhiteSteals += players[i].getSteals();
XXXXXXXXXXwhiteTurnovers += players[i].getTurnovers();