回分類題庫
d289: 105OOP Lab Exercise: 多重繼承
出處:

Difficulity : N/A
Accepted : 49 Times | Submit :115 Times | Clicks : 484
Accepted : 47 Users | Submit : 48 Users | Accepted rate : 98%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2016-11-25 15:07

Content :

有一 Base Class 為 冒險者(Adventurer)

冒險者類別有三個 private members, 分別為姓名(string name),生命值(int hp),魔力值(int mp);另外應有 getName, getHP, setHP, getMP, setMP 五個 function

Derived Class: 

劍士(Swordsman)繼承冒險者類別,private members 為物理攻擊力(int atk)

魔法師(Enchanter)也繼承冒險者類別,private members 為魔法攻擊力(int magicAtk) 

魔法劍士(MagicSwordsman)繼承劍士及魔法師類別,private members 為魔法劍技能(magicBladeSkill)

Input :

第一行是魔法劍士的基本屬性,格式如下

例: John 100 5 20 80 70
第二行之後為指令,指令代號及內容如下
1: setHP,格式:1 hp,例如:1 100
2: setMP,格式:2 mp,例如:2 5
3: setATK,格式:3 atk,例如:3 20
4: setMagicATK,格式:4 magicATK,例如:4 80 
5: setMagicBladeSkill,格式:5 magicBladeSkill,例如 5 70
6: exit program

Output :

魔法劍士類別在建立時需依正確順序印出 Constructor,銷毀時,也需依正確順序印出 Destructor
執行任一行指令後,都要印出目前狀態再繼續下一個指令

Sample Input :

Norris 100 20 70 50 30
1 1000
2 2000
3 7000
4 5000
5 3000
6

Sample Output :

Constructor of Adventurer
Constructor of Swordsman
Constructor of Enchanter
Constructor of MagicSwordsman
==============MagicSwordsman==============
NAME = Norris
HP = 100
MP = 20
ATK = 70
MAGIC ATK = 50
MAGIC BLADE SKILL = 30
======================================
==============MagicSwordsman==============
NAME = Norris
HP = 1000
MP = 20
ATK = 70
MAGIC ATK = 50
MAGIC BLADE SKILL = 30
======================================
==============MagicSwordsman==============
NAME = Norris
HP = 1000
MP = 2000
ATK = 70
MAGIC ATK = 50
MAGIC BLADE SKILL = 30
======================================
==============MagicSwordsman==============
NAME = Norris
HP = 1000
MP = 2000
ATK = 7000
MAGIC ATK = 50
MAGIC BLADE SKILL = 30
======================================
==============MagicSwordsman==============
NAME = Norris
HP = 1000
MP = 2000
ATK = 7000
MAGIC ATK = 5000
MAGIC BLADE SKILL = 30
======================================
==============MagicSwordsman==============
NAME = Norris
HP = 1000
MP = 2000
ATK = 7000
MAGIC ATK = 5000
MAGIC BLADE SKILL = 3000
======================================
==============MagicSwordsman==============
NAME = Norris
HP = 1000
MP = 2000
ATK = 7000
MAGIC ATK = 5000
MAGIC BLADE SKILL = 3000
======================================
Destructor of MagicSwordsman
Destructor of Enchanter
Destructor of Swordsman
Destructor of Adventurer

Hint :

記得用虛擬繼承

Author :

(管理員:oopTA)

  Solve it!   Status Forum (0)

C++
C
JAVA
76392. oop102703035 (4 ms , 428KB)
76353. oop104703039 (4 ms , 424KB)
76331. oop104703009 (4 ms , 424KB)
76146. oop103304042 (4 ms , 428KB)
76648. oop104703015 (6 ms , 428KB)
沒有解題記錄 86358. nwgs524513cja (108 ms , 258KB)

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡