16 using Value = std::pair<std::string, double>;
19 enum Idx { x0, v0, a, time };
23 std::vector<Value> _in;
25 std::vector<Value> _out;
33 double read(std::string &label) {
35 std::cout << label <<
"=?\t";
38 if (std::cin.fail()) {
39 throw std::invalid_argument(label);
50 for (
const auto label : {
"x0",
"v0",
"a",
"t1" }) {
51 _in.push_back(Value{ label, 0 });
54 for (
const auto &label : {
"x",
"v",
"s",
"vbar" }) {
55 _out.push_back(Value{ label, 0 });
64 x022::Motion motion{ 1, _in[Idx::a].second, { _in[Idx::x0].second, _in[Idx::v0].second } };
66 double t1 = _in[Idx::time].second;
67 _out[0].second = motion.
x(t1);
68 _out[1].second = motion.v(t1);
69 _out[2].second = motion.distance(t1);
70 _out[3].second = motion.vmean(t1);
77 for (
auto &vals : _in) {
78 vals.second =
read(vals.first);
81 if (_in.back().second <= 0) {
82 throw std::domain_error(
"time must be >0");
90 std::cout << std::fixed << std::setprecision(2);
91 std::cout <<
"------------output-------" << std::endl;
93 for (
const auto &[label, val] : _out) {
95 <<
"=" << val << std::setw(3) <<
"\t";
97 std::cout << std::endl;
104 constexpr
auto maxstreamsize = std::numeric_limits<std::streamsize>::max();
110 }
catch (std::domain_error
ex1) {
116 std::cin.ignore(maxstreamsize,
'\n');
117 std::cerr <<
"input error:" << ex1.what() << std::endl;
118 }
catch (std::invalid_argument
ex2) {
121 std::cin.ignore(maxstreamsize,
'\n');
122 std::cerr <<
"input error for:" << ex2.what() << std::endl;
131 std::cout <<
"------------input-------------" << std::endl;
135 std::cout <<
"new calculation? y[yes] / n[no]" << std::endl;
137 }
while (cmd !=
'y' && cmd !=
'n');
The Motion class Geradlinige Bewegung mit konstanter Beschleunigung.
void ex1()
ex1 Beispielprogramm Geradlinige Bewegung mit konstanter Beschleunigung
double x(double t) const
x Ortsfunktion