您好,我无法为我的作业编写解决方案代码。我需要要求用户为两个方程输入 6 个变量。仅在成功提取数字后,如果有解决方案,我需要找到每条线的斜率、每条线的 y 截距、每条线上的两个点(有序对,例如 (2,1))。还有什么关系。我搜索并搜索了大多数数字检查和方程式。我遇到的麻烦是找到方程的点和解。
#include <iostream>
#include <limits>
int main()
{
std::cout<<"This program is designed to test two linear equations. \n";
std::cout<<"In order to best solve the system, \n";
std::cout<<"equations will be in the form of a*x + b*y = c. \n";
std::cout<<"and d*x + e*y =f. \n";
std::cout<<"Please enter an integer for a, b, and c. \n";
double a, b, c, d, e, f;
while ((std::cout << "Enter a.")
&& !(std::cin >> a))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter b.")
&& !(std::cin >> b))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter c.")
&& !(std::cin >> c))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout<<"Equation 1 is "<<a<<"x +"<<b<<"y ="<<c;
std::cout<<"Please enter an integer for d, e, and f. \n";
while ((std::cout << "Enter d.")
&& !(std::cin >> d))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter e.")
&& !(std::cin >> e))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter f.")
&& !(std::cin >> f))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout<<"Equation 2 is "<<d<<"x +"<<e<<"y ="<<f;
double slope1, slope2;
double x1, x2, y1, y2;
slope1 = (b / a);
slope2 = (e / d);
std::cout<<" Slope of Equation 1 is "<<slope1<<"\n";
std::cout<<" Slope of Equation 2 is "<<slope2<<"\n";
x1 = ((c*e)-(b*f))/ ((a*e)-(b*d));
y1 = ((a*f)-(c*d))/ ((a*e)-(b*d));
return 0;
}