岩を崖から投げ落としたときに、岩がどれだけの距離と時間を移動するかを決定するプログラムを作成します。ここをクリックしてファイル toss.txt をデスクトップにコピーします (ファイル名を右クリックし、[名前を付けて保存] を選択します)。このファイルには、崖の高さがメートル単位で含まれています。
次に、プログラムは次のことを行います。
ファイル toss.txt を開き、崖の高さを倍精度変数に読み取り、適切なラベルを付けて崖の高さの値を画面にエコー出力します。
岩が投げられる角度 (90 度は真上、0 度は真正面) と岩が投げられる速度 (マイル/時) をユーザーに尋ねます。
角度が 0 以上 90 以下であることを確認してください。そうでない場合、プログラムは終了し、適切なエラー メッセージが画面に出力されます。
速度が 100 mph 以下で 0 mph 以上であることを確認します。そうでない場合、プログラムは終了し、適切なエラー メッセージが画面に出力されます。
角度と速度が有効な場合、プログラムは次のように計算を完了します。
マイル/時をメートル/秒に変換します。
角度をラジアンに変換します。
次の式を使用して移動時間を計算します。
どこ
以下を使用して、水平方向に移動した距離を計算します。
適切なラベルを付けて、水平方向に移動した時間と距離を画面に出力します。
水平方向に移動した距離が崖の高さよりも大きいか、小さいか、または等しいかをユーザーに知らせる適切なメッセージを出力します。
/* This program */ using namespace std; #include<iostream> #include<cmath> #include<iomanip> #include<fstream> int readit (); int calcit (double, double, double); int main() { readit (); system ("pause"); return 0; } int readit () { double hite, angl, v; ifstream datain ( "toss.txt" ); datain >> hite; cout << "The cliff height is " << hite << " meters"<< endl; cout << "Enter the angle in degrees (from horizontal) the rock is thrown: " << endl; cin >> angl; if (angl>=0 && angl<=90) { cout << endl << "The angle you have entered is "<<angl<< endl <<endl; } else { cout << "The angle you have entered is not acceptable" << endl; return 0; } cout << "Enter the velocity in mph the rock is thrown: " << endl; cin >> v; if (v>=0 && v<=100) { cout << endl << "The velocity at which the rock is thrown is "<<v<< " mph" << endl << endl; } else { cout << "The velocity you have entered is not acceptable" << endl; return 0; } calcit (hite, angl, v); } int calcit (double hite, double angl, double v) { double tyme, dist; v = v * (1609.344/3600); angl = angl*(M_PI/180); tyme = -v*sin(angl) + (sqrt((v*sin(angl)*v*sin(angl)) + 2*9.8*hite)/9.8) + (2*(v*sin(angl))/9.8); dist = (tyme * v) * cos(angl); cout << tyme << " " << dist <<endl; }
岩が地面に衝突する前に岩が移動する正確な時間を取得しようとしていますが、間違った答えが返ってきます。方程式を回して、岩が空中にある時間をC ++言語に正しく影響するまで計算しているかどうかはわかりません。何かアイデアはありますか?私は本当にこのいまいましいプロジェクトを終わらせる必要があります。