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 the1D x-axis. The moth has a position, the distance from a fixedorigin. When the moth moves toward a point of light, its newposition is halfway between its old position and the position of thelight source. (If the light position and the moth's current position are

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 #include using namespace std; class Tester { public: // Checks answer and prints success or failed bool test (double got, double expected) ; private: size_t test_num = 1; double thresh = 1.0 / 1024.0; bool Tester: : test (double got, double expected) { cout = thresh) { cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!