Representing destinations in a square
Tell your instructor to become familiar with the Standard Guidelines.  You can find presentations on youtube where Stroustrup introduces this as a keynote speech, and many others speaking on them since.



Don’t use naked new (and delete).  Make your vector of unique_ptr instead.

The srand48 is not a standard function.  And the old C rand/srand are infamous for poor quality random numbers.  See the &lt;random&gt; header file.

Why does one location use 0. (funny way to write 0.0, a double) and the other use 1 as an int?

You don’t need to put private: at the top of the class; that is assumed.

Does visit modify the object? You did not make it const.  Also, use the override keyword in the derived version!  That is very important in real code for maintainability as well as error checking.

for(int j=0; j&lt;10; j++)  v.push_back(Location());


Did you know that vector elements are always initialized? And what will it use do you suppose?  The default constructor of the element, of course!

So just write:  v.resize(10+v.size())  to add 10 default locations to the end.

Location a(0.1, 0.1);


Use uniform initialization syntax.

Location a{0.1, 0.1};


Thou hast scribed an olde dialect.  You’re using the ranged for loop so your textbook must be written after 2011; perhaps it is just a slightly updated lesson plan from 1998?



Location() {
    x_ = drand48();
    y_ = drand48();
}


A random-initialized location might be handy for this specific program, but it’s sufficiently bizzare that it hinders the understanding of the code.  Make a function to return a random location instead!



double getx() {return x_; }
bool operator&lt;(const Location &amp; L) { return x_ &lt; L.x_; }


You are definitly missing const on your member functions.

Writing good relational operators is a whole lesson and not the point here — this is probably fine for the class as it stands, but reviewers will wonder why you didn’t make it a non-member and supply all the relational and equality operators.

Since the (partial) ordering exists specifically for your algorithm, you might want to make it a named function instead. Consider the future maintainer that writes a test using &gt; and then has to figure out why it didn’t compile, and of course documenting that less means East and is not a complete ordering.



double distance(const Location &amp; L) {
    return std::sqrt(std::pow(x_ - L.x_, 2) + std::pow(y_ - L.y_, 2));


Besides being const, just call std::hypot.  It will be faster and more accurate.



Salesman(const Location &amp; start, std::vector&lt;Location&gt;::iterator it1, std::vector&lt;Location&gt;::iterator it2) 
: start_(start), tobevisited_(it1, it2) 
{ }


Very interesting that you allow salesman to be initialized with a segment of a larger vector.  Is that a use case you anticipate (e.g. a huge list divided up among several salesmen)?

It’s enlightened but only part way to what we expect: it is limited to segments of another vector, and can’t take begin/end iterators to locations in general (anything that can be iterated).

Also, you should be using the const_iterator.

Here is the simple/direct way to take that information in the constructor.

      ⋮
    Location start_;
    std::vector&lt;Location&gt; tobevisited_;
public:
    Salesman (start, std::vector&lt;Location&gt; locations) 
      : start_{start}, tobevisited_{std::move(locations)} 
      { }




Get a post-it note and write using a fat marker, “Can it be const?”. Stick that on the edge of your monitor.