程序查找在C ++中经过2点的线
为此,我们将提供两点。我们的任务是使用这些值并找到通过这些点的直线方程。
示例
#include <iostream>
using namespace std;
//存储x,y对
#define pdd pair<double, double>
//从给定点找到线
void lineFromPoints(pdd P, pdd Q){
double a = Q.second - P.second;
double b = P.first - Q.first;
double c = a*(P.first) + b*(P.second);
if(b<0){
cout << "The line passing through points P and Q is: " << a << "x " << b << "y = " << c << endl;
} else {
cout << "The line passing through points P and Q is: " << a << "x + " << b << "y = " << c << endl;
}
}
int main(){
pdd P = make_pair(3, 2);
pdd Q = make_pair(2, 6);
lineFromPoints(P, Q);
return 0;
}输出结果
The line passing through points P and Q is: 4x + 1y = 14
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短