/** roomba4.cpp 26-feb-2007/sklar this program expands on roomba3.cpp by calculating the distance the roomba needs to travel from its randomly selected initial location to its home location (0,0). */ // section 1: include C++ library definitions #include #include #include #include using namespace std; // section 2: declare variables int x; // robot's x position int y; // robot's y position // section 3: declare methods int display() { cout << "the roomba is at location ("; cout << x; cout << ","; cout << y; cout << ")\n"; return 0; } // end of display() // section 4: define main method int main() { double d; // initialize random seed srand( time( NULL )); // find random initial location x = rand() % 10; y = rand() % 10; display(); // compute distance to "home" (0,0) // euclidean distance d = sqrt( (double)( x*x + y*y )); cout << "Euclidean distance to home is: " << d << endl; // manhattan distance d = x + y; cout << "Manhttan distance to home is: " << d << endl; // double f = sqrt( 4.0 ); double f = sqrt( (double)4 ); cout << "f = " << f << endl; } // end of main()