一个俱乐部需要保存它的简要信息,包括四项:名称(字符串),成立年份(整数),教练姓名(字符串)和教练胜率(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%
实现代码如下:
void Coach::show() { cout<<name<<" "<<winRate<<"%"; } Club::Club(string n1, int y, string n2, int wr):c(n2,wr) { year=y; name=n1; } void Club::show() { cout<<name<<" "<<year<<endl; c.show(); }