Problem C 複製人來了!

2022-04-02 13:43:07 字數 2183 閱讀 5056

轉殖技術飛速發展,複製人已經成為現實了!!所以,現在由你來編寫乙個person類,來模擬其中的轉殖過程。這個類具有2個屬性:name——姓名(char*型別),和age——年齡(int型別)。

該類具有無參建構函式(人名為「no name」,年齡是0)、帶引數建構函式、拷貝建構函式以及析構函式外,還有以下3個成員函式:

1. void person::showperson():按照指定格式顯示人的資訊。

2. person& person::setname(char *):設定人的姓名。

3. person& person::setage(int):設定人的年齡。

輸入分多行,第一行是乙個正整數n,表示其後有n行輸入。每行分兩部分:第一部分是乙個沒有空白符的字串,表示乙個人的姓名;第二部分是乙個正整數,表示人的年齡。

呃~比較複雜,見樣例吧!注意:要根據樣例編寫相應函式中的輸出語句,注意格式哦!

3zhang 20

li 18

zhao 99

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!

注意:輸出中有「」!

#include

#include

usingnamespacestd;

classperson

person& setage(inta)

person(constperson &tom);

intmain()

anothertom.setname(str).setage(18);

anothertom.showperson();

noname.showperson();

return0;

}

複製人來了!

description 轉殖技術飛速發展,複製人已經成為現實了!所以,現在由你來編寫乙個person類,來模擬其中的轉殖過程。這個類具有2個屬性 name 姓名 char 型別 和age 年齡 int型別 該類具有無參建構函式 人名為 no name 年齡是0 帶引數建構函式 拷貝建構函式以及析構函...

Problem A 複製人來了!

home web board problemset standing status statistics time limit 1 sec memory limit 128 mb submit 1979 solved 1072 submit status web board 轉殖技術飛速發展,複製人...

Problem A 複製人來了!

time limit 1 sec memory limit 128 mb submit 3298 solved 1788 submit status web board 轉殖技術飛速發展,複製人已經成為現實了!所以,現在由你來編寫乙個person類,來模擬其中的轉殖過程。這個類具有2個屬性 name...