Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3 C c l p trong ch ng tr nh B i t p l n n y s d ng L p tr nh
Cc lp trong chng trnh
Bi tp ln ny s dng Lp trnh Hng i tng m t qu trnh m Sherlock v Watson
truy bt tn ti phm Cc i tng trong BTL c biu din thng qua class vc m
t nh bn di
Thnh phn ca bn
M cung m Sherlock, Watson ui bt tn ti phm c biu din bi mt bn c kch
thc l Bn ny l mt mng chiu c kch thc hng v ct Mi phn
t ca bn c biu din bng class MapElement. Bn c loi phn t:
Path: biu din li i cc i tng c th di chuyn trn phn t ny
Wall: biu din bc tng cc i tng khng c di chuyn trn phn t ny
FakeWall: biu din mt bc tng gi tn ti phm v l ngi to ra m cung nn
nhn bit c tng gi cn Sherlock bng kh nng quan st ca mnh th c th pht
hin c tng gi nyi vi Watson, FakeWall s b pht hin v di chuyn qua
c nu Watson c EXP ln hn EXP yu cu ca FakeWall. Tt c cc i tng di
chuyn khc u khng th di chuyn trn phn t ny
Bn cnh cc i tng chc di chuyn bn trong bn
Cho trc nh ngha ca enum ElementType nh sau:
enum ElementType PATH, WALL, FAKEWALL ;
Yu cu: Hin thc lp tru tng abstract class MapElement vi cc m t sau:
Thuc tnh protected tn type c kiu l ElementType biu din kiu ca thnh phn
bn
Phng thc khi to public c tham s truyn vo kiu ElementType. Phng thc
khi to gn gi tr ca tham s cho thuc tnh type.
MapElement ElementType intype;
Phng thc hy o virtual destructor vi quyn truy cp public.
Phng thc getType publicc nh ngha bn trong class nh bn di:
virtual ElementType getType const; TRNG HC BCH KHOA DHQGHCM
KHOA KHOA HC V K THUT MY TNH
Yu cu: Hin thc cc lp c thconcrete class Path, Wall, FakeWall k tha
class MapElement vi m t sau:
Class FakeWall c thuc tnh private tn reqexp biu din EXP ti thiu m Watson
cn c pht hin ra bc tng
Mi class c cc phng thc khi to publicc khai bo nh bn di Phn hin hin
thc ca mi phng thc khi to cn gi phng thc khi to ca class MapElement
v gn cc gi tr ph hp Class FakeWall cn cn gn gi tr ca inreqexp cho
reqexp. Class FakeWall c phng thc getReqExp tr v gi tr ca thuc tnh
reqexp. inreqexp c tnh bng vi v ln
lt l v tr theo hng v ct ca FakeWall.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started