汽車行駛記錄儀C語言編程_第1頁
汽車行駛記錄儀C語言編程_第2頁
汽車行駛記錄儀C語言編程_第3頁
汽車行駛記錄儀C語言編程_第4頁
汽車行駛記錄儀C語言編程_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、汽車黑匣子項目說明1.汽車黑匣子簡介汽車黑匣子,又稱汽車工作信息記錄儀,汽車安全信息記錄儀,也有人將其形象地稱為汽車電子警察。它能夠完整、準確地記錄汽車行駛狀態(tài)下的有關(guān)情況,并通過專用軟件在電腦上再現(xiàn)。本項目只是實現(xiàn)的是它的軟件部分。2.項目要求1.記錄汽車運行時的日期,時間和速度;2.經(jīng)可能的多存一些信息:使用位段;3.每滿10次(可根據(jù)用戶要求更改)記錄向文件中存一次;4.文件大小只有1.2K(可根據(jù)用戶要求更改);3.分析建模本次項目主要的關(guān)鍵點有不斷的采集數(shù)據(jù)直到汽車停止,將采集到了數(shù)據(jù)存入到一個大小固定的文件中(此文件大小可以根據(jù)用戶要求改變),將文件里的數(shù)據(jù)讀出查看汽車行駛時采集到

2、的數(shù)據(jù)。3.1采集數(shù)據(jù)集存儲通過調(diào)用time 和localtime函數(shù)來采集日期和時間,(由于目前沒有采集速度的設(shè)備所以速度采用手動從鍵盤輸入);程序如下;void input(PPER new)int n=0;printf(請輸入卡車行駛的速度n);scanf(%d,&n);time_t timep;struct tm *p;time(&timep);p=localtime(&timep);new-year=(1900+p-tm_year);new-mouth=(1+p-tm_mon);new-day=p-tm_mday;new-hour=p-tm_hour;new-fen=p-tm_min

3、;new-second=p-tm_sec;new-speed=n;new-next=NULL;由于每條數(shù)據(jù)有比較多的信息所以我們定義一個結(jié)構(gòu)體來存儲采集到的每條數(shù)據(jù),數(shù)據(jù)采用位段存儲省空間;程序如下:typedef struct carunsigned int year:12;unsigned int mouth:4;unsigned int day:5;unsigned int hour:5;unsigned int fen:6;unsigned int second:6;unsigned int speed:9;struct car * next;PER,*PPER;由于存儲的數(shù)據(jù)條數(shù)比較

4、多且條數(shù)不固定所以采用鏈表將這些結(jié)構(gòu)體鏈接起來,來的數(shù)據(jù)往鏈表末尾一掛程序如下:PPER addlink(PPER head)int i=0;PPER ps=head;while(1)PPER new=calloc(1,sizeof(PER);input(new);if(NULL=head)head=new;ps=head;i+;elsehead-next=new;if(0=new-speed)return ps;head=head-next;i+;if(i=N)return ps;3.2將數(shù)據(jù)存入文件中每一次存儲數(shù)據(jù)在文件的位置都要從上一次結(jié)束的位置開始,我們定義一個變量n來記錄每次文件存儲

5、結(jié)束的位置,并存入文件的開頭,第二次要存儲數(shù)據(jù)的時候先讀取n的數(shù)據(jù)就知道上一次存在哪里,然后接著往后面存;文件的大小我們宏定義一個FILEMAX來控制每一次剩余文件的大小不能存儲一條 數(shù)據(jù)時將文件跳到n后面開始存儲程序如下:void inputfile(PPER head)int n=sizeof(int);FILE *fp=fopen(xiangmu.txt,r+);if(NULL=fp)fp=fopen(xiangmu.txt,w);fwrite(&n,sizeof(int),1,fp);elsefread(&n,sizeof(int),1,fp);fseek(fp,n,SEEK_SET)

6、;while(1)if(NULL=head)break;if(FILEMAX-ftell(fp)sizeof(PER)fwrite(head,sizeof(PER),1,fp);head=head-next;elsefseek(fp,sizeof(int),SEEK_SET);n=ftell(fp);rewind(fp);fwrite(&n,sizeof(int),1,fp);fclose(fp);3.3顯示文件由于文件是以二進制代碼方式存儲,人類無法直接查看所以要先將文件的內(nèi)容調(diào)入PC機內(nèi)存中顯示在顯示器上才好查看,文件到內(nèi)存放在鏈表中存儲程序如下:PPER outputfile(PPER

7、head)FILE *fp=fopen(xiangmu.txt,r);if(NULL=fp)printf(文件打開失敗n);return NULL;fseek(fp,sizeof(int),SEEK_SET);while(1)PPER new=calloc(1,sizeof(PER);fread(new,sizeof(PER),1,fp);new-next=NULL;if(0!=feof(fp)break;head=addlink1(head,new);fclose(fp);return head;PPER output(PPER head)PPER ps=head;if(NULL=head)

8、return head;while(1)show(ps);ps=ps-next;if(NULL=ps)return head;4.畫流程圖由于時間有限在此就不畫電子版的流程圖;5.編寫程序程序附帶在同一個文件夾里,再此就不做編寫6.顯示程序運行結(jié)果主菜單頁請輸入功能號0-退出1-將采集來的數(shù)據(jù)輸入鏈表中2-顯示鏈表3-將鏈表里的數(shù)據(jù)存入文件中4-釋放鏈表5-把文件里面的數(shù)據(jù)導入鏈表中6-求最大速度7求平均速度顯示文件記錄的所有數(shù)據(jù)時間2015年8月5日9時36分48秒speed93km/h時間2015年8月5日9時36分49秒speed94km/h時間2015年8月5日9時36分50秒spee

9、d95km/h時間2015年8月5日9時36分50秒speed96km/h時間2015年8月5日9時36分52秒speed97km/h時間2015年8月5日9時36分53秒speed98km/h時間2015年8月5日9時36分54秒speed99km/h時間2015年8月5日9時36分56秒speed100km/h時間2015年8月5日9時37分1秒speed101km/h時間2015年8月5日9時37分22秒speed102km/h時間2015年8月5日9時37分24秒speed103km/h時間2015年8月5日9時37分25秒speed104km/h時間2015年8月5日9時37分27秒

10、speed105km/h時間2015年8月5日9時37分28秒speed106km/h時間2015年8月5日9時37分29秒speed107km/h時間2015年8月5日9時37分31秒speed108km/h時間2015年8月5日9時37分33秒speed109km/h時間2015年8月5日9時37分36秒speed110km/h時間2015年8月5日9時37分38秒speed111km/h時間2015年8月5日9時32分15秒speed12km/h時間2015年8月5日9時32分17秒speed13km/h時間2015年8月5日9時32分18秒speed14km/h時間2015年8月5日9

11、時32分19秒speed15km/h時間2015年8月5日9時32分20秒speed16km/h時間2015年8月5日9時32分21秒speed17km/h時間2015年8月5日9時32分22秒speed18km/h時間2015年8月5日9時32分23秒speed19km/h時間2015年8月5日9時32分25秒speed20km/h時間2015年8月5日9時32分27秒speed21km/h時間2015年8月5日9時32分57秒speed22km/h時間2015年8月5日9時32分58秒speed23km/h時間2015年8月5日9時32分59秒speed24km/h時間2015年8月5日9

12、時33分0秒speed25km/h時間2015年8月5日9時33分1秒speed26km/h時間2015年8月5日9時33分2秒speed27km/h時間2015年8月5日9時33分3秒speed28km/h時間2015年8月5日9時33分4秒speed29km/h時間2015年8月5日9時33分6秒speed30km/h時間2015年8月5日9時33分7秒speed31km/h時間2015年8月5日9時33分26秒speed32km/h時間2015年8月5日9時33分28秒speed33km/h時間2015年8月5日9時33分29秒speed34km/h時間2015年8月5日9時33分30秒

13、speed35km/h時間2015年8月5日9時33分31秒speed36km/h時間2015年8月5日9時33分32秒speed37km/h時間2015年8月5日9時33分34秒speed38km/h時間2015年8月5日9時33分35秒speed39km/h時間2015年8月5日9時33分37秒speed40km/h時間2015年8月5日9時33分39秒speed41km/h時間2015年8月5日9時34分2秒speed42km/h時間2015年8月5日9時34分3秒speed43km/h時間2015年8月5日9時34分4秒speed44km/h時間2015年8月5日9時34分6秒spee

14、d45km/h時間2015年8月5日9時34分7秒speed46km/h時間2015年8月5日9時34分8秒speed47km/h時間2015年8月5日9時34分9秒speed48km/h時間2015年8月5日9時34分10秒speed49km/h時間2015年8月5日9時34分12秒speed50km/h時間2015年8月5日9時34分13秒speed51km/h時間2015年8月5日9時34分47秒speed52km/h時間2015年8月5日9時34分48秒speed53km/h時間2015年8月5日9時34分50秒speed54km/h時間2015年8月5日9時34分51秒speed55

15、km/h時間2015年8月5日9時34分52秒speed56km/h時間2015年8月5日9時34分53秒speed57km/h時間2015年8月5日9時34分54秒speed58km/h時間2015年8月5日9時34分56秒speed59km/h時間2015年8月5日9時34分57秒speed60km/h時間2015年8月5日9時34分58秒speed61km/h時間2015年8月5日9時35分14秒speed62km/h時間2015年8月5日9時35分15秒speed63km/h時間2015年8月5日9時35分16秒speed64km/h時間2015年8月5日9時35分17秒speed65

16、km/h時間2015年8月5日9時35分18秒speed66km/h時間2015年8月5日9時35分19秒speed67km/h時間2015年8月5日9時35分20秒speed68km/h時間2015年8月5日9時35分21秒speed69km/h時間2015年8月5日9時35分23秒speed70km/h時間2015年8月5日9時35分24秒speed71km/h時間2015年8月5日9時35分38秒speed72km/h時間2015年8月5日9時35分40秒speed73km/h時間2015年8月5日9時35分41秒speed74km/h時間2015年8月5日9時35分42秒speed75

17、km/h時間2015年8月5日9時35分43秒speed76km/h時間2015年8月5日9時35分45秒speed77km/h時間2015年8月5日9時35分46秒speed78km/h時間2015年8月5日9時35分47秒speed79km/h時間2015年8月5日9時35分48秒speed80km/h時間2015年8月5日9時35分49秒speed81km/h時間2015年8月5日9時36分14秒speed82km/h時間2015年8月5日9時36分15秒speed83km/h時間2015年8月5日9時36分16秒speed84km/h時間2015年8月5日9時36分18秒speed85km/h時間2015年8月5日9時36分19秒speed86km/h時間2015年8月5日9時36分20秒speed87km/h時間2015年8月5日9時36分21秒spee

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論