|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 yaowuliu 于 2013-1-5 21:24 编辑
本意是想统计某场比赛热火队球员的数据,包括球员名字,球衣号码,总投篮次数,命中次数,三分及命中次数,罚球命中次数,还有投篮,三分,罚球命中率,以及上了多少个人……先就这些了……我用三个文件来实现的不甚感激……急用
#include<iostream.h>
#include<string.h>
class player
{
public:
player(char *name1,float t,int p,int x1,int x2,int y1,int y2,int z1,int z2);//带形参的构造函数
~player();
void FG(int x1,int x2);//投篮命中率
void P(int y1,int y2);//三分球命中率
void FT(int z1,int z2);//罚球命中率
void show();
void total();
player (const player& p);
void display(int i);
private:
char *name;
float time;
int number;
int FGM;
int FGA;
int PM;
int PA;
int FTM;
int FTA;
static int count;//定义静态数据成员,统计上场球员数
};
#include"player.h"
player::player(char *name1,float t,int p,int x1,int x2,int y1,int y2,int z1,int z2)
{
name=new char[strlen(name1)+1];
strcpy(name,name1);
time=t;
number=p;
FGM=x1;
FGA=x2;
PM=y1;
PA=y2;
FTM=z1;
FTA=z2;
count++;
}
void player::show()
{
cout<<number<<"\t"<<"球员:"<<"\t"<<name<<endl;
cout<<"出场时间: "<<time<<endl;
cout<<"总出手次数"<<"\t"<<FGM<<"命中"<<"\t"<<FGA<<endl;
cout<<"3分出手次数"<<"\t"<<PM<<"命中"<<"\t"<<PA<<endl;
cout<<"罚球次数"<<"\t"<<FTM<<"命中"<<"\t"<<FTA<<endl;
}
void player::FG(int x1,int x2)
{
cout<<"投篮命中率:"<<(x1/x2)*100<<"%"<<endl;
}
void player::P(int y1,int y2)
{
cout<<"三分命中率:"<<(y1/y2)*100<<"%"<<endl;
}
void player::FT(int z1,int z2)
{
cout<<"罚球命中率:"<<(z1/z2)*100<<"%"<<endl;
}
void player::display(int i)
{
cout<<"上场球员人数:"<<count<<endl;
}
#include"player.h"
void main()
{
player player1(james,6,41,8,14,1,5,13,16);
player1.show();
player player2(bosh,1,38,5,12,0,2,4,4);
player2.show();
player player3(wade,2,33,7,11,1,1,7,9);
player3.show();
player player4(haslam,3,20,2,3,0,0,0,0);
player4.show();
player player5(chalmos,4,25,2,6,1,3,0,0);
player5.show();
player player6(ray allen,5,23,2,3,1,2,0,0);
player6.show();
player6.display()
} |
|