- 分享
- 0
- 人气
- 0
- 主题
- 2
- 帖子
- 25
- UID
- 163638
- 积分
- 66
- 阅读权限
- 12
- 注册时间
- 2008-8-31
- 最后登录
- 2018-7-20
- 在线时间
- 231 小时
|
#include<iostream>
using namespace std;
void Calculation(int count, int impact, int earth_count, int moon_count, float impact_speed_e,float earth_h, float impact_speed_m, float moon_h, float final_h)
{
do
{
impact_speed_e = sqrt(2*9.81*earth_h);
impact_speed_m = sqrt(2*1.62*moon_h);
earth_h = earth_h / 3 * 2;
moon_h = moon_h / 9 * 8;
impact = impact + 1;
cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
cout<<impact <<"\t " <<impact_speed_e <<"\t\t " <<earth_h <<"\t\t\t " <<impact_speed_m <<"\t\t " <<moon_h<<endl;
if(earth_h < final_h && count == 0)
{
earth_count = impact;
count = count + 1;
}
if (moon_h < final_h)
moon_count = impact;
}while(moon_h >= final_h);
cout<<"On Earth, it takes " <<earth_count <<" bounces to reach below the final height" <<endl;
cout<<"On Moon, it takes " <<moon_count <<" bounces to reach below the final height" <<endl;
}
int main()
{
float initial_h;
int impact=0, count=0;
int earth_count=0,moon_count=0;
float impact_speed_e=0,impact_speed_m=0,earth_h,moon_h;
float final_h;
do
{
cout<<"Enter Initial Height: ";
cin>>initial_h;
cout<<"Enter Final Height: ";
cin>>final_h;
if (initial_h == 0 && final_h == 0)
cout<<"Initial Height and Final Height cannot be 0";
else if (initial_h == 0)
cout<<"Initial Height cannot be 0";
else if (final_h == 0)
cout<<"Final Height cannot be 0";
cout<< endl << endl;
} while(initial_h == 0 || final_h == 0);
cout<<"\t\t On Earth \t\t\t\t On Moon" << endl;
cout<<"Impact \t Impact Speed \t Height \t\t Impact Speed \t Height" <<endl;
earth_h = initial_h;
moon_h = initial_h;
Calculation(count, impact, earth_count, moon_count, impact_speed_e, earth_h, impact_speed_m, moon_h, final_h);
return 0;
} |
|