Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <kickstart/all.hpp> // https://github.com/alf-p-steinbach/kickstart/
- using namespace kickstart::all; // input, to_vector_, split_on_whitespace, out, endl
- #include <unordered_map>
- using std::unordered_map;
- void cppmain()
- {
- using Op = function<auto( double, double ) -> double>;
- const unordered_map<string_view, Op> ops =
- {
- { "+", std::plus() }, { "-", std::minus() },
- { "*", std::multiplies() }, { "/", std::divides() }
- };
- const string op_symbol = input( "Enter an operator: " );
- const Op op = ops.at( op_symbol );
- const string number_specs = input( "Enter two numbers: " );
- const auto numbers = to_vector_<double>( split_on_whitespace( number_specs ) );
- const auto [a, b] = array{numbers.at( 0 ), numbers.at( 1 )};
- out << a << " " << op_symbol << " " << b << " = " << op( a, b ) << "." << endl;
- }
- auto main() -> int { return with_exceptions_displayed( cppmain ); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement