0

Header File

#pragma once
#ifndef PLAYERDATA_H
#define PLAYERDATA_H
#include <string>
using namespace std;


class PlayerData
 {
private:

Private member variables

static const int SIZE = 10;
string name;            //Player Name
int jnum;               //Jersey Number
string team;            //Player Team
string position;        //Player position
int points[SIZE];       // Array of points for last 10 games
int rebounds[SIZE];     // Array of rebounds for last 10 games
int assist[SIZE];       // Array of assist for last 10 games
double ap = 0.0;            // Average number of points
double ar = 0.0;            // Average number of rebounds
double aa = 0.0;            // Average number of assits


public:

Constructor to initialize data if no data is passed

// Constructor #1
PlayerData()
{
    jnum = 0;
    name = "";
    team = "";
    position = "";
    for (int i = 0; i < SIZE; i++)
    {
        points[SIZE] = 0;
        rebounds[SIZE] = 0;
        assist[SIZE] = 0;
    }

}

// Constructor #2

Constructor to accept parameter. Collects jersey number, name, team name, position, array of points for last 10 games, array of rebounds for last 10 games, array of assist for last 10 games.

PlayerData( int jn, string n, string t, string pos, int p[SIZE], int r[SIZE], int a[SIZE])
{

    jnum = jn;
    name = n;
    team = t;
    position = pos;
    for (int i = 0; i < SIZE; i++)
    {
        points[SIZE] = p[SIZE];
        rebounds[SIZE] = r[SIZE];
        assist[SIZE] = a[SIZE];
    }

}


// Mutator Function

void setJersery(int jn)
{
    jnum = jn;
}

void setName(string n)
{
    name = n;
}

void setTeam(string t)
{
    team = t;
}

void setPosition(string pos)
{
    position = pos;
}

void  setPoints(int p[SIZE])
{
    for (int z = 0; z < SIZE; z++)
    {
        points[SIZE] = p[SIZE];
    }
}

void  setRebounds(int r[SIZE])
{
    for (int z = 0; z < SIZE; z++)
    {
        rebounds[SIZE] = r[SIZE];
    }
}

void  setAssist(int a[SIZE])
{
    for (int z = 0; z < SIZE; z++)
    {
        assist[SIZE] = a[SIZE];
    }
}


// Acessor methods
string getName()
{
    return name;
}

int getJersey()
{
    return jnum;
}

string getTeam()
{
    return team;
}

string getPosition()
{
    return position;
}

int getPoints()
{
    return points[SIZE];
}

int getRebounds()
{
    return rebounds[SIZE];
}

int getAssist()
{
    return assist[SIZE];
}
/*
double averageP(int p[], const int SIZE);
double averageR(int r[], const int SIZE);
double averageA(int a[], const int SIZE);
*/
void  averageP(int p[], const int SIZE);
void averageR(int r[], const int SIZE);
void averageA(int a[], const int SIZE);


double getAP()
{
    return ap;
}

double getAR()
{
    return ar;
}

double getAA()
{
    return aa;
}

};

#endif // !PLAYERDATA_H

Calculates average points,rebounds, assist from the arrays that were passed.

PlayerData.cpp

#include "PlayerData.h"
using namespace std;

// Calculate average points
void PlayerData::averageP(int p[], const int s)
{
for (int c = 0; c < s; c++)
{
  ap += p[c];
}

ap /= s;

//return ap;
}

 // Calculate average rebounds
 void PlayerData::averageR(int r[], const int s)
{
for (int c = 0; c < s; c++)
{
    ar += r[c];
}

ar /= s;

//return ar;
}

  // Calculate average assist
void PlayerData::averageA(int a[], const int s)
{
for (int c = 0; c < s; c++)
{
    aa += a[c];
}

aa /= s;

//return aa;
}

Main

#include <iostream>
#include <iomanip>
#include "PlayerData.h"
using namespace std;


int main()
{
const int SIZE = 10;
int points[SIZE] = { 10,10,10,10,10,10,10,10,10,10 };
int assist[SIZE] = { 2,2,2,2,2,2,2,2,2,2, };
int rebounds[SIZE] = { 3,3,3,3,3,3,3,3,3,3 };

Here is where the problem occurs. The compiler marks under the 6 as if the int is not part of the arguments for the constructor. I'm not sure why it is doing this. I receive this message "No instance of constructor "PlayerData::PlayerData" matches the argument list."

PlayerData player1(6,  "Jimmy Butler",  "Chicago Bulls", "Forward",    points[SIZE],  rebounds[SIZE],  assist[SIZE]);   
getchar();
return 0;
}
Frantz Paul
  • 127
  • 2
  • 11
  • 2
    I think you need to take a few steps back, and [find a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to re-read the chapter on arrays. Especially how you pass arrays to functions. A good hint should be in the ***full*** error message, if you just read it all. – Some programmer dude Mar 24 '17 at 09:20
  • `points[SIZE]` is an int not an array of int . Also it is off the end of the array so Undefined Behaviour. – Richard Critten Mar 24 '17 at 09:22
  • On an unrelated note: If you want to define two arrays using the same size, then use only a single "variable" for the size. What if you in the future change `PlayerData::SIZE` but forget to change `SIZE` in the `main` function? – Some programmer dude Mar 24 '17 at 09:24

1 Answers1

0

Constructor requires an array of integers and in main you are passing a pointer to int. If you want to pass the whole array you should delete the [SIZE] because that is translated as (if SIZE is 5 for example) "give me the 6th element of 5 element array".

Try calling it like this.

PlayerData player1(6,  "Jimmy Butler",  "Chicago Bulls", "Forward",    points,  rebounds,  assist);
Petar Velev
  • 2,305
  • 12
  • 24