#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
double calculateExpression(double x) {
double result = 0;
result = (95 / 10) + 4 * (1 - 95 / cos(x - 95)) * (sin(x) / 95));
if (((sin(x) / 95) == 0 && (1 - 95 / cos(x - 95)) == 0 && cos(x - 95)) == 0 && (95 / 10) + 4 * (1 - 95 / cos(x - 95)) * (sin(x) / 95)) <= 0 ) {
std::string str = std::to_string(result);
std::cout << "Calculation error" << result << std::endl;
return result;
}
return result;
}
/*double calculateExpression(double x) {
double result = 0;
if (x != 95 && cos(x - 95) != 0) {
result = log(abs(95 / 10) + 4 * (1 - 95 / cos(x - 95))*(sin(x)/95));
}
else {
std::string str = std::to_string(result);
std::cout << "Calculation error" << result << std::endl;
}
return result;
}*/
double compareExpressions(double x1, double x2) {
double result = 0;
double expression1 = calculateExpression(x1);
double expression2 = calculateExpression(x2);
if (expression1 < expression2) {
result = expression1;
}
else {
result = expression2;
}
return result;
}
void printTable(double startX, double endX, double step) {
std::cout << std::right << std::string(10, ' ') << std::string(60, '-') << std::endl;
std::cout << std::right << std::setw(10) << "|" << " N " << std::right << std::setw(9) << " | " << std::right << std::setw(10) << std::right << std::setw(10)
<< " X " << std::right << std::setw(10) << " | " << std::right << std::setw(20) << " Expression " << std::right << std::setw(10) << " | " << std::endl;
std::cout << std::right << std::string(10, ' ') << std::string(60, '-') << std::endl;
int rowNum = 1;
double x = startX;
while (x <= endX) {
double expressionValue = calculateExpression(x);
std::cout << std::right << std::setw(10) << "|" << std::right << std::setw(3) << rowNum << std::right << std::setw(8) << "|" << std::right << std::setw(10)
<< std::setprecision(2) << x << std::right << std::setw(10) << "|" << std::right << std::setw(10) << std::setprecision(6) << expressionValue
<< std::right << std::setw(20) << "|" << std::endl;
rowNum++;
x += step;
std::cout << std::right << std::string(10, ' ') << std::string(60, '-') << std::endl;
}
}
int main() {
double startX = 0, endX = 0, step = 0;
std::cout << "Initial value for X: ";
std::cin >> startX;
std::cout << "Final value for X: ";
std::cin >> endX;
do {
std::cout << "Variable change step deltaX: ";
std::cin >> step;
} while (step == 0);
printTable(startX, endX, step);
return 0;
}
Почитаю больше вообще про всё это, так как мозги мне сделала эта ситуация знатно !