Negative number

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//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>
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");
	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");

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//jasmine.cpp
#include "defense.h"
#include "Jasmine.h"
#include "player.h"
#include<string>
#include<iostream>


using namespace std;

Jasmine::Jasmine(string name) : Defense(name) {}

void Jasmine::setTackles(int tackles)
{
tackles=tackles;
}

void Jasmine::printStats() 
{
	Defense::printStats();
	cout<<"\tTackles"<<tackles<<endl;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//jasmine.h
//CSC 4111 Assignment 2
// Jasmine.h
#ifndef JASMINE_H
#define JASMINE_H
#include "player.h"
#include "defense.h"
#include<string>
#include<iostream>


using namespace std;

class Jasmine : public Defense
{
	public:
	Jasmine (string name);

//void printStats(const int);

void setTackles(int tackles);
void printStats () ;

private:
	int tackles;
	};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//defense.h
#ifndef DEFENSE_H
#define DEFENSE_H

#include "player.h"
#include <iostream>
#include <string>

using namespace std;

class Defense:public Player
{
private:
	int tackles;

public:
	Defense(string name);
	virtual void setMinutesPlayed(int minutes);
	void setTackles(int tackles);
	virtual void printStats() const;
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//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>

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 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//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;
}
sorry boss, give an example to understand your project.
input, internal calculation, output
Topic archived. No new replies allowed.