I am having several issues, besides figuring out how to word this request.
1. Trying to integrate some sort of looping to increment class object.
2. Properly declaring #1
3. The use of Static member function to Subtotal and Total data.
4. ? What ever is messed up.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Player {
public:
char pP;
int sN, tAB, nOH;
string pN;
void GetData(); // Obtain all Player Data
void Calculations(); // Perform calcs and to display all the player's detail totals
float ShowSub(); // Show Each Position's SubTotals
float ShowTotal(); // Show Team Totals
private:
char positionPlayed;
int shirtNumber;
string playerName;
int timesAtBat;
int numberOfHits;
float pAvg, iAvg, oAvg, avg;
static int pTABSub, pNOHSub;
static int iTABSub, iNOHSub;
static int oTABSub, oNOHSub;
static int teamTABTotal, teamNOHTotal;
};
int Player::pTABSub = 0;
int Player::pNOHSub = 0;
int Player::iTABSub = 0;
int Player::iNOHSub = 0;
int Player::oTABSub = 0;
int Player::oNOHSub = 0;
int n;
Player playerNumber;
void Player::GetData(){
positionPlayed = pP;
shirtNumber = sN;
playerName = pN;
timesAtBat = tAB;
numberOfHits = nOH;
cout << "For Player #" << n << " \n\tEnter Positon Played: (p)Pitcher,(i)Infielder,(o)Outfielder: "; cin >> pP;
cout << "\tEnter Shirt Number: "; cin >> sN;
cout << "\tEnter Players Name: "; getline(cin, pN);
cout << "\tEnter Times at Bat: "; cin >> tAB;
cout << "\tEnter Number of Hits: "; cin >> nOH;
}
void Player::Calculations(){
const avg = ((float) numberOfHits) / timesAtBat; //cast expression original int NumberOfHits to float
if (positionPlayed == 'p'){
pTABSub += pTABSub;
pTABSub += teamTABTotal;
pNOHSub += pNOHSub;
pNOHSub += teamNOHTotal;
pAvg =((float) pNOHSub) / pTABSub;
} else if (positionPlayed == 'i'){
iTABSub += iTABSub;
iTABSub += teamTABTotal;
iNOHSub += iNOHSub;
iNOHSub += teamNOHTotal;
} else if (positionPlayed == 'o'){
oTABSub += oTABSub;
oTABSub += teamTABTotal;
oNOHSub += oNOHSub;
oNOHSub += teamNOHTotal;
}
cout << left << setw(12) << playerNumber[n].playerName << "\t" << playerNumber[n].shirtNumber
<< "\t\t" << playerNumber[n].timesAtBat << "\t\t" << playerNumber[n].numberOfHits
<< "\t\t" << fixed << setw(4) << setprecision(3) << playerNumber[n].avg << endl;
}
void Player::ShowSub(position catagory){
cout << "Pitcher Stats SubTotals:\t\t\t\t" << pTABSub << "\t\t" << pNOHSub
<< "\t\t" << fixed << setw(4) << setprecision(3) << pAvg << endl;
}
float Player::ShowTotal(){
}
int main{
int n;
Player playerNumber[n];
cout << "Please enter Player Data in the Following Format: /\n"
<< "Ex:\n\tp <enter> 12 <enter> Bob Smith <enter> 150 <enter> 101 <enter>\n"
if (n = 1; n < 9; n++){
Player playerNumber[n];
playerNumber[n].GetData();
}
cout << "\nName\t\tPlayer #\tTimes at bat\tHits\t\tBatting Average" << endl;
playerNumber[n].ShowSub();
return 0;
}
I appreciate any help/pointers.