这份代码使用安卓智能手机上的C4droid编写的,下载下来最好是用C4droid打开。这个程序是拿来算抛物线的长度的,默认左端点是0,右端点由用户输入。计算从0到您输入值区间抛物线的长度,所求值是一个近似值,精确度较高。
1.[代码][C/C++]代码
#include
#include
using namespace std;
double curveLenth(double a, double b, double c, double x)
{
long double dx1, dx2, dy1, dy2, l = 0;
double i, h;
for (h = 0, i = 1; i <= (x * 100000); i++, h++)
{
dx1 = h / 100000, dx2 = i / 100000;
dy1 = a * dx1 * dx1 + b * dx1, dy2 = a * dx2 * dx2 + b * dx2;
l = l + hypot(dx2 – dx1, dy2 – dy1);
}
return l;
}
int main()
{
a:double a, b, c, x; //做个标记
cout << “请输入方程系数a b c:”;
cin >> a >> b >> c;
cout << “请输入曲线右端点x值:”;
cin >> x;
cout << “曲线长度为:” << curveLenth(a, b, c, x) << endl;
goto a; //这样程序运行完就不会退出了
return 0;
}
2.[文件] 抛物线长度计算.cpp ~ 714B 下载(19)
#include
#include
using namespace std;
double curveLenth(double a, double b, double c, double x)
{
long double dx1, dx2, dy1, dy2, l = 0;
double i, h;
for (h = 0, i = 1; i <= (x * 100000); i++, h++)
{
dx1 = h / 100000, dx2 = i / 100000;
dy1 = a * dx1 * dx1 + b * dx1, dy2 = a * dx2 * dx2 + b * dx2;
l = l + hypot(dx2 – dx1, dy2 – dy1);
}
return l;
}
int main()
{
a:double a, b, c, x; //做个标记
cout << “请输入方程系数a b c:”;
cin >> a >> b >> c;
cout << “请输入曲线右端点x值:”;
cin >> x;
cout << “曲线长度为:” << curveLenth(a, b, c, x) << endl;
goto a; //这样程序运行完就不会退出了
return 0;
}