私のプログラムは、.txt ファイルを入力 (1 ~ 10 秒の時間) として使用して、落下物体の距離を計算することになっています。テキスト ファイルは次のようになります。
1 2 3 4 5 6 7 8 9 10
これまでのコードは次のとおりです。
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
using namespace std;
//function prototype
double fallingDistance (int);
void main()
{
ifstream inputFile;
int time;
double distance;
//open the file
inputFile.open("05.txt");
inputFile >> time;
{
distance = fallingDistance (time);
cout << time << "\t\t" << distance << endl;
}
}
double fallingDistance (int time)
{
double distance, gravity=9.8;
distance = static_cast<double>(0.5 * gravity * pow(time,2));
return distance;
}
そして、これは私のプログラムがコンパイルするものです:
1 4.9
press any key to continue...
前もって感謝します!