A miniature robot designed to mimic the behavior of an ant is being tested to evaluate the robot’s ability to avoid a chemical repellant (the robot has a chemical sensor, and a control loop that makes...


A miniature robot designed to mimic the

behavior of an ant is being tested to evaluate

the robot’s ability to avoid a chemical

repellant (the robot has a chemical sensor,

and a control loop that makes the robot

avoid moving in a direction that will result

in the sensor detecting a chemical

concentration above a certain limit). The x

and y positions of the robot are measured

with time, and the resulting data is saved to

a file called data.txt which contains 3

columns: 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 work

with another, but similar, file!) and then does the following: it asks for an X and Y position, and then

prints to screen the time at which the ant robot was closest to this position. For example, if we wish

to know when the robot is closest to x = 200cm and y = 400cm (the red dot shown in the plot), your

program should produce:

Enter x & y position: 200 400

The smallest distance is 54.7068 cm, which occurs at 67.2 seconds.


900<br>800<br>700<br>600<br>500<br>> 400<br>300<br>200<br>100<br>50<br>100<br>150<br>200<br>250<br>300<br>350<br>x (cm)<br>(ua) A<br>

Extracted text: 900 800 700 600 500 > 400 300 200 100 50 100 150 200 250 300 350 x (cm) (ua) A

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here