最近,我一直在研究一個發動機推力計算給定值的斜率。在方程中使用二維數組
我已經得到了很多的代碼工作,但我似乎無法得到方程功能的工作。該人應該根據圖表和牛頓上的特定點列出數值,然後給出不同的時間,計算機將在給定的時間和斜率計算之間找到一個值。
當然,這不工作,我真的迷失在這一點上,我100%肯定我的循環在函數中是錯誤的,但我不知道我的方程是錯誤的。
基本程序是應該這樣做
x y
.19 14.5
.24 6.0
.40 4.4
Enter a time: .21
((.21-.19)/.24-.19))*(6-14.5)+14.5=11.1
the thrust at time .21 is 11.1
來源
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
const int grid_rows=50;
const int grid_cols=2;
double slope(double thrust[grid_rows][grid_cols],double time);
// Constant Declarations
const double PI = 3.1415926535; // the radius/diameter of a circle
// Main Program
int main()
{
system("CLS");
cout << "Take Home #12 by - "
<< "CETUA\n\n";
double thrust[grid_rows][grid_cols];
double time;
double newton;
char ans;
int i=0;
int j=0;
cout << "Enter thrust curve data (0 for thrust end list): "<<endl;
for(i=0;i < grid_rows; i++)
{
for(j=0; j< grid_cols;j++)
{
cin >> thrust[i][j];
if(thrust[i][j]==0)
{
break;
}
}
if(thrust[i][j]==0)
{
break;
}
}
do
{
cout << "Enter a time: "<<endl;
cin >> time;
newton=slope(thrust,time);
cout << "The thrust at time "<<time << " is " << newton << " newtons." <<endl:
cout << "Would you like another thrust value? (Y or N): " <<endl;
cin >> ans;
}while(ans=='Y'||ans=='y');
}
double slope(double thrust[50][2],double time)
{
double newton;
while(time > thrust[50][2]);
{
for(int i=0;i < grid_rows; i++)
{
for(int j=0; j< grid_cols;j++)
{
newton=((time - thrust[i][j])/(thrust[i][j]-thrust[i][j]))
*(thrust[i][j]-thrust[i][j])+thrust[i][j];
return newton;
}
}
}
}
嘗試在發佈之前縮進代碼,它使代碼更具可讀性。 – ANjaNA
以數組表示給我你的例子,它是3X2嗎? – ANjaNA
它的一個50 * 2,50行和2列 – Notkrokidal