输出图表/条形图的棒球平均值
Baseball average with chart/bar graph outputted
我正在尝试制作一个程序来计算棒球运动员的平均数,并不断询问,直到达到用户设置的球员数量。然后,我必须将数据输出到一个图表中,该图表让球员平均击球,并用*标记它落入的位置。
这是我到目前为止所拥有的:
#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 << "nnData 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 名球员),我需要它在一张图上为整个团队输出。我不知道该怎么做。
这是一个非常基本的图表,从左到右显示值。您可以以此为基础并对其进行更改以显示您的数据。如果这不是您要查找的,则可能需要使用适当的GUI库。
请注意我使用矢量<>而不是数组。除非必要,否则不要使用数组。使用矢量。
我猜这可能是一个学校项目,所以自己完成这个可能是最好的。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void display_as_graph(vector<int>& numbers)
{
char space = ' ';
for(int i = 0; i < numbers.size(); i++)
{
for(int num_spaces = 0; num_spaces < numbers[i]; num_spaces++)
{
cout << space;
}
cout << "xn";
}
}
int main()
{
vector<int> numbers;
numbers.push_back(4);
numbers.push_back(6);
numbers.push_back(8);
numbers.push_back(3);
display_as_graph(numbers);
string wait;
cin >> wait;
return 0;
}
相关文章:
- 计算数组c++的平均值
- C / C++ 移位/偏移/向左或向右移动位图?
- Qt 图表条形图调整大小崩溃
- 通过显示一行星号来创建条形图,该条形图将读取数据的输入文件
- QT 条形图/QT 商业 5.6 的图形
- 使用星号在条形图中输出负值,以表示三个值的范围
- 使用 OpenGL 使用 C++ 以图形方式表示堆积条形图
- 如何在C++中创建 ASCII 艺术条形图
- 使用循环创建条形图
- 使用 char*array 存储条形图的条形图,以便我可以动态制作它并作为字符串返回
- 创建.svg条形图
- Qt.的浮动条形图
- 输出图表/条形图的棒球平均值
- 五家商店的销售条形图
- C++ :使用 * 显示数组数据的条形图
- 销售条形图
- 在QCustomPlot中,如何实时绘制相同数据的折线图和条形图
- 如何为矢量<类型*>条形图*赋值*
- 显示条形图(和其他时髦的图形)
- 条形图程序行为奇怪