6-1 体育俱乐部I(构造函数) (5 分)
一个俱乐部需要保存它的简要信息,包括四项:名称(字符串),成立年份(整数),教练姓名(字符串)和教练胜率(0-100之间的整数)。用键盘输入这些信息后,把它们分两行输出:第一行输出名称和成立年份,第二行输出教练姓名和胜率。
裁判测试程序样例:
#include <iostream>#include <string>using namespace std;class Coach{ string name; int winRate;public: Coach(string n, int wr){ name=n; winRate=wr; } void show(); };class Club{ string name; Coach c; int year;public: Club(string n1, int y, string n2, int wr); void show(); };int main(){ string n1, n2; int year, winRate; cin>>n1>>year>>n2>>winRate; Club c(n1,year, n2, winRate); c.show(); return 0; }/* 请在这里填写答案 */
输入样例:
Guanzhou 2006 Tom 92
输出样例:
Guanzhou 2006 Tom 92%
作者
何振峰
单位
福州大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
void Coach::show() { cout<<name<<" "<<winRate<<"%"<<endl; } Club::Club(string n1,int y,string n2,int wr):c(n2,wr) { name=n1; year=y; } void Club::show() { cout<<name<<" "<<year<<endl; c.show(); }