Assignment Write a program that moves a forester unit and a desert corps 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 desert corps 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 Desert Corps Forester Desert Corps Forest 1.3 0.6 4 12 Desert 0.4 1.2 15 6 Hills 0.7 0.8 6 8 Others 1.0 0.8 8 6 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
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Assignment Write a program that moves a forester unit and a desert corps 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 desert corps 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 Desert Corps Forester Desert Corps Forest 1.3 0.6 4 12 Desert 0.4 1.2 15 6 Hills 0.7 0.8 6 8 Others 1.0 0.8 8 6 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 desert corps 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). 0 0 20 10 70 44 10 70 44 Input 0 0 25 60 432 60 432 0 100 forest 80 24 desert 80 24 hills Forester walked for Forester walked for Forester walked for 104.308 hours 174.22 hours 77.2688 hours Desert Corps walked Desert Corps walked Desert Corps walked for 232 hours for 17.6777 hours for 34.5165 hours Unit is at 0, 100 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 Output
Step by step
Solved in 4 steps with 2 images