#include #include #include #include #include #include std::tuple read_from_file(std::string filename); std::tuple read_from_file_term(std::string filename); std::tuple normalize(std::tuple values); std::tuple normalize_term(std::tuple values); int main(int argc, char *argv[]) { if (argc != 2) { std::cerr << "Forneca o nome do arquivo de dados.\n"; return 1; } auto values = read_from_file_term(argv[1]); auto [na, nb, nc] = normalize_term(values); std::cout << "Normalized values: " << na << ", " << nb << ", " << nc << std::endl; return 0; } std::tuple read_from_file(std::string filename) { std::ifstream file(filename); int a, b, c; file >> a >> b >> c; return {a, b, c}; } std::tuple read_from_file_term(std::string filename) { std::ifstream file(filename); if (!file.good()) { std::cerr << "Impossivel acessar arquivo.\n"; std::exit(2); } int a, b, c; file >> a >> b >> c; if (file.fail()) { std::cerr << "Erro lendo os dados do arquivo.\n"; std::exit(3); } return {a, b, c}; } std::tuple normalize(std::tuple values) { auto [a, b, c] = values; double m = a; if (b < a && c < a) { m = std::max(b, c); } else if (a < c && a < b) { m = std::min(b, c); } return {a/m, b/m, c/m}; } std::tuple normalize_term(std::tuple values) { auto [a, b, c] = values; double m = a; if (b < a && c < a) { m = std::max(b, c); } else if (a < c && a < b) { m = std::min(b, c); } if (m == 0) { std::cerr << "Erro: Divisao por zero.\n"; std::exit(4); } return {a/m, b/m, c/m}; }