壁に向かってボールを投げ、壁にあたり床に落ちる。そして、ボールが床をバウンドしなくなるまでのプログラムを作りたいのです。反発係数ありで空気抵抗はなしにします。vidualstudio C++で制作します。
関数と配列を必ず用いなければならないのですが、どのように進めたよいかわかりません。
日曜日までに完成させたいのですが、わかる方教えてください。
このプログラムが完成したら、excelで軌跡を描きます。
それについても教えてください。
それじゃ「丸投げ」やないですか。
このようにプログラムをつくりました。でも動きません。
#include<stdio.h>
#include<math.h>
#define MAX 1000
void main(void){
int i;
double x[MAX],y[MAX];
double t,dt;
double v0x,v0y,v0,g,e1,e2,x0;
scanf("%lf",&v0x);
scanf("%lf",&v0y);
scanf("%lf",&v0);
scanf("%lf",&g);
scanf("%lf",&e1);
scanf("%lf",&e2);
FILE *fp;
dt=0.01;
fp=fopen("kekka.csv","w");
x0=0;
y0=0;
for(i=0;i<x0/v0*dt;i++){
t=i*dt;
x=v0x*t+x0;
}
x0=e1*v0x;
y0=0;
for(i=0;i<sqrt2vo/g;i++){
x=e1*v0x*t;
y=y0-1/2*g*t*t;
}
x0=0;
while(v0y>0.1){
for(i=0;i<2*v0y/g/dt;i++){
t=i*dt;
x[i]=x0+v0x*t;
y[i]=v0y*t-g*t*t/2;
fprintf(fp,"%f,%f\n",x[i],y[i]);
}
x0=x0+2*v0x*v0y/g;
v0y=e1*v0y;
}
fclose(fp);
}
動かすと
1>------ ビルド開始: プロジェクト: 最終課題, 構成: Debug Win32 ------
1>コンパイルしています...
1>物体の運動.cpp
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(12) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(295) : 'scanf' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(13) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(295) : 'scanf' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(14) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(295) : 'scanf' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(15) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(295) : 'scanf' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(16) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(295) : 'scanf' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(17) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(295) : 'scanf' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(22) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(234) : 'fopen' の宣言を確認してください。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(25) : error C2659: '=' : 関数が演算子の左辺にあります
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(28) : error C2440: '=' : 'double' から 'double [1000]' に変換できません。
1> 配列型への変換はありませんが、参照またはポインタから配列への変換があります。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(31) : error C2659: '=' : 関数が演算子の左辺にあります
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(32) : error C2065: 'sqrt2vo' : 定義されていない識別子です。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(33) : error C2440: '=' : 'double' から 'double [1000]' に変換できません。
1> 配列型への変換はありませんが、参照またはポインタから配列への変換があります。
1>c:\users\eri\documents\visual studio 2005\projects\最終課題\最終課題\物体の運動.cpp(34) : error C2296: '-' : 無効です。左オペランドには型 'double (__cdecl *)(double)' が指定されています。
1>ビルドログは "file://c:\Users\eri\Documents\Visual Studio 2005\Projects\最終課題\最終課題\Debug\BuildLog.htm" に保存されました。
1>最終課題 - エラー 6、警告 7
========== ビルド: 0 正常終了、1 失敗、0 更新、0 スキップ ==========
と出ます。どのように直せばよいかわかりません。
まるでデタラメ。
> x0=0;
> y0=0;
x0,y0なんて定義してないし。
他にも山ほど。指摘するのもメンドクセー
すいません。
ツイート | ![]() |