A miniature robot designed to mimic thebehavior of an ant is being tested to evaluatethe robot’s ability to avoid a chemicalrepellant (the robot has a chemical sensor,and a control loop that makes the robotavoid moving in a direction that will resultin the sensor detecting a chemicalconcentration above a certain limit). The xand y positions of the robot are measuredwith time, and the resulting data is saved toa file called data.txt which contains 3columns: the time of the measurement (in seconds), the x position (in cm), and the y position (in cm).The first line of the file is a “header”: it has a single integer that specifies how many lines of data follow.Write a C++ program called ant.cpp that reads files of this type (i.e., your program should workwith another, but similar, file!) and then does the following: it asks for an X and Y position, and thenprints to screen the time at which the ant robot was closest to this position. For example, if we wishto know when the robot is closest to x = 200cm and y = 400cm (the red dot shown in the plot), yourprogram should produce:Enter x & y position: 200 400The smallest distance is 54.7068 cm, which occurs at 67.2 seconds.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here