我正在尝试制作一个计算棒球运动员平均值的程序,并一直询问直到达到用户设定的球员数量。然后我必须将数据输出到一个图表中,该图表有球员的平均击球率,并带有 * 标记。
这是我到目前为止所拥有的:
#include <iostream>
#include <string>
using namespace std;
class BattingInfo
{
public:
char fname[25];
char lname[25];
float hits;
float battimes;
float games;
float tgames;
float average;
float averaget;
float gaverage;
};
bool getd(BattingInfo& bi);
void displayd(BattingInfo& bi);
int main()
{
int players;
BattingInfo bi[9999];
cout <<"Please input the number of players:\n";
cin >> players;
int index;
index = 0;
while (getd(bi[index])&& index < players - 1)
{
index++;
}
cout << "\n\nData Entries: \n";
for (int i = 0; i <= index; i++)
{
displayd(bi[i]);
}
}
bool getd(BattingInfo& bi)
{ cout <<"Please input the Players first name:\n";
cin >> bi.fname;
cout <<"Please input the Players last name:\n";
cin >> bi.lname;
cout << "Please input the number of number of successful hits of the player.\n";
cin >> bi.hits;
cout << "Please input the numer of times at bat.\n";
cin >> bi.battimes;
cout << "Please input the number of games the player participated in.\n";
cin >> bi.games;
cout <<"Please input the total numer of games the player could have batted in.\n";
cin >> bi.tgames;
system("cls");
return true;
}
void displayd(BattingInfo& bi)
{
bi.average = bi.hits/bi.battimes;
bi.gaverage = bi.games/bi.tgames;
bi.averaget = bi.average*bi.gaverage;
cout <<"Batting Average: " << bi.averaget << endl;
cout << ".000 - .099";
if (bi.averaget > .0 && bi.averaget < .1)
{ cout << "*";}
cout << "\n.100 - .199";
if (bi.averaget > .099 && bi.averaget < .2)
{ cout << "*";}
cout << "\n.200 - .299";
if (bi.averaget > .199 && bi.averaget < .3)
{ cout << "*";}
cout << "\n.300 - .399";
if (bi.averaget > .299 && bi.averaget < .4)
{ cout << "*";}
cout << "\n.400 - .499";
if (bi.averaget > .399 && bi.averaget < .5)
{ cout << "*";}
cout << "\n.500 - .599";
if (bi.averaget > .499 && bi.averaget < .6)
{ cout << "*";}
cout << "\n.600 - .699";
if (bi.averaget > .599 && bi.averaget < .7)
{ cout << "*";}
cout << "\n.700 - .799";
if (bi.averaget > .699 && bi.averaget < .8)
{ cout << "*";}
cout << "\n.800 - .899";
if (bi.averaget > .799 && bi.averaget < .9)
{ cout << "*";}
cout << "\n.000 - .999";
if (bi.averaget > .899 && bi.averaget < .1)
{ cout << "*";}
cout << "\n1";
if (bi.averaget > .999)
{ cout << "*\n";}
system("\nPAUSE");
system("cls");
}
它有点工作,但图表是为每个球员输出的(平均只有 1 名球员),我需要它在一个图表上为整个团队输出。我不知道该怎么做。