Question: Implement a class Moth that models a moth flying along the 1D x-axis. The moth has a position, the distance from a fixed origin. When





Implement a class Moth that models a moth flying along the 1D x-axis. The moth has a position, the distance from a fixed origin. When the moth moves toward a point of light, its new position is halfway between its old position and the position of the light source. (If the light position and the moth's current position are the same, then it doesn't move.) Provide a constructor . Moth (double initial_position) and member functions . void move_to_light (double light_position) . double get_position () const Here are some instructions of this problem: 1. In Bruinlearn "Files/Homework/homework_7", We have provided the starter code moth. h and moth. cpp. We also provided moth main. cpp, which contains the main function and testers. 2. In moth. h, you will provide the class definition 3. In moth. cpp, you will provide the implementations of the member functions. 4. Do NOT modify the file moth main. cpp, but you will run this file and it will test your implementation. When you have filled in the files moth. h and moth. cpp, you should run moth main . cpp. Once you see the following output, you have passed all the tests. === Test case 1 ==== Passed === Test case 2 ==== Passed ==== Test case 3 === = Passed. === Test case 4 ==== Passed. === Test case 5 ==== Passed. Hooray, you passed all tests!// Do not edit this file. #include "moth.h" #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
