经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库运维 » Oracle » 查看文章
实验9:Problem G: 克隆人来了!
来源:cnblogs  作者:一一一匹马赛克儿  时间:2018/9/25 20:04:36  对本文有异议

想要输出""的话:

  1. cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is created!"<<endl;
Home Web Board ProblemSet Standing Status Statistics
 
Problem G: 克隆人来了!

Problem G: 克隆人来了!

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 448  Solved: 263
[Submit][Status][Web Board]

Description

克隆技术飞速发展,克隆人已经成为现实了!!所以,现在由你来编写一个Person类,来模拟其中的克隆过程。这个类具有2个属性:name——姓名(char*类型),和age——年龄(int类型)。

该类具有无参构造函数(人名为“no name”,年龄是0)、带参数构造函数、拷贝构造函数以及析构函数外,还有以下3个成员函数:

1. void Person::showPerson():按照指定格式显示人的信息。

2. Person& Person::setName(char *):设定人的姓名。

3. Person& Person::setAge(int):设定人的年龄。

 

Input

输入分多行,第一行是一个正整数N,表示其后有N行输入。每行分两部分:第一部分是一个没有空白符的字符串,表示一个人的姓名;第二部分是一个正整数,表示人的年龄。

 

Output

呃~比较复杂,见样例吧!注意:要根据样例编写相应函数中的输出语句,注意格式哦!

 

Sample Input

3 Zhang 20 Li 18 Zhao 99

Sample Output

A person whose name is "no name" and age is 0 is created! A person whose name is "Tom" and age is 16 is created! A person whose name is "Tom" and age is 16 is cloned! A person whose name is "Zhang" and age is 20 is created! This person is "Zhang" whose age is 20. A person whose name is "Zhang" and age is 20 is erased! A person whose name is "Li" and age is 18 is created! This person is "Li" whose age is 18. A person whose name is "Li" and age is 18 is erased! A person whose name is "Zhao" and age is 99 is created! This person is "Zhao" whose age is 99. A person whose name is "Zhao" and age is 99 is erased! This person is "Zhao" whose age is 18. This person is "no name" whose age is 0. A person whose name is "Zhao" and age is 18 is erased! A person whose name is "Tom" and age is 16 is erased! A person whose name is "no name" and age is 0 is erased!

HINT

注意:输出中有“”!

 

 

Append Code

[Submit][Status][Web Board]
  1. #include<iostream>
  2. using namespace std;
  3. class Person{
  4. public:
  5. char* name;
  6. int age;
  7. Person():name("no name"),age(0){cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is created!"<<endl;}
  8. Person(char* n,int a):name(n),age(a){cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is created!"<<endl;}
  9. Person(const Person& p){name=p.name;age=p.age;cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is cloned!"<<endl;}
  10. ~Person(){cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is erased!"<<endl;}
  11. void showPerson(){cout<<"This person is \""<<name<<"\" whose age is "<<age<<"."<<endl;}
  12. Person& setName(char* n){name=n;return *this;}
  13. Person& setAge(int a){age=a;return *this;}
  14. };
  15. int main()
  16. {
  17. int cases;
  18. char str[80];
  19. int age;
  20. Person noname, Tom("Tom", 16), anotherTom(Tom);
  21. cin>>cases;
  22. for (int ca = 0; ca < cases; ca++)
  23. {
  24. cin>>str>>age;
  25. Person newPerson(str, age);
  26. newPerson.showPerson();
  27. }
  28. anotherTom.setName(str).setAge(18);
  29. anotherTom.showPerson();
  30. noname.showPerson();
  31. return 0;
  32. }

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号