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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
#include <iostream>
using namespace std;
class Player {
private:
void calcFTP(void);
void calcFGP(void);
public:
float FTA, FTM, FGA, FGM, FTP, FGP, PPG, RPG, APG, SPG, BPG;
float R, A, S, B, G;
void dataCheck(void);
void setFTA(void);
void setFTM(void);
void setFGA(void);
void setFGM(void);
void setR(void);
void setA(void);
void setS(void);
void setB(void);
void setG(void);
void getPPG(void) {cout << "Average points per game--> " << PPG << endl;}
void getRPG(void) {cout << "Average rebounds per game--> " << RPG << endl;}
void getAPG(void) {cout << "Average assists per game--> " << APG << endl;}
void getSPG(void) {cout << "Average steals per game--> " << SPG << endl;}
void getBPG(void) {cout << "Average blocks per game--> " << BPG << endl;}
void getFTP(void) {cout << "Average free throw percentage--> " << FTP << "%" << endl;}
void getFGP(void) {cout << "Average field goal percentage--> " << FGP << "%" << endl;}
void setData(float FTA, float FTM, float FGA, float FGM);
void calcPPG(void);
void calcRPG(void);
void calcAPG(void);
void calcSPG(void);
void calcBPG(void);
};
void Player::calcPPG(void) {
PPG = ((FTM+(FGM*2))/G);
}
void Player::calcRPG(void) {
RPG = (R/G);
}
void Player::calcAPG(void) {
APG = (A/G);
}
void Player::calcSPG(void) {
SPG = (S/G);
}
void Player::calcBPG(void) {
BPG = (B/G);
}
void Player::setData(float FTA, float FTM, float FGA, float FGM) {
calcFTP();
calcFGP();
}
void Player::calcFTP(void) {
FTP = (FTM/FTA ) * 100;
}
void Player::calcFGP(void) {
FGP = (FGM/FGA) * 100;
}
void Player::setFTA(void) {
cout << "Please enter the player's number of free throws attempted: ";
cin >> FTA;
while(FTA < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of free throws attempted: ";
cin >> FTA;
}
}
void Player::setFTM(void) {
cout << "Please enter the player's number of free throws made: ";
cin >> FTM;
while(FTM < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of free throws made: ";
cin >> FTM;
}
}
void Player::setFGA(void) {
cout << "Please enter the player's number of field goals attempted: ";
cin >> FGA;
while(FGA < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of field goals attempted: ";
cin >> FGA;
}
}
void Player::setFGM(void) {
cout << "Please enter the player's number of field goals made: ";
cin >> FGM;
while(FGM < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of field goals made: ";
cin >> FGM;
}
}
void Player::setR(void) {
cout << "Please enter the player's number of rebounds: ";
cin >> R;
while(R < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of rebounds: ";
cin >> R;
}
}
void Player::setA(void) {
cout << "Please enter the player's number of assists: ";
cin >> A;
while(A < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of assists: ";
cin >> A;
}
}
void Player::setS(void) {
cout << "Please enter the player's number of steals: ";
cin >> S;
while(S < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of steals: ";
cin >> S;
}
}
void Player::setB(void) {
cout << "Please enter the player's number of blocked shots: ";
cin >> B;
while(B < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of blocked shots: ";
cin >> B;
}
}
void Player::setG(void) {
cout << "Please enter the player's number of games played: ";
cin >> G;
while(G < 0) {
cout << "Invalid data entry." << endl;
cout << "Please enter a positive value." << endl << endl;
cout << "Please reenter the player's number of games played: ";
cin >> G;
}
}
int main(void)
{
Player Patrick;
Patrick.setFTA();
Patrick.setFTM();
Patrick.setFGA();
Patrick.setFGM();
Patrick.setR();
Patrick.setA();
Patrick.setS();
Patrick.setB();
Patrick.setG();
Patrick.calcPPG();
Patrick.calcRPG();
Patrick.calcAPG();
Patrick.calcSPG();
Patrick.calcBPG();
Patrick.setData(FTA,FTM,FGA,FGM); // Says they are undefined? Pass by reference maybe?
Patrick.getFTP();
Patrick.getFGP();
Patrick.getPPG();
Patrick.getRPG();
Patrick.getAPG();
Patrick.getSPG();
Patrick.getBPG();
return 0;
}
|