3v.cpp

来自「《C/C++程序设计导论(第二版)》一书的程序源文件」· C++ 代码 · 共 27 行

CPP
27
字号
// Program to calculate the height of a tower
#include <iostream.h>
#include <math.h>

// CalcHypot() A function to calc. and return the hypotenuse
// of a right triangle.
// 	IN:		base; the base of the triangle
//			angle; an angle in degrees between the base and hypot.
float CalcHypot (float base, float angle)
{	float radians, ht, dist;
	const float pi_radians = 0.01745;					// pi / 180.0;
	radians = angle * pi_radians;				
	ht = base * tan(radians);
	dist = sqrt (base*base + ht*ht);
	return (dist);
}

void main()
 {	float base, angle, dist;
	cout << "enter base distance to tower:";
	cin >> base;
	cout << "enter angle (in degrees):";
	cin >> angle;
	dist = CalcHypot (base, angle);
	cout << " distance from observer to top: " << dist << endl;
 }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?