For my program, we have to make our own class and implement it through our choice of Offense or Defense. This piggybacks off an assignment I asked about last week. I keep getting a big negative number for my number of tackles. This is a group project and I will be posting my classes and files. Please let me know what I am doing wrong and how to fix the tackles. Thank you in advance.
//main
/*
* This is the main class for CSC 4111 Lab 1 Task 2
* You are not allowed to change this file.
* 10 points will be subtracted if this file is modified.
*
* @Author C. Dorman
*/
#include <iostream>
#include <string>
#include "player.h"
#include "offense.h"
#include "defense.h"
#include "catherine.h"
#include "Jasmine.h"
#include <windows.h>
usingnamespace std;
int main(){
// Create the players for the team.
Offense player("Bob");
Defense player1("Jane");
Offense player2("Sai");
Defense player3("Chin");
Offense player4("Kali");
Offense player5("Tom");
Catherine player6("Catherine");
Jasmine player7("Jasmine");
Player *team[9]; // 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;
team[5] = &player5;
team[6] = &player6;
team[7] = &player7;
// Set the player numbers
for(int i=0; i<8; i++)
team[i]->setNumber(i+10);
// Set the player minutes.
for(int i=0; i<8; i++)
team[i]->setMinutesPlayed(i*8+(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);
player5.setYards(20);
player6.setYards(75);
player7.setTackles(3);
player6.setTouchdowns(1);
// Print out each player's stats.
for(int i=0; i<8; i++)
team[i]->printStats();
system("pause");
}
//player.h
/*
* This is the header file for the player class for CSC 4111 Lab 1 Task 2
* You are not allowed to change this file.
* 10 points will be subtracted if this file is modified.
*
* @Author C. Dorman
*/
// Question 3 - What do the #ifndef, #define and #endif preprocessor commands do in this file?
#ifndef PLAYER_H
#define PLAYER_H
#include <iostream>
#include <string>
usingnamespace 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.
*/
virtualvoid 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.
*/
virtualvoid printStats() const; // Question 7 - What does 'const' do here?
};
#endif
//player.cpp
/*
* This is the implementation file for the player class for CSC 4111 Lab 1 Task 2
* You are not allowed to change this file.
* 10 points will be subtracted if this file is modified.
*
* @Author C. Dorman
*/
#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 << "Name: " << name << "\tNumber: " << number;
}