我创建了一个计算两点之间距离的程序,并找到了斜率.
1)我如何将程序更改为严格指针?
2)无论输入什么,距离函数都返回"-1".我100%肯定我的算法是正确的,但似乎出现了问题.
// This program computes the distance between two points
// and the slope of the line passing through these two points.
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
struct Point
{
double x;
double y;
};
double distance(Point &p1, Point &p2);
double slope(Point &p1, Point &p2);
int main()
{
Point p1, p2;
char flag = 'y';
cout << fixed << setprecision(2);
while(flag == 'y' || flag == 'Y')
{
cout << "First x value: "; cin >> p1.x; …Run Code Online (Sandbox Code Playgroud)