#include #include #include #include #include #include #include #include #include int main(int argc, char** argv) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " FILE" << std::endl; return 1; } std::ifstream ifs { argv[1] }; if (!ifs) { std::cerr << "Unable to open file: " << argv[1] << std::endl; return 2; } double dx { }; ifs >> dx; std::vector values { std::istream_iterator{ifs}, std::istream_iterator{} }; std::vector lengths { }; std::adjacent_difference(std::begin(values), std::end(values), std::back_inserter(lengths)); std::transform(std::begin(lengths), std::end(lengths), std::begin(lengths), [dx](double dy) { return std::sqrt(dx*dx + dy*dy); }); double length { std::accumulate(std::next(std::begin(lengths)), std::end(lengths), 0.0) }; std::cout << "The arc length is: " << length << std::endl; }