• 大小: 0.2M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: 其他
  • 标签: 其他  

资源简介

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      // 给数组开辟空间
#define L 300 // 给数组开辟空间

// 定义整形变量
int j h;
// 定义浮点型变量
float temp;
// a[N]用于存原始数据 sum[N]用于存所需中间量
float a[N] sum[N];
// 频率 累计频率
double frequency[L] accumulated_freq[L];


// 函数声明
void readdata();
void calculate();
int save_data();
 
void main()
{
readdata();         // 读取文本文件里的数据
calculate(); // 计算
save_data(); // 存文档
}

// 读取文本文件里的数据
void readdata()
{
int i = 0;
FILE *f; // 定义指针

// 打开并读取文件,f指向文件里第一个数据的地址
if((f = fopen(“quantity_of_speed.txt“ “r“)) == NULL) 
{ // 增强程序的健壮性
printf(“无法打开\n“);
return;
}
// 将文件里的数据逐个读取到数组当中
while(!feof(f))
{
fscanf(f “%f“ &a[i]);
i++;
}
// 关闭文件
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];
}
}

// 计算
void calculate()
{
int k=0;

// 频数,第一个for循环的范围由Excel表格排序给出循环区间
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“ );//假设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“);

// 累计频率
fprintf(pf“累计频率: \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)//关闭文件 
{
fclose( pf);
pf=NULL;

printf(“数据已写入data.txt文件!\n“);
return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      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


评论

共有 条评论