想要输出""的话:

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]

#include<iostream>
using namespace std;
class Person{
public:
char* name;
int age;
Person():name("no name"),age(){cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is created!"<<endl;}
Person(char* n,int a):name(n),age(a){cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is created!"<<endl;}
Person(const Person& p){name=p.name;age=p.age;cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is cloned!"<<endl;}
~Person(){cout<<"A person whose name is \""<<name<<"\" and age is "<<age<<" is erased!"<<endl;} void showPerson(){cout<<"This person is \""<<name<<"\" whose age is "<<age<<"."<<endl;}
Person& setName(char* n){name=n;return *this;}
Person& setAge(int a){age=a;return *this;}
}; int main()
{
int cases;
char str[];
int age; Person noname, Tom("Tom", ), anotherTom(Tom);
cin>>cases;
for (int ca = ; ca < cases; ca++)
{
cin>>str>>age;
Person newPerson(str, age);
newPerson.showPerson();
}
anotherTom.setName(str).setAge();
anotherTom.showPerson();
noname.showPerson();
return ;
}

实验9:Problem G: 克隆人来了!的更多相关文章

  1. 实验12:Problem G: 强悍的矩阵运算来了

    这个题目主要是乘法运算符的重载,卡了我好久,矩阵的乘法用3个嵌套的for循环进行,要分清楚矩阵的乘法结果是第一个矩阵的行,第二个矩阵的列所组成的矩阵. 重载+,*运算符时,可以在参数列表中传两个矩阵引 ...

  2. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem G: Check The Check(模拟国际象棋)

    Problem G: Check The Check Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 3[Submit][Statu ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  4. 【贪心+中位数】【新生赛3 1007题】 Problem G (K)

    Problem G Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  5. Problem G: If We Were a Child Again

    Problem G: If We Were a Child AgainTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 14[Submi ...

  6. Problem G: Keywords Search

    Problem G: Keywords SearchTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 10 Solved: 6[Submit][Status] ...

  7. BZOJ4977 八月月赛 Problem G 跳伞求生 set 贪心

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4977 - 八月月赛 Problem G 题意 小明组建了一支由n名玩家组成的战队,编号依次为1到n ...

  8. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp

    Problem G. k-palindrome 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022 ...

  9. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

随机推荐

  1. Deep learning:五十(Deconvolution Network简单理解)

    深度网络结构是由多个单层网络叠加而成的,而常见的单层网络按照编码解码情况可以分为下面3类: 既有encoder部分也有decoder部分:比如常见的RBM系列(由RBM可构成的DBM, DBN等),a ...

  2. Anliven - 有效阅读的方法

    讲方法,忌盲目. 阅读方法 做好眼前事 排除其他事项干扰,营造适合阅读的状态和环境,专注地投入阅读之中. 如果被一堆乱糟糟的事情烦扰,身心处于一个疲惫的状态,必然无法保持专注的阅读. 定性定量 每个人 ...

  3. Design Pattern: Not Just Mixin Pattern

    Brief 从Mix-In模式到Mixin模式,中文常用翻译为“混入/织入模式”.单纯从名字上看不到多少端倪,而通过采用Mixin模式的jQuery.extend我们是否可以认为Mixin模式就是深拷 ...

  4. CSS魔法堂:再次认识font

    一.前言 文字承载着站点内涵,而良好的字体.排版则为用户提供舒适的阅读体验.本文打算对字体稍微深入一下子网页字体的内容,若有纰漏请大家指正,谢谢! 目录一坨: 二, 字体分类 1. 衬线体(Serif ...

  5. qml基础学习 模型视图(一)

    一.理解qml模型和视图 qt的发展是迅速的,虽然在每一个release版本中或多或少都有bug,但是作为一个庞大的gui库,no,应该说是一个开发框架开说,qt已经算是做的相当好.qml部分是qt4 ...

  6. LeetCode - 52. N-Queens II

    52. N-Queens II Problem's Link --------------------------------------------------------------------- ...

  7. 【转】万网域名查询接口(API)的说明

    1.域名查询接口采用HTTP,POST,GET协议:调用URL:http://panda.www.net.cn/cgi-bin/check.cgi参数名称:area_domain 值为标准域名,例:h ...

  8. linux下的C语言开发

    在很多人的眼里,C语言和linux常常是分不开的.这其中的原因很多,其中最重要的一部分我认为是linux本身就是C语言的杰出作品.当然,linux操作系统本身对C语言的支持也是相当到位的.作为一个真正 ...

  9. datatable删除行

    先列出正确的写法,如果你只想马上改错就先复制吧, protected void deleteDataRow(int RowID,DataTable dt) { ; i >= ; i--) { i ...

  10. Asp.net Mvc模块化开发系列(目录)

    模块化开发是非常重要的,模块化开发是个系统性问题,为此我觉得有必须要写一个系列的文章才能基本说的清楚 那又为什么要写一个目录呢? 其一.是对我昨天承诺写一个系列新的文章的回应 其二.是先写出一个大纲, ...