C++ implements k-means algorithm