Write a program that moves a forester unit and a mountaineer unit to a given target location and prints the number of hours it took for each unit to reach the target. First, the user will give the starting X and Y positions of the forester unit as well as its base speed (all ints). Then, the starting X and Y positions of the mountaineer unit as well as its base speed (all ints). Finally, the target X and Y positions (both ints) and the terrain type (std:string). Speeds are given as distance traveled in one full day (i.e., 24 hours) and is affected by the terrain type using a multiplier over the base speed. Also, after 1 full day, each unit rests for a certain number of hours. Speed multiplier and rest amount of each type of unit depending on the terrain type are as below.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question
100%

c++

Write a program that moves a forester unit and a mountaineer unit to a given target location and
prints the number of hours it took for each unit to reach the target.
First, the user will give the starting X and Y positions of the forester unit as well as its base speed (all
ints). Then, the starting X and Y positions of the mountaineer unit as well as its base speed (all ints).
Finally, the target X and Y positions (both ints) and the terrain type (std:string).
Speeds are given as distance traveled in one full day (i.e., 24 hours) and is affected by the terrain type
using a multiplier over the base speed. Also, after 1 full day, each unit rests for a certain number of
hours. Speed multiplier and rest amount of each type of unit depending on the terrain type are as
below.
Speed Multiplier
Rest Duration After 1 day
Terrain type
Forester
Mountaineer
Forester
Mountaineer
Forest
1.35
0.7
5
11
Mountain
0.75
1.4
10
5
Marsh
0.5
0.45
10
12
Others
0.85
1.0
8.
After getting all this information, the program will move both the units to the target by printing out
the total time (in hours) it took the units to reach their target and their final positions in the format
seen in the outputs.
Requirements:
• You should define a class for the unit, two CHILD classes of the unit class one for the
forester unit, another for the mountaineer unit.
• Coordinate information should be kept as private inside the unit class whereas the
speed information should be kept as protected inside the unit class.
• Classes should take the related input in their constructor functions.
• The base unit class MUST have a public function which prints out the current location of
the unit.
• The base unit class MUST have a protected function which moves the unit to a given
location.
• The base unit class MUST have a protected function which calculates the distance
between itself and a target location,
• Each child classes MUST have a public function which moves the unit to a target location
Transcribed Image Text:Write a program that moves a forester unit and a mountaineer unit to a given target location and prints the number of hours it took for each unit to reach the target. First, the user will give the starting X and Y positions of the forester unit as well as its base speed (all ints). Then, the starting X and Y positions of the mountaineer unit as well as its base speed (all ints). Finally, the target X and Y positions (both ints) and the terrain type (std:string). Speeds are given as distance traveled in one full day (i.e., 24 hours) and is affected by the terrain type using a multiplier over the base speed. Also, after 1 full day, each unit rests for a certain number of hours. Speed multiplier and rest amount of each type of unit depending on the terrain type are as below. Speed Multiplier Rest Duration After 1 day Terrain type Forester Mountaineer Forester Mountaineer Forest 1.35 0.7 5 11 Mountain 0.75 1.4 10 5 Marsh 0.5 0.45 10 12 Others 0.85 1.0 8. After getting all this information, the program will move both the units to the target by printing out the total time (in hours) it took the units to reach their target and their final positions in the format seen in the outputs. Requirements: • You should define a class for the unit, two CHILD classes of the unit class one for the forester unit, another for the mountaineer unit. • Coordinate information should be kept as private inside the unit class whereas the speed information should be kept as protected inside the unit class. • Classes should take the related input in their constructor functions. • The base unit class MUST have a public function which prints out the current location of the unit. • The base unit class MUST have a protected function which moves the unit to a given location. • The base unit class MUST have a protected function which calculates the distance between itself and a target location, • Each child classes MUST have a public function which moves the unit to a target location
the total time (in hours) it took the units to reach their target and their final positions in the format
seen in the outputs.
Requirements:
• You should define a class for the unit, two CHILD classes of the unit class one for the
forester unit, another for the mountaineer unit.
• Coordinate information should be kept as private inside the unit class whereas the
speed information should be kept as protected inside the unit class.
• Classes should take the related input in their constructor functions.
• The base unit class MUST have a public function which prints out the current location of
the unit.
• The base unit class MUST have a protected function which moves the unit to a given
location.
• The base unit class MUST have a protected function which calculates the distance
between itself and a target location.
• Each child classes MUST have a public function which moves the unit to a target location
given the terrain type, calculates the total amount of hours it took the unit to reach to the
target, and print it out.
• Getting all the user input, instantiating objects, calling the move functions of the child
classes should be done in the main() function.
• Do NOT use polymorphism in this question (i.e., do NOT overload the move function of
the base class).
00 20
10 70 44
10 70 44
Input
00 25
60 4 32
60 4 32
0 100 forest
80 24 marsh
80 24 mountain
Forester walked
for 103.889
Forester walked for
121.376 hours
Forester walked for
80.9175 hours
hours
Mountaineer
walked for 59.1405
Mountaineer
walked for
192.143 hours
Mountaineer walked for
15.1523 hours
Output
hours
Unit is at 80, 24
Unit is at 80, 24
Unit is at 0, 100
Unit is at 80, 24
Unit is at 80, 24
Unit is at 0, 100
Transcribed Image Text:the total time (in hours) it took the units to reach their target and their final positions in the format seen in the outputs. Requirements: • You should define a class for the unit, two CHILD classes of the unit class one for the forester unit, another for the mountaineer unit. • Coordinate information should be kept as private inside the unit class whereas the speed information should be kept as protected inside the unit class. • Classes should take the related input in their constructor functions. • The base unit class MUST have a public function which prints out the current location of the unit. • The base unit class MUST have a protected function which moves the unit to a given location. • The base unit class MUST have a protected function which calculates the distance between itself and a target location. • Each child classes MUST have a public function which moves the unit to a target location given the terrain type, calculates the total amount of hours it took the unit to reach to the target, and print it out. • Getting all the user input, instantiating objects, calling the move functions of the child classes should be done in the main() function. • Do NOT use polymorphism in this question (i.e., do NOT overload the move function of the base class). 00 20 10 70 44 10 70 44 Input 00 25 60 4 32 60 4 32 0 100 forest 80 24 marsh 80 24 mountain Forester walked for 103.889 Forester walked for 121.376 hours Forester walked for 80.9175 hours hours Mountaineer walked for 59.1405 Mountaineer walked for 192.143 hours Mountaineer walked for 15.1523 hours Output hours Unit is at 80, 24 Unit is at 80, 24 Unit is at 0, 100 Unit is at 80, 24 Unit is at 80, 24 Unit is at 0, 100
Expert Solution
steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning