12 std::array v1 = { 1., 2., 3. };
13 std::array v2 = { -3., -9., 1. };
15 auto normalize = [](
auto v) {
17 double vnorm = std::inner_product(vcopy.begin(), vcopy.end(), vcopy.begin(), 0.0);
18 std::transform(vcopy.begin(), vcopy.end(), vcopy.begin(), [vnorm](
double x) {
24 auto print = [](
auto v) {
26 std::cout << x <<
"\t";
28 std::cout << std::endl;
31 auto v1n = normalize(v1);
32 auto v2n = normalize(v2);
34 std::cout << std::fixed << std::setprecision(2);
45 double x1, v1, s, vbar;
47 std::cout <<
"------------input-------------" << std::endl;
50 std::cout <<
"x0=?\t";
53 std::cout <<
"v0=?\t";
56 std::cout <<
"a =?\t";
59 std::cout <<
"t1=?\t";
62 x1 = x0 + v0 * t1 + 0.5 * a * pow(t1, 2);
67 std::cout << std::fixed << std::setprecision(2);
68 std::cout <<
"------------output-------" << std::endl;
69 std::cout <<
"t1 = " << t1 <<
"\t";
70 std::cout <<
"x1 = " << x1 <<
"\t";
71 std::cout <<
"v1 = " << v1 <<
"\t";
72 std::cout <<
"s = " << s <<
"\t";
73 std::cout <<
"vbar = " << vbar << std::endl;
76 std::cout <<
"continue? y[yes] / n[no]" << std::endl;
78 }
while (cmd !=
'y' && cmd !=
'n');
91 double read(
const char *label) {
93 std::cout << label <<
"=?\t";
96 if (std::cin.fail()) {
97 throw std::invalid_argument(label);
106 void write(std::initializer_list<ValuePair> lst) {
107 for (
auto &[label, val] : lst) {
108 std::cout << label << std::setw(6 - static_cast<int>(label.size())) <<
"=" << val
115 double x0, v0, a, t1;
116 double x1, v1, s, vbar;
126 throw std::domain_error(
"time must be >0");
129 x1 = x0 + v0 * t1 + 0.5 * a * pow(t1, 2);
134 std::cout << std::fixed << std::setprecision(2);
135 std::cout <<
"------------output-------" << std::endl;
136 write({ {
"t1", t1 },
146 constexpr
auto maxstreamsize = std::numeric_limits<std::streamsize>::max();
147 std::cout <<
"------------input-------------" << std::endl;
151 }
catch (std::domain_error
ex1) {
154 std::cin.ignore(maxstreamsize,
'\n');
155 std::cerr <<
"input error:" << ex1.what() << std::endl;
156 }
catch (std::invalid_argument
ex2) {
159 std::cin.ignore(maxstreamsize,
'\n');
160 std::cerr <<
"input error for:" << ex2.what() << std::endl;
164 std::cout <<
"new claculation? y[yes] / n[no]" << std::endl;
166 }
while (cmd !=
'y' && cmd !=
'n');
void ex2()
ex2 ex3 Geradlinige Bewegung mit konstanter Beschleunigung, Version 1.0
std::pair< std::string, double > ValuePair
void write(std::initializer_list< ValuePair > lst)
double read(const char *label)