#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>

// Read one whole line so a failed conversion cannot trap the input stream.
bool readNumber(const std::string& prompt, double& value, double low, double high) {
    std::string line;
    while (std::cout << prompt && std::getline(std::cin, line)) {
        std::istringstream input(line);
        char extra = '\0';
        if (input >> value && !(input >> extra) && std::isfinite(value)
            && value >= low && value <= high) {
            return true;
        }
        std::cout << "Enter a finite number in [" << low << ", " << high << "].\n";
    }
    std::cerr << "Input ended before a valid number was supplied.\n";
    return false;
}

double lengthChange(double alphaPerKelvin, double lengthM, double temperatureChangeC) {
    return alphaPerKelvin * lengthM * temperatureChangeC;
}

int main() {
    double lengthM = 0.0, initialTempC = 0.0, alphaPerKelvin = 0.0, allowanceM = 0.0;
    if (!readNumber("Initial length (m): ", lengthM, 1e-6, 1e6)
        || !readNumber("Initial temperature (C): ", initialTempC, -200.0, 200.0)
        || !readNumber("Linear coefficient (1/K): ", alphaPerKelvin, 0.0, 1e-3)
        || !readNumber("Illustrative movement allowance (m): ", allowanceM, 0.0, 1e3)) return 1;
    std::cout << "Teaching model: marker compares absolute movement with an illustrative allowance.\n"
              << "final_C final_m change_m marker\n" << std::fixed << std::setprecision(6);
    for (int finalTempC = 0; finalTempC <= 40; ++finalTempC) {
        const double changeM = lengthChange(alphaPerKelvin, lengthM, finalTempC - initialTempC);
        const char marker = std::abs(changeM) > allowanceM ? '*' : '-';
        std::cout << finalTempC << ' ' << lengthM + changeM << ' ' << changeM << ' ' << marker << '\n';
    }
}
