运动会"/>
A.运动会
A.运动会 | |||||
| |||||
Description | |||||
利用面向对象设计方法解决问题。 运动会结束后统计各学院运动员绩点分数。 现有类College的完整定义,其中places表示学院团体总分排名(int型),Collegename表示学院名称(string型)。 现完成程序计算某学院某运动员绩点分数,运动员Athlete(每人设定只参加一项比赛)信息包括:本学院团体总分排名(int型),Collegename表示学院名称(string型),name表示运动员姓名(string型),rank表示运动员个人参赛排名(int型)。 绩点分数设定:绩点总分=成绩分+参赛分。 成绩分=学院团体排名前8名的每名运动员得分(9-places)*4+个人比赛排名前8的得分(9-rank)*2。团体和个人未进入前8的不得分。 参赛分=5。 | |||||
Input | |||||
有1组测试数据。有一行输入运动员的学院团体排名,运动员个人参赛排名,学院名称,个人姓名,数据之间以空格分隔。 | |||||
Output | |||||
针对输入数据,有一行输出。 输出的内容分别是运动员所在学院名称,个人姓名,绩点总分。数据之间以空格分隔。 | |||||
Sample Input | |||||
3 9 EB JACK | |||||
Sample Output | |||||
EB JACK 29 | |||||
Hint | |||||
#include<iostream> #include<stdio.h> #include<cmath> #include<iomanip> #include<cstdio> class College{ protected: int places; string Collegename; public: int getP(){return places;} string getCN(){return Collegename;} void setP(int p){places=p;} void setCN(string n){Collegename=n;} }; int main() { Athlete a; int p,r; string cn,n; cin>>p>>r>>cn>>n; a.setALL(p,r,cn,n); cout<<a.getCN()<<" "<<a.getN()<<" "<<a.getTotal()<<endl; return 0; } |
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdio>
using namespace std;
class College
{
protected:
int places;
string Collegename;
public:
int getP() { return places; }
string getCN() { return Collegename; }
void setP(int p) { places = p; }
void setCN(string n) { Collegename = n; }
};
class Athlete
{
public:
int places; //本学院团体总分排名
string Collegename;
string name;
int rank;
void setALL(int p, int r, string cn, string n)
{
places = p, rank = r, Collegename = cn, name = n;
}
string getCN()
{
return Collegename;
}
string getN()
{
return name;
}
int getTotal()
{
if (places < 9 && rank < 9)
{
return (9 - places) * 4 + (9 - rank) * 2 + 5;
}
else if (places < 9 && rank >= 9)
{
return (9 - places) * 4 + 5;
}
else if (places >= 9 && rank < 9)
{
return (9 - rank) * 2 + 5;
}
else return 5;
}
};
int main()
{
Athlete a;
int p, r;
string cn, n;
cin >> p >> r >> cn >> n;
a.setALL(p, r, cn, n);
cout << a.getCN() << " " << a.getN() << " " << a.getTotal() << endl;
return 0;
}
更多推荐
A.运动会
发布评论