JBTALKS.CC

标题: 请关贴。。。 [打印本页]

作者: HUGOHUGO    时间: 2014-7-31 02:18 AM
标题: 请关贴。。。
本帖最后由 HUGOHUGO 于 2014-7-31 12:57 PM 编辑

请关贴。。。
作者: Koo01    时间: 2014-7-31 08:58 AM
哇!好难哦……
我之前做过calendar的,现在忘光光了
作者: edison31    时间: 2014-7-31 09:24 AM
在你diplay result后加while(1);
就会出现你的result了,不然他会直接end,或者你做给他显示“press any key to leave",这样他就不会直接end了。还有你的function都已经错了,下面的图片是你code的result。这类型code应该只是属于a-level或foundation的assignment罢了,很容易罢了的,你应该要学会如何debug他。

Untitled.png (8.74 KB, 下载次数: 4)

Untitled.png


作者: memring007    时间: 2014-7-31 11:20 AM
你的 "} while(final_height<=0 || initial_height<final_height );" 里的variables都不是变数。你要它如何loop.

Display_Title();
do
{
         height_moon = initial_height;
         height_earth = initial_height;

        // FUNCTION CALL
        Display_Title();
        /*Calculation    (impact_speed_earth, height_earth, impact_speed_moon, height_moon,height_earth);*/

        Calculation    (impact_speed_earth, height_earth, impact_speed_moon, height_moon, initial_height);
        Display_Result (impact, impact_speed_earth, height_earth, impact_speed_moon, height_moon);
        impact++;  

         // when 6th impact,height > final height,impact ++ to 7,and now the height < final height,then no more impact++.
} while(height_earth<=0 || height_earth<final_height );
作者: memring007    时间: 2014-7-31 11:33 AM
你的nitial_h也没有变数啊。如果有assign value给它就可以。

void  Calculation    ( double &impact_speed_e , double &height_e , double &impact_speed_m , double &height_m ,double &initial_h)
{   const double  gravity_e=9.81, gravity_m=1.62;
        height_e  *= (2/3);
        height_m *= (8/9);
        /*height_e = initial_h * (2/3);
        height_m = initial_h * (8/9);*/
        impact_speed_e = sqrt(2*gravity_e * height_e);
        impact_speed_m = sqrt(2*gravity_m * height_m);
      
}  
作者: HUGOHUGO    时间: 2014-7-31 12:20 PM
memring007 发表于 2014-7-31 11:33 AM
你的nitial_h也没有变数啊。如果有assign value给它就可以。

void  Calculation    ( double &impact_sp ...

放=0给他???

我不是很明白。
作者: memring007    时间: 2014-7-31 01:21 PM
试试看是不是你要的结果。

void  Calculation    ( double &impact_speed_e , double &height_e , double &impact_speed_m , double &height_m ,double &initial_h)
{   const double  gravity_e=9.81, gravity_m=1.62;
        height_e  *= (2/3);
        height_m *= (8/9);
        /*height_e = initial_h * (2/3);
        height_m = initial_h * (8/9);*/
        impact_speed_e = sqrt(2*gravity_e * height_e);
        impact_speed_m = sqrt(2*gravity_m * height_m);
      initial_h *= (2/3);
}  
作者: karkit1990    时间: 2014-7-31 01:45 PM
1. Function Call和Calculation的Loop, 每次你的loop开始都会把initial height assign to height moon and height earth. 如果你的calculation没有错的话,你的loop永远不会停。

应该把它们放在loop的前面

2.
the impact speed and the bounce back height on every impact until the ball bounces lower than the final height on moon.

While 那里应该 放 (Height_moon>=final_height)
Loop不会停一直到height_moon小过final_height

3.Calculation()
看一下你的example,
Impact        Impact Speed        Height
1        9.905                3.333

很明显第一个impact speed是用initial height = 5,第二个才用3.333,所以你的calculation不能放height_e*=(2/3)在前面,应该放在impact speed的后面

应该用
impact_speed_e = sqrt(2*gravity_e*height_e)
impact_speed_m = sqrt(2*gravity_m*height_m)
height_e *= (2/3)
height_m *= (8/9)

你去改一改再放上来吧
作者: karkit1990    时间: 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 (https://www.jbtalks.my/) Powered by Discuz! X2.5