【c++oj】OOP 球员成就统计(单继承)

题目描述

定义一个球员类Player,包含数据成员name,height,weight。

派生两个奖项类MVP与DPOY。MVP记录了获奖年,得分,篮板,助攻信息。DPOY记录了获奖年,篮板,抢断,盖帽信息。

MVP的获奖条件是得分>25,篮板>6,助攻>6;

DPOY的获奖条件是篮板>12,盖帽>2.5,抢断>1.5。

根据题目要求,增加必要的构造函数和其他所需函数。

输入

第一行输入球员姓名,以及身高体重。

接下来12行输入球员2010年到2021年的场均数据(得分,篮板,助攻,盖帽,抢断)

输出

第一行输出球员的基本信息。

输出球员获得MVP的获奖年,以及相关数据(数据保留小数点后1位)。

输出球员获得DPOY的获奖年,以及相关数据(数据保留小数点后1位)。

IO模式

本题IO模式为标准输入/输出(Standard IO),你需要从标准输入流中读入数据,并将答案输出至标准输出流中。

样例

输入:

Michael 198 96
25.2 5.2 4.2 1.3 1.4
22.2 12.6 6.2 2.5 1.2
24.4 6.4 7.8 2.6 0.5
22.7 10.8 5.2 2.7 0.8
26.6 8.1 6.2 2.4 0.9
28.8 9.5 5.8 1.2 1.6
24.2 12.3 10.5 2.7 1.8
25.2 10.9 7.1 1.4 2.4
22.4 5.6 4.0 1.9 1.2
23.8 13.0 4.8 2.1 0.6
28.9 10.7 8.6 0.5 1.7
26.2 5.9 6.1 1.2 2.1

输出:

球员姓名:Michael 身高:198 体重:96
MVP年份:2014 得分:26.6 篮板:8.1 助攻:6.2
MVP年份:2017 得分:25.2 篮板:10.9 助攻:7.1
MVP年份:2020 得分:28.9 篮板:10.7 助攻:8.6
DPOY年份:2016 盖帽:2.7 篮板:12.3 抢断:1.8

AC代码:

#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

class Player {
	protected:
		char name[20];
		float height, weight;
	public:
		Player() {
		}
		Player(char *n, float h, float w) {
			strcpy(name, n);
			height = h;
			weight = w;
		}
		void print() {
			cout << "球员姓名:" << name << " 身高:" << height << " 体重:" << weight << endl;
		}
};

class MVP: public Player {
	protected:
		int year;
		float score, lb, zg;
	public:
		MVP() {}
		MVP(int y, float s, float l, float z) {
			year = y;
			score = s;
			lb = l;
			zg = z;
		}
		int win() {
			if (score > 25 && lb > 6 && zg > 6) {
				return 1;
			} else {
				return 0;
			}
		}
		void print() {
			cout << "MVP年份:" << year << fixed << setprecision(1) << " 得分:" << score << " 篮板:" << lb << " 助攻:" << zg << endl;
		}
};

class DPOY: public Player {
	protected:
		int year;
		float lb, qd, gm;
	public:
		DPOY() {
		}
		DPOY(int y, float l, float q, float g) {
			year = y;
			lb = l;
			qd = q;
			gm = g;
		}
		int win() {
			if (lb > 12 && gm > 2.5 && qd > 1.5) {
				return 1;
			} else {
				return 0;
			}
		}
		void print() {
			cout << "DPOY年份:" << year << fixed << setprecision(1) << " 盖帽:" << gm << " 篮板:" << lb << " 抢断:" << qd << endl;
		}
};

int main() {
	int year;
	int i = 0;
	float w, h, score, lb, zg, gm, qd;
	char name[20];
	cin >> name >> h >> w;
	Player a(name, h, w);
	MVP *p[12];
	DPOY *q[12];
	year = 2010;
	for (i = 0; i < 12; i++) {
		cin >> score >> lb >> zg >> gm >> qd;
		p[i] = new MVP(year, score, lb, zg);
		q[i] = new DPOY(year, lb, qd, gm);
		year++;
	}
	a.print();
	for (i = 0; i < 12; i++) {
		if (p[i]->win()) {
			p[i]->print();
		}
	}
	for (i = 0; i < 12; i++) {
		if (q[i]->win()) {
			q[i]->print();
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shiroha Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值