Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in C++ please and make sure it matches the output below. Thanks and will rate. please feel free to comments if you can. We

Write in C++ please and make sure it matches the output below. Thanks and will rate. please feel free to comments if you can. We need to write a program to help our favorite team keep track of its players performance. The file that will print out the players stats is done. You are given a class for a player; however, a football team is composed of offensive and defensive players. So you need to build on the player class. It is rare that a player is both, so we will assume our team has exclusively offensive and defensive players. All players have a name, number and they all play for some number of minutes. However, a defensive player is measured by the number of tackles they get, while an offensive player is measured by the number of yards they get. For this assignment you need to create 2 classes that inherit from a class player that has already been written. This class makes no calculations; it just holds data on each player. Your class will be used by the main function in main.cpp to print the teams stats, so it must follow the guidelines below. You may not change the files given in any way. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The program does not compile because it's missing some classes. The project needs 4 files added: defense.h, defense.cpp, offense.h, offense.cpp (10 points). There are also a few questions that must be answered (20 points). image text in transcribed

Given Files:

player.h

/* * This is the header file for the player class * You are not allowed to change this file. * 10 points will be subtracted if this file is modified. * */

// Question 3 - What do the #ifndef, #define and #endif preprocessor commands do in this file? #ifndef PLAYER_H #define PLAYER_H

#include #include

using namespace std;

class Player{ private: string name; // The player's name, notice it's private, Question 4 - What does this mean you have to do?

protected: // Question 5 - Why does number have to be private. int number; // The player's number. int minutes; // The number of minutes the player is in the game.

public:

/* * This is the constructor for the player class. * @param The player's name. */ Player(string name);

/* * This is a mutator method, it sets the player's number. * @param The player's number. */ void setNumber(int number);

/* * Add comments for this method in your inherited class. */ virtual void setMinutesPlayed(int minutes) = 0; // Question 6 - why does this method equal zero? /* * This is a method to print out a players stats, its virtual, * so it is possible to override it. */ virtual void printStats() const; // Question 7 - What does 'const' do here? };

#endif

.................................................................................................................................................................................

player.cpp

/* * This is the implementation file for the player class * You are not allowed to change this file. * 10 points will be subtracted if this file is modified. * */

#include "player.h"

/* * This is the constructor for the player class. * @param The player's name. */ Player::Player(string name){ this->name = name; }

/* * This is a mutator method, it sets the player's number. * @param The player's number. */ void Player::setNumber(int number){ this->number = number; }

/* * This is a method to print out a players stats, its virtual, * so it is possible to override it. */ void Player::printStats() const{ cout

.................................................................................................................................................................................

main.cpp

/* * This is the main class * You are not allowed to change this file. * 10 points will be subtracted if this file is modified. * */

#include #include #include "player.h" #include "offense.h" #include "defense.h" #include using namespace std;

int main(){

// Create the players for the team. Offense player("Bob"); Defense player1("Jane"); Offense player2("Sai"); Defense player3("Chin"); Offense player4("Kali");

Player *team[5]; // Make a team of pointers to players.

// Question 1 - Why is there an '&' before the players on lines 29 to 33? team[0] = &player; team[1] = &player1; team[2] = &player2; team[3] = &player3; team[4] = &player4;

// Set the player numbers for(int i=0; isetNumber(i+10);

// Set the player minutes. for(int i=0; isetMinutesPlayed(i*7+(i+1)*i+1);

// Question 2 - Why not use a loop for lines 45 to 49? // Set the player's stats. player.setYards(34); player1.setTackles(5); player2.setYards(23); player3.setTackles(7); player4.setYards(132);

// Print out each player's stats. for(int i=0; iprintStats();

system("pause");

} image text in transcribed

Note the main.cpp, player.h and player.cpp files must not be changed in any way. 10 points will be deducted if any of them has been modified. The added files should be formatted similarly to the Player class files. The classes need to have the following, and you must decide the retum types, visibility and any additional modidifiers for these methods: defense class fields int tacklesi defense class methods: Defense (string name) setMinutesPlayed (int minutes); setTackles (int tackles)i printStats) const: offense class fields: int yards: offense class methods: Offense (string name) i setMinutesPlayed (int minutes); setYards (int yards) printStats) const: Rules: . Your classes must inherit from the base class Player . You should not recode anything. If the base class already does something, do NOT put it in your derived class. Use what has been already there. . You should follow the coding conventions of the program given. All files should have a brief description at the beginning that includes the title of the file and your name. The code should have comments describing each method and large section. See the provided code for examples. - All 4 of the methods listed for each new class above must be implemented. You can add extra methods, but it is not necessary and there is no bonus. This is just a suggestion: the solution averages exactly one line of code (LOC) inside each method, so if a method has 2 LOC, another should have 0 LOC. There is no trick here either with crazy lines that call multiple methods or anything else. Basically, if you are writing many lines of code per method, you need to review inheritance or polymorphism. All classes should include all needed libraries

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

What advantages do taller people have over shorter people?

Answered: 1 week ago