w 请关贴。。。 - 第2页 - 电脑语言编程讨论区 JBTALKS.CC -->
Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
12
返回列表 发新帖
楼主: HUGOHUGO
打印 上一主题 下一主题

请关贴。。。

 关闭 [复制链接]

2

主题

0

好友

66

积分

中级会员

Rank: 2Rank: 2

11#
发表于 2014-8-1 12:18 PM |只看该作者
#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;
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2025-10-17 06:00 AM , Processed in 0.429771 second(s), 19 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部