Answered step by step
Verified Expert Solution
Link Copied!

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

3 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.
3.1 Thnh phn ca bn
M cung m Sherlock, Watson ui bt tn ti phm c biu din bi mt bn c kch
thc l(nr,nc). Bn ny l mt mng 2 chiu c kch thc nr hng vnc ct. Mi phn
t ca bn c biu din bng class MapElement. Bn c2 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 ny.i 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:
?1 enum ElementType { PATH, WALL, FAKE_WALL };
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) c1 tham s truyn vo kiu ElementType. Phng thc
khi to gn gi tr ca tham s cho thuc tnh type.
MapElement (ElementType in_type);
Phng thc hy o (virtual destructor) vi quyn truy cp public.
Phng thc getType (public)c nh ngha bn trong class nh bn di:
?1 virtual ElementType getType() const; TRNG HC BCH KHOA - DHQG-HCM
KHOA KHOA HC V K THUT MY TNH
Yu cu: Hin thc cc lp c th(concrete class) Path, Wall, FakeWall k tha
class MapElement vi m t sau:
Class FakeWall c thuc tnh private tn req_exp biu din EXP ti thiu m Watson
cn c pht hin ra bc tng.
Mi class c cc phng thc khi to (public)c 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 in_req_exp cho
req_exp. Class FakeWall c phng thc getReqExp tr v gi tr ca thuc tnh
req_exp. in_req_exp c tnh bng (r**257+c**139+89)%900+1 vi r vc ln
lt l v tr theo hng v ct ca FakeWall.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Design test cases for testing a search engine such as Google.

Answered: 1 week ago