資源簡(jiǎn)介
InvestigationofCar-speed.rar

代碼片段和文件信息
/*************************************************************************
*@?property?in?copyright???:Guo?Youtian
*@?author??????????????????:Guo?Youtian
*@?contact?information?????:QQ:272318713??WeChat:Guoyoutiande
*@?result??????????????????:?calculate?all?the?result?of?experiment?two
*@?matters?need?ateention??:?do?not?change?the?content?if?possible
*@?the?last?change?time????:2017-05-10
**************************************************************************/
#include?
#define?N?7000??????//?給數(shù)組開辟空間
#define?L?300 //?給數(shù)組開辟空間
//?定義整形變量
int?j?h;
//?定義浮點(diǎn)型變量
float?temp;
//?a[N]用于存原始數(shù)據(jù)?sum[N]用于存所需中間量
float?a[N]?sum[N];
//?頻率?累計(jì)頻率
double?frequency[L]?accumulated_freq[L];
//?函數(shù)聲明
void?readdata();
void?calculate();
int?save_data();
?
void?main()
{
readdata(); ????????//?讀取文本文件里的數(shù)據(jù)
calculate(); //?計(jì)算
save_data(); //?存文檔
}
//?讀取文本文件里的數(shù)據(jù)
void?readdata()
{
int?i?=?0;
FILE?*f; //?定義指針
//?打開并讀取文件,f指向文件里第一個(gè)數(shù)據(jù)的地址
if((f?=?fopen(“quantity_of_speed.txt“?“r“))?==?NULL)?
{ //?增強(qiáng)程序的健壯性
printf(“無法打開\n“);
return;
}
//?將文件里的數(shù)據(jù)逐個(gè)讀取到數(shù)組當(dāng)中
while(!feof(f))
{
fscanf(f?“%f“?&a[i]);
i++;
}
//?關(guān)閉文件
fclose(f);
//?四舍五入
for?(i=0;?i<6885;?i++)
{
temp?=?a[i]?-?(int)a[i];
if?(temp?>=?0.5)
a[i]?=?(int)a[i]?+?1;
else
a[i]?=?(int)a[i];
}
}
//?計(jì)算
void?calculate()
{
int?k=0;
//?頻數(shù),第一個(gè)for循環(huán)的范圍由Excel表格排序給出循環(huán)區(qū)間
for?(j=11;?j<224;?j++)
{
//?清零
sum[0]?=?0;
// frequency[j]?=?0;
// accumulated_freq[j]?=?0;
for?(k=0;?k<6885;?k++)
{
if?(j?==?a[k])
frequency[j]?+=?1;
}
frequency[j]?=?frequency[j]/6885*100;
accumulated_freq[j]?=?accumulated_freq[j-1]?+?frequency[j];
}
}
//?存文檔
int?save_data()
{
FILE?*pf=NULL;
pf=fopen(“data.txt“?“w“?);//假設(shè)test.txt文件為空?
if(!pf)
{
printf(“打開文件失敗,程序退出!“);
exit(1);?
}?
//?頻率
fprintf(pf“頻率:?\n“);
for?(j=11;?j<224;?j++)
{
fprintf(pf“速度為%dKm/h:?%3.8f\t“j?frequency[j]);
if(((j-11)%6)==0)
fprintf(pf“\n“);
}
fprintf(pf“\n“);
//?累計(jì)頻率
fprintf(pf“累計(jì)頻率:?\n“);
for?(j=11;?j<224;?j++)
{
fprintf(pf“速度為%dKm/h:?%3.8f\t“j?accumulated_freq[j]);
if(((j-11)%6)==0)
fprintf(pf“\n“);
}
if(pf)//關(guān)閉文件?
{
fclose(?pf);
pf=NULL;
}?
printf(“數(shù)據(jù)已寫入data.txt文件!\n“);
return?0;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????11204??2017-05-10?22:30??Investigation?of?Car-speed\data.txt
?????文件???????4874??2017-05-10?22:26??Investigation?of?Car-speed\data_1.txt
?????文件??????41984??2017-05-10?22:30??Investigation?of?Car-speed\Debug\experiment2.bsc
?????文件?????209028??2017-05-10?22:30??Investigation?of?Car-speed\Debug\experiment2.exe
?????文件?????235688??2017-05-10?22:30??Investigation?of?Car-speed\Debug\experiment2.ilk
?????文件???????9399??2017-05-10?22:30??Investigation?of?Car-speed\Debug\experiment2.obj
?????文件?????175588??2017-05-10?17:27??Investigation?of?Car-speed\Debug\experiment2.pch
?????文件?????500736??2017-05-10?22:30??Investigation?of?Car-speed\Debug\experiment2.pdb
?????文件??????????0??2017-05-10?22:30??Investigation?of?Car-speed\Debug\experiment2.sbr
?????文件??????33792??2017-05-10?22:30??Investigation?of?Car-speed\Debug\vc60.idb
?????文件??????53248??2017-05-10?22:30??Investigation?of?Car-speed\Debug\vc60.pdb
?????文件???????2566??2017-05-10?22:30??Investigation?of?Car-speed\experiment2.c
?????文件???????3463??2017-05-10?22:30??Investigation?of?Car-speed\experiment2.dsp
?????文件????????530??2017-05-10?22:30??Investigation?of?Car-speed\experiment2.dsw
?????文件??????33792??2017-05-10?22:30??Investigation?of?Car-speed\experiment2.ncb
?????文件??????48640??2017-05-10?22:30??Investigation?of?Car-speed\experiment2.opt
?????文件???????1977??2017-05-10?22:30??Investigation?of?Car-speed\experiment2.plg
?????文件??????43070??2017-05-10?15:51??Investigation?of?Car-speed\quantity_of_speed.txt
?????目錄??????????0??2018-12-01?12:25??Investigation?of?Car-speed\Debug
?????目錄??????????0??2018-12-01?12:25??Investigation?of?Car-speed
-----------?---------??----------?-----??----
??????????????1409579????????????????????20
評(píng)論
共有 條評(píng)論