0

初めて質問するので、何か不手際がありましたらご容赦ください。私は車のサスペンションシステムのプロジェクトに取り組んでいます。車とタイヤの変位と、車とタイヤの速度の 4 つの関数を作成する必要がありました。コードをうまく構成したと感じていますが、最終製品を出力していません。主な目的は、各関数の最大値を見つけることです。私はそれを修正しようと多くのことを試みましたが、解決策を思い付くことができないようです. 要点は。データファイルが最後まで情報をフィードする4つの関数を持つプログラムを構築しました。実行しようとすると、ヘッダーだけが出力されます。私はこれがどうなっているのか途方に暮れています。

データファイルは、A号車からD号車まで、タイヤのバネ定数、ダッシュポットの湿り定数、車輪の質量、車の質量、発進時間、増分値のように4つのグループに分けられています。

関数自体はちょっと…飲み込みにくいです。そこで、問題があると思われるコードのセクションをいくつか共有したいと思います。

ヘルプ/ヒント/コメントをいただければ幸いです。

csdatafiles>> total_readings;      

csdatafiles >> car_name >> spring_constant_tire >> spring_constant_spring 
>> damp_constant >> mass_of_tire >> mass_of_car 
>> start_time_value >> end_time_value >> increment_time_value;



//Initialize max min
max_displacement_car=displacement_of_car;
max_displacement_tire=displacement_of_tire;
max_velocity_car=velocity_of_car;
max_velocity_tire=velocity_of_tire;


//Output Header
 cout << "\nCar Name    Max Tire Displace   Max Tire Vel   Max Car Displace   Max Car Vel \n" << endl;


{




//recall functions
velocity_of_tire= old_new_tire_velocity (variables needed);
velocity_of_car=old_new_car_velocity (variables needed);
displacement_of_car= old_new_car_displacement (variables needed);


//check for max
if (displacement_of_car>max_displacement_car)
    max_displacement_car=displacement_of_car;

if (displacement_of_tire>max_displacement_tire)
    max_displacement_tire=displacement_of_car;

if (velocity_of_car>max_velocity_car)
    max_velocity_car=velocity_of_car;

if (velocity_of_tire>max_velocity_tire)
    max_velocity_tire=velocity_of_tire;

total_readings++;

//read rest of data
csdatafiles >> spring_constant_tire >> spring_constant_spring 
>> damp_constant >> mass_of_tire >> mass_of_car 
>> start_time_value >> end_time_value >> increment_time_value;

} while (!csdatafiles.eof());
//Output
cout << car_name << max_displacement_tire << max_velocity_tire << max_displacement_car << max_velocity_car;
4

1 に答える 1

1

投稿したコードから外れたところ、a を入れようとしたdo-whileが忘れてしまったようdoです ...

それ以外の

do {

//recall functions
//...
//check for max
//...
//read rest of data
//....

} while (!csdatafiles.eof());

あなたが持っている

{

//recall functions
//...
//check for max
//...
//read rest of data
//....

} while (!csdatafiles.eof());

これは非常に異なります!がないdo場合、コードは次と同等です。

{

//recall functions
//...
//check for max
//...
//read rest of data
//....

}

while (!csdatafiles.eof()) {
  ;
}

ご覧のとおり、最後の cout ステートメントの直前に無限ループがあるため、そこに到達することはありません。

于 2013-03-31T09:09:59.680 に答える