程式设计入门_第1页
程式设计入门_第2页
程式设计入门_第3页
程式设计入门_第4页
程式设计入门_第5页
已阅读5页,还剩63页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程式設計入門專題報告題目:輻射劑量估算系統組別:第22組9512814林慕涵9613515趙祥萍9631131賀安麗

一、系統功能,輸入及輸出資料從事放射性相關的工作人員身上會佩帶一個配章,內部可以記錄人在工作場所所受到的輻射量。此配章可同時紀錄「深部劑量」,表示體內器官接受之劑量;「淺部劑量」,表示體表皮膚所接受到之劑量,「水晶體劑量」,表示水晶體所接受之劑量,以及「背景值」,表示該場所輻射背景值。為了人員的健康安全,政府針對上述三種部位的劑量分別有其年度劑量限度的規定,若在該年度內員工身上的累積輻射量值經報告分析後超過法定量,必須一段時間不能接觸放射性的工作場所,或採取必須之醫療行動。此劑量配章在每月初發放至各單位,並在每月底送回相關劑量分析機構進行計讀及劑量估算,並檢查每位人員是否已接受超出法規劑量限度。本程式即模擬該劑量分析機構之工作,將回收讀出之人員劑量讀值轉換為絕對劑量,並分別輸出單位人員劑量資料給各工作單位,以及檢查、列出劑量超出法規規定之人員名單給政府機關存查。1.輸入的資料:A當月人員劑量讀值檔(import_idreading.txt)包含下列欄位:◎公司代碼◎人員代碼2

◎姓名◎深部讀值◎淺部讀值◎水晶體讀值◎背景讀值例:含有12筆當月劑量的讀入數據檔001970200197030020010019710003011010105732901752519027103040030525100177251906525450272097029600197050020020040100200300197010030225100177000025100177105550019715B累積劑量資料庫檔(import_database.txt)包含下列欄位:◎公司代碼◎人員代碼◎姓名◎深部累積劑量◎淺部累積劑量3◎水晶體累積劑量◎紀錄是否超出劑量例:含有9筆累積劑量的資料庫:0019702001970300197050019710002001002002002003003017020030732901725190630400302519027254502725100172510017251001700302C公司部門資料檔(import_dep_id.txt)有四個機構,分別以001到004編號排序。包含以下欄位:◎公司代碼◎公司名稱例:含有4筆機構資料的機構資料檔001青樺大學002長羹醫院003大千醫院004同步輻射中心2.輸出的資料41.儲存新的人員累積劑量資料庫2.各單位人員累積劑量名單,並以星號(*)註記各人員超出劑量限度的項目3.呈報政府機關劑量超出法規的所有人員名單二、應用層面說明本程式應用結構陣列資料搜尋/處理以及各式排序法、字串處理以及各式迴圈判斷,這樣的系統除了用在人員輻射劑量佩章管理之外,也可應用財經報表、客戶名單管理、圖書資料管理…等等,甚至是研究、實驗數據資料處理亦可應用結構陣列整合參數、實驗敘述以及所得之數據結果。三、全域常數及資料結構說明程式最上方定義了全域常數A.最大陣列限制:MAX_ARRAY_SIZE500B.不同部位之輻射轉換、法規定義之劑量限度定設為全域常數。如下:(ex.cf_deep)1.55021(ex.Criteria_deep)5001505在程式當中,我們建構並使用了三種資料結構A.人員當月劑量讀值資料結構(person),用來儲存個人員的資料,包含下列欄位:◎公司代碼(intdepid)◎人員代碼(intpid)◎姓名(charname[20])(最多20字元)◎深部讀值(floatrdeep)◎淺部讀值(floatrshallow)◎水晶體讀值(floatreye)◎背景讀值(floatbg)圖示概念如下:(person)intdepidintpidcharname[20]floatrdeepfloatrshallowfloatreyefloatbgB.累積劑量資料庫結構(database),用來儲存人員之前的各項資料紀錄,包含下列欄位:◎公司代碼(intdepid)6◎人員代碼(intpid)◎姓名(charname[20])◎深部累積劑量(floatyrdeep)◎淺部累積劑量(floatyrshallow)◎水晶體累積劑量(floatyreye)◎紀錄是否超出劑量(intreference)圖示概念如下:(database)intdepidintpidcharname[20]floatyrdeepfloatyrshallowfloatyreyeintreferenceC.公司部門資料結構(department),儲存公司名稱及編號,包含下列欄位:◎公司代碼(intdepid)◎公司名稱(chardepname[20])圖示概念如下:(departmentintdepidchardepname[20]7再以三個一维陣列personpdata[num_person]、databaseydata[num_dat及departmentddata[num_depart],分別儲存所有資料。每一筆personpdata[i](0<≤num_pe、irson)database<ydata[i]i≦num_dat(0及abase)department<ddata[i]i≦num_de分p別a(0代rt)表一個人員的當月劑量讀值、累積劑量資料、一個公司部門。num_person、num_database及num_depart分別指出最多有幾個人員的資料、最多有幾筆累積資料、以及最多有幾間公司部門。圖示概念如下:儲存所有人員當月劑量讀值的一维陣列(personpdata[num_person])[1][2][3]8儲存所有人員累積劑量資料庫的一维陣列(databaseddata[num_data[1][2][3]例:假設一開始人員當月劑量讀值陣列儲存的內容如下:[1][2][3][4][5][6][7][8][9][10][11]0010010020010030010020040020010039702970300197100110732530252525910101727301765290190400100190450705105797050020152729170206003970102250100070251001779[12]001971510555一開始,人員累積劑量資料庫陣列如下:[1][2][3][4][5][6][7][8][9]001001001001002002002003003970297039705971000100200301707325302525252525200290190400190450100100100301760000000003027271717170210假設經過程式執行後,新的資料庫內容如下所示:[11][1][2][3][4][12][5][6][7][8][9][10]00100100100100100100200200200300300497019702970397059710971500100200301000077.517555210860560119003529734567.57.547.532.5525507055013102862862861284434272727238910110520252014.50上圖中有陰影的位置表示曾於程式執行過程中修改過。詳細說明請參閱執行範例。四、程式說明1.主程式main()◎說明:根據所讀取的當月劑量與累計劑量加總後運算出數值,並檢查是否超過法定標準,印出劑量超出法規的所有人員名單,以及以各機構為單位的人員所有讀值,若超過標準則在旁另有標註。◎輸入參數:無◎回傳值:無11◎流程圖:(見下頁)12

開始打開相關輸入及輸出檔案No檔案是否存在?Yes呼叫副程式read_person讀入人員劑量讀值離開程式呼叫副程式read_database,讀入劑量資料庫呼叫副程式read_department讀入公司資料庫呼叫副程式dose_convert將當月人員劑量讀值轉為絕對劑量呼叫副程式cumulate_dose將本月劑量累積加入資料庫併且將新加入的人員插入資料庫呼叫副程式sort_personid將資料庫中各公司人員依照人員編號重新排序呼叫副程式link_overdose串連超出劑量限度的名單呼叫副程式write_database將新的資料庫寫入檔案呼叫副程式display_write_department顯示並儲存各公司部門人員之劑量呼叫副程式display_write_gov顯示並儲存劑量超出法規之人員名單結束13◎程式碼:main(){/**/FILE*person_data_fp;structpersonpdata[MAX_ARRAY_SIZE];intnum_person;/**/FILE*database_data_fp;structdatabaseydata[MAX_ARRAY_SIZE];intnum_database;/**/FILE*depart_data_fp;structdepartmentddata[MAX_ARRAY_SIZE];intnum_depart;/**/intheadindex;/**/FILE*database_data2_fp;/*database*/database_data2_fp=fopen(OUTPUT_NEWDATABASE_FILENAME,"a");FILE*to_department_fp;/**/to_department_fp=fopen(OUTPUT_DEP_FILENAME,"a");FILE*to_government_fp;/**/to_government_fp=fopen(OUTPUT_GOV_FILENAME,"a");/**/if(!(person_data_fp=fopen(PERSON_READING_FILENAME,"r"))){printf("personaldosefileisnotexist\n");}14if(!(database_data_fp=fopen(PERSON_DOSE_DATABASE_FILENAME,"r"))){printf("databasefileisnotexist\n");}if(!(depart_data_fp=fopen(DEPARTMENT_FILENAME,"r"))){printf("company/departmentfileisnotexist\n");}/**/num_person=read_person(pdata,person_data_fp);fclose(person_data_fp);/**/num_database=read_database(ydata,database_data_fp);/*fclose(database_data_fp);*/num_depart=read_department(ddata,depart_data_fp);fclose(depart_data_fp);/**//**/dose_convert(pdata,num_person);/**/num_database=cumulate_dose(pdata,ydata,num_person,num_database);/**/sort_personid(ydata,ddata,num_depart,num_database);/**/headindex=link_overdose(ydata,num_database);/**/write_database(ydata,num_database,database_data2_fp);/**/display_write_department(ydata,ddata,num_depart,num_database,to_department_fp);/**/display_write_gov(ydata,ddata,num_depart,headindex,to_government_fp);15getch();}2.副程式2.1read_person()◎說明:讀取檔案內容◎輸入參數:人員當月劑量結構矩陣◎回傳值:該矩陣資料筆數至主程式◎流程圖:i=0Noi<Max_array_sizeYes結束從檔案中將資料讀入ptemp資料結構陣列中:ptemp[i+1].depid,ptemp[i+1].pid,ptemp[i+1].name,ptemp[i+1].rdeep,ptemp[i+1].rshallow,ptemp[i+1].reye,ptemp[i+1].bgYesfeof(fp)=1?回傳iNoi=i+116◎程式碼:intread_person(structpersonptemp[MAX_ARRAY_SIZE],FILE*fp){inti;i=0;/*iMAX_ARRAY_SIZEptemp*/*/while(i<MAX_ARRAY_SIZE){/*fscanf(fp,"%d%d%s%f%f%f%f",&ptemp[i+1].depid,&ptemp[i+1].pid,&ptemp[i+1].name,&ptemp[i+1].rdeep,&ptemp[i+1].rshallow,&ptemp[i+1].reye,&ptemp[i+1].bg);if(!feof(fp))/**/{i++;}/*i1*/else{returni;}/*i*/}}2.2read_database()◎說明:讀取檔案後,將資料讀入人員累積劑量資料庫◎輸入參數:人員累積劑量結構矩陣◎回傳值:該矩陣資料筆數至主程式◎流程圖:與2.1read_person()同一模式。◎程式碼:17intread_database(structdatabaseytemp[MAX_ARRAY_SIZE],FILE*fp){inti;i=0;while(i<MAX_ARRAY_SIZE){fscanf(fp,"%d%d%s%f%f%f",&ytemp[i+1].depid,&ytemp[i+1].pid,&ytemp[i+1].name,&ytemp[i+1].yrdeep,&ytemp[i+1].yrshallow,&ytemp[i+1].yreye);if(!feof(fp)){i++;}else{returni;}}}2.3read_department()◎說明:將資料讀入部門資料結構陣列◎輸入參數:公司部門結構矩陣◎回傳值:該矩陣資料筆數至主程式◎流程圖:與2.1read_person()同一模式。◎程式碼:intread_department(structdepartmentdtemp[MAX_ARRAY_SIZE],FILE*fp){inti;i=0;18while(i<MAX_ARRAY_SIZE){fscanf(fp,"%d%s",&dtemp[i+1].depid,&dtemp[i+1].depname);if(!feof(fp)){i++;}else{returni;}}}192.4dose_convert()◎說明:將人員當月劑量讀值減去背景值並乘上劑量轉換因子,轉換為絕對劑量◎輸入參數:人員當月劑量讀值資料結構、人員當月劑量資料筆數◎回傳值:無◎流程圖:i=0Noi≤num_p結束Yesptemp[i].rdeep=((ptemp[i].rdeep)-(ptemp[i].bg))*cf_deepptemp[i].rshallow=((ptemp[i].rshallow)-(ptemp[i].bg))*cf_shallowptemp[i].reye=((ptemp[i].reye)-(ptemp[i].bg))*cf_eyei=i+1◎程式碼:voiddose_convert(structpersonptemp[MAX_ARRAY_SIZE],intnum_p){inti;for(i=1;i<=num_p;i++){/**/ptemp[i].rdeep=((ptemp[i].rdeep)-(ptemp[i].bg))*cf_deep;ptemp[i].rshallow=((ptemp[i].rshallow)-(ptemp[i].bg))*cf_shallow;ptemp[i].reye=((ptemp[i].reye)-(ptemp[i].bg))*cf_eye;20}}212.5cumulate_dose()◎說明:將每筆人員當月劑量資料讀出,依著人員累積劑量資料庫做比對。呼叫check副程式,若部門編號及員工編號相符(回傳值>0),則將當月劑量加入累積劑量中,若無部門編號及員工編號相符者(回傳值=0),則將該筆資料新增至累積劑量資料庫。每新增一筆則在計數器add中加1;呼叫副程式sort_department將新的人員累積劑量資料庫依照公司編號排序。加上add,回傳新的人員累最後,將原有人員累積劑量資料庫筆數(num_d)積劑量資料庫筆數(num_d)◎輸入參數:人員當月劑量結構矩陣、人員當月劑量資料筆數、人員累積劑量結構矩陣、人員累積劑量資料筆數◎回傳值:人員累積劑量資料筆數◎流程圖:22

add=0i=1Noi≤num_p呼叫sort_department(ytemp,num_d,add)Yesnum_d=num_d+add回傳num_d結束呼叫index=check(ytemp,num_d,ptemp[i].depid,ptemp[i].pid)ytemp[index].yrdeep=ytemp[index].yrdeep+ptemp[i].rdeepNoytemp[index].yrshallow=ytemp[index].yrshallow+ptemp[i].rshallowindex=0?ytemp[index].yreye=ytemp[index].yreye+ptemp[i].reyeYeslength=1Noytemp[length].depid=ptemp[i].depidytemp[length].pid=ptemp[i].pidytemp[length].depid≠0?Yesstrcpy(ytemp[length].name,ptemp[i].name)length=length+1ytemp[length].yrdeep=ptemp[i].rdeepytemp[length].yrshallow=ptemp[i].rshallowytemp[length].yreye=ptemp[i].reyeadd=add+1i=i+1◎程式碼:intcumulate_dose(structpersonptemp[MAX_ARRAY_SIZE],structdatabaseytemp[MAX_ARRAY_SIZE],intnum_p,intnum_d){intindex;/*check*/intadd;/**/intlength;/*inti;database*/add=0;/**/for(i=1;i<=num_p;i++)23{index=check(ytemp,num_d,ptemp[i].depid,ptemp[i].pid);/*checkdatabase*/if(index==0){/*index=0*//*databaselength*/length=1;/*=1*/while(ytemp[length].depid!=0)/*{depid*/length++;/*length1*/}/*"length"*/ytemp[length].depid=ptemp[i].depid;/*database*/ytemp[length].pid=ptemp[i].pid;/*database*/strcpy(ytemp[length].name,ptemp[i].name);/*database(11)*/ytemp[length].yrdeep=ptemp[i].rdeep;/*database*/ytemp[length].yrshallow=ptemp[i].rshallow;/*database*/ytemp[length].yreye=ptemp[i].reye;/*database*/add++;/*1*/}else{ytemp[index].yrdeep=ytemp[index].yrdeep+ptemp[i].rdeep;/*database()*/ytemp[index].yrshallow=ytemp[index].yrshallow+ptemp[i].rshallow;/*database()*/ytemp[index].yreye=ytemp[index].yreye+ptemp[i].reye;/*database()*/}24}sort_department(ytemp,num_d,add);num_d=num_d+add;/*returnnum_d;dtatbase*/}2.6check()◎說明:dip及pid分別表示人員當月劑量中的公司編號、人員編號。沿著人員累積劑量資料庫,逐一比對每一筆傳入副程式的資料。◎輸入參數:人員累積劑量結構矩陣、人員累積劑量資料筆數、人員當月劑量資料庫公司編號、當月劑量資料庫人員編號◎回傳值:有相符則回傳人員累積劑量資料庫中位址,無相符則回傳0◎流程圖:(見下頁)i=1ret_val=0Noi≤num_dYesytemp[i].depid=did且ytemp[i].pid=pid?Yesret_val=i回傳ret_valNoi=i+1結束25◎程式碼:intcheck(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d,intdid,intpid)/*10check*/{inti;intret_val;i=1;ret_val=0;/**/while(i<=num_d)/*database{*/if(ytemp[i].depid==did&ytemp[i].pid==pid)/**/{ret_val=i;/*break;*/}i++;}returnret_val;/*ret_val*/}2.7sort_department()◎說明:利用第九章排序中的Insert方法,將每筆新增資料依照部門編號往前進行檢查,將該筆新資料移到該公司最後一位。◎輸入參數:人員累積劑量結構矩陣、人員累積劑量資料筆數、新增資料筆數◎回傳值:無◎流程圖:26宣告tempj=num_d+1Noj≦num_d+add結束Yesi=jNoi≥1Yesytemp[i-1].depid>ytemp[i].depid?NoYestemp=ytemp[i-1]ytemp[i-1]=ytemp[i]ytemp[i]=tempi=i-1j=j+1◎程式碼:voidsort_department(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d,intadd){inti;intj;27structdatabasetemp;database/*tempswap*/*/for(j=(num_d+1);j<=num_d+add;j++){/*for(i=j;i>=1;i--){/**/if(ytemp[i-1].depid>ytemp[i].depid)/*/*{Insert*/*/temp=ytemp[i-1];/*ytemp[i-1]=ytemp[i];ytemp[i]=temp;swap()*/}}}}2.8sort_personid()◎說明:由第一家公司部門編號開始,以迴圈檢查部門編號相同者,計算各家公司的資料在人員累積劑量資料庫中位址的起始點(start)及終點(end)並在起點及終點定義出的範圍內,依照人員編號,進行氣泡排序。,◎輸入參數:人員累積劑量結構矩陣、公司部門結構矩陣、公司部門資料筆數、人員累積劑量資料筆數◎回傳值:無◎流程圖:(見下頁)28宣告tempend=0start=0i=1Noi≤num_depart結束Yescounter=0start=end+1j=1Noj≤num_databaseend=end+counterYesk=startytemp[j].depid=dtemp[i].depid?NoNok≤endYesYescounter=counter+1l=end–start+1j=j+1NoNol>kYesytemp[l-1].pid>ytemp[l].pidYestemp=ytemp[l-1]ytemp[l-1]=ytemp[l]ytemp[l]=templ=l-1k=k+1i=i+129◎程式碼:voidsort_personid(structdatabaseytemp[MAX_ARRAY_SIZE],structdepartmentdtemp[MAX_ARRAY_SIZE],intnum_depart,intnum_database){intcounter;/**/intend;/**/intstart;/**/structdatabasetemp;/*databasetempswap*/inti;intj;intk;intl;end=0;start=0;/**/for(i=1;i<=num_depart;i++)/**/{counter=0;/*counter*/start=end+1;/**/for(j=1;j<=num_database;j++)/*database~*/{if(ytemp[j].depid==dtemp[i].depid)/*databasejdtemp[i].depid*/{}counter++;/*counter1*/}end=end+counter;/*(counter)*/)*//*(for(k=start;k<=end;k++)/*{startend*/30for(l=end-start+1;l>k;l--)/*{*/if(ytemp[l-1].pid>ytemp[l].pid)/*{idswap*/temp=ytemp[l-1];ytemp[l-1]=ytemp[l];ytemp[l]=temp;}}}}}2.9link_overdose()◎說明:利用第十章串聯名單的方始,將劑量超出法規限度名單串聯起來◎輸入參數:人員累積劑量結構矩陣、人員累積劑量資料筆數◎回傳值:超出劑量名單資料筆數(headindex)◎流程圖:31i=1Noi≤num_dj=i+1YesNo回傳headindexj≤num_dytemp[i].yrdeep>criteria_deep或ytemp[i].yrshallow>criteria_shallow或ytemp[i].yreye>criteria_eyeYesNoytemp[i].yrdeep>criteria_deep或ytemp[i].yrshallow>criteria_shallow或ytemp[i].yreye>criteria_eyeNoYesheadindex=iYesi=i+1ytemp[i].reference=ji=jj=j+1◎程式碼:intlink_overdose(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d){inti;intj;intheadindex;i=1;while(i<=num_d)/*{*/if(ytemp[i].yrdeep>criteria_deep||ytemp[i].yrshallow>criteria_shallow||ytemp[i].yreye>criteria_eye){headindex=i;/*break;headindex*/}i++;}j=i+1;32while(j<=num_d){if(ytemp[j].yrdeep>criteria_deep||ytemp[j].yrshallow>criteria_shallow||ytemp[j].yreye>criteria_eye){ytemp[i].reference=j;i=j;}j++;}returnheadindex;}332.10write_database()◎說明:將新的資料庫資料輸出至檔案中。◎輸入參數:人員累積劑量資料、人員累積劑量資料筆數、檔案database_data2_fp◎回傳值:無◎流程圖:i=1Noi≤num_d關上FileYes在file中印入數值:ytemp[i].depid,ytemp[i].pid,結束ytemp[i].name,ytemp[i].yrdeep,ytemp[i].yrshallow,ytemp[i].yreyei=i+1◎程式碼:voidwrite_database(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d,FILE*fp){inti;i=1;while(i<=num_d){fprintf(fp,"%d%d%s%f%f%f\n",ytemp[i].depid,ytemp[i].pid,ytemp[i].name,ytemp[i].yrdeep,ytemp[i].yrshallow,ytemp[i].yreye);i++;}fclose(fp);34}2.11display_write_department()◎說明:螢幕上顯示各公司所有人員的累積劑量資料,並檢查各項劑量資料是否超出法規限度,若超出則在其劑量後方以星號(*)註記。最後將該資料輸出至檔案中◎輸入參數:人員累積劑量結構矩陣、公司部門結構矩陣、公司部門資料筆數、人員累積劑量資料筆數、檔案to_department_fp◎回傳值:無。◎流程圖:35end=0start=0i=1印出“----------打'*'號,表示該項劑量超出法規標準-------------“在螢幕上Noi≤num_depart結束Yes印出dtemp[i].depname的值在螢幕上end=end+counterk=start將dtemp[i].depname的值寫入file中印出“人員編號姓名深部劑量淺部劑量水晶體劑量“在螢幕上將“人員編號姓名深部劑量淺部劑量水晶體劑量“寫入file中Nok≦endYes印出ytemp[k].pid,ytemp[k].name的值在螢幕上counter=0將ytemp[k].pid,ytemp[k].name的值寫入file中start=end+1Yesytemp[k].yrdeep>criteria_deepNoj=1印出ytemp[k].yrdeep的值並加上*在螢幕上印出ytemp[k].yrdeep的值在螢幕上NoNoj≦num_database將ytemp[k].yrdeep的值並加上*寫入file中將ytemp[k].yrdeep的值寫入file中Yesytemp[j].depid=dtemp[i].depidYesytemp[k].yrshallow>NoYescriteria_shallowcounter=counter+1印出ytemp[k].yrshallow的值並加上*在螢幕上印出ytemp[k].yrshqllow的值在螢幕上將ytemp[k].yrshallow的值並加上*寫入file中將ytemp[k].yrshallow的值寫入file中j=j+1Yesytemp[k].yreye>criteria_eyeNo印出ytemp[k].yreye的值並加上*在螢幕上印出ytemp[k].yreye的值在螢幕上將ytemp[k].yreye的值並加上*寫入file中將ytemp[k].yreye的值寫入file中k=k+1i=i+136◎程式碼:voiddisplay_write_department(structdatabaseytemp[MAX_ARRAY_SIZE],structdepartmentdtemp[MAX_ARRAY_SIZE],intnum_depart,intnum_database,FILE*fp){inti;intj;intk;intcounter;intstart;intend;start=0;end=0;for(i=1;i<=num_depart;i++){printf("\n\t\t\t\t%s\n",dtemp[i].depname);/**/fprintf(fp,"\t\t\t\t%s\n",dtemp[i].depname);/**/printf("\t\t\t\t\n");fprintf(fp,"counter=0;start=end+1;\t\t\t\t\n");for(j=1;j<=num_database;j++)/*{*/if(ytemp[j].depid==dtemp[i].depid){counter++;}}end=end+counter;for(k=start;k<=end;k++){printf("%d\t\t%s\t",ytemp[k].pid,ytemp[k].name);fprintf(fp,"%d\t\t%s\t",ytemp[k].pid,ytemp[k].name);if(ytemp[k].yrdeep>criteria_deep)/*,*/{37printf("%f*\t",ytemp[k].yrdeep);/*fprintf(fp,"%f*\t",ytemp[k].yrdeep);*/}else{printf("%f\t",ytemp[k].yrdeep);fprintf(fp,"%f\t",ytemp[k].yrdeep);}if(ytemp[k].yrshallow>criteria_shallow){printf("%f*\t",ytemp[k].yrshallow);fprintf(fp,"%f*\t",ytemp[k].yrshallow);}else{printf("%f\t",ytemp[k].yrshallow);fprintf(fp,"%f\t",ytemp[k].yrshallow);}if(ytemp[k].yreye>criteria_eye){printf("%f*\n",ytemp[k].yreye);fprintf(fp,"%f*\n",ytemp[k].yreye);}else{printf("%f\n",ytemp[k].yreye);fprintf(fp,"%f\n",ytemp[k].yreye);}}}printf("\n'*'");}382.12display_write_gov()◎說明:在螢幕上顯示所有劑量超出法規限度人員的累積劑量資料並將該資料輸出至檔案中。◎輸入參數:人員累積劑量結構矩陣、公司部門結構矩陣、公司部門資料筆數、串連超出劑量名單資料筆數、檔案to_government_fp◎回傳值:無。◎流程圖:39

i=headindexi=1印出“劑量超出法規名單“在螢幕上將“劑量超出法規名單“寫入file中印出“單位名稱人員編號姓名深部劑量淺部劑量水晶體劑量“在螢幕上將“單位名稱人員編號姓名深部劑量淺部劑量水晶體劑量“寫入file中Noi≠0結束Yesnext=ytemp[i].referencedep=ytemp[i].depid在螢幕上印出數值:dtemp[dep].depname,ytemp[i].pid,ytemp[i].name,ytemp[i].yrdeep,ytemp[i].yrshallow,ytemp[i].yreye在file中印入數值:dtemp[dep].depname,ytemp[i].pid,ytemp[i].name,ytemp[i].yrdeep,ytemp[i].yrshallow,ytemp[i].yreyei=next◎程式碼:voiddisplay_write_gov(structdatabaseytemp[MAX_ARRAY_SIZE],structdepartmentdtemp[MAX_ARRAY_SIZE],intnum_depart,intheadindex,FILE*fp){inti;40intj;intnext;intdep;i=headindex;printf("\n======================================================================\n");printf("\n\t\t\t\t\n\n");fprintf(fp,"\n\t\t\t\t\n\n");printf("fprintf(fp,"while(i!=0){\t\t\t\t\n");\t\t\t\t\n");next=ytemp[i].reference;dep=ytemp[i].depid;printf("%s\t%d\t%s\t%f\t%f\t%f\t\n",dtemp[dep].depname,ytemp[i].pid,ytemp[i].name,ytemp[i].yrdeep,ytemp[i].yrshallow,ytemp[i].yreye);fprintf(fp,"%s\t%d\t%s\t%f\t%f\t%f\t\n",dtemp[dep].depname,ytemp[i].pid,ytemp[i].name,ytemp[i].yrdeep,ytemp[i].yrshallow,ytemp[i].yreye);i=next;}}41五、程式執行範例1.輸入資料A.輸入當月人員劑量資料當月劑量讀值檔(personpdata)001970200197030020010019710003011010105732901752519027103040030525100177251906525450272097029600197050020020040100200300197010030225100177000025100177105550019715B.輸入累積劑量資料累積劑量資料檔(databaseydata)0019702001970300197050019710002001002002002003003017020030732901725190630400302519027254502725100172510017251001700302C.輸入公司部門資料機構資料檔(departmentddata)42001002003004則經過讀取後,在陣列中當月人員劑量讀值結構陣列(pdata)內容如下所示:[1][2][3][4][5][6][7][8][9][10][11][12]001001002001003001002004002001003001970297030019710011073253025252591010172730176529019040010019045070510579705002015272917020600397010225010007025101005175797155累積劑量資料庫結構陣列(ydata)內容:[1][2][3][4][5][6][7][8][9]001001001001002002002003003970297039705971000100200301707325302525252525200290190400190450100100100301760000000003027271717170243公司部門結構陣列內容(ddata)內容:[1][2][3][4]0010020030042.轉換劑量(副程式dose_convert)人員當月劑量讀值減去背景值並乘上劑量轉換因子,轉換為絕對劑量。轉換因子定義於全域常數。絕對劑量=人(員當月劑量讀值-背景值)劑*量轉換因子以”張比利”為例,其本月劑量讀值為:1010105劑量轉換因子如下:cf_deep1.5cf_shallowcf_eye21因此,經由轉換後,張比利本月的絕對劑量為:7.5105544經過轉換後,機構人員的數據如下:[1][2][3][4][5][6][7][8][9][10][11][12]001001002001003001002004002001003001970297030019710017.510222.537.52710555703607901863708601281860121725101510579705002013057.54.527720623100003970102700271860100797157.55453.將本月劑量累積加入資料庫並將新加入的人員插入資料庫cumulate_dosecheck,呼叫副程式,尋找原有資料中是否有該人員,副程式若有該人員則進行劑量累加,若無該人則新增該人員資料入資料庫,而後呼叫副sort_department,將新增人員插入該公司名單最下方。程式執行結果如下所示,累積劑量為原資料庫內所儲存的累積劑量值,加上本月劑量,以”張比利”為例,在原有的資料庫中,其劑量資料為:7020030其本月劑量為:7.5105經累積後,其劑量為:77.521035其餘人員累積劑量如下表示,斜體字所示的累積劑量值,灰色格子表示的是新增的人員名單。[1]001970277.521035046[2][3][4][5][6][7][8][9][10][11][12]00100100100200200200300300400100197039705971000100200301175558605601190550131028628628612802970000000000067.547.532.552554434272727230520252014.50970197157.500sort_department排序,將新增人員放置到該單位名單的最後一位,新經由的資料庫名單為:[1][2][3][4][11][12][5][6][7][8][9][10]0010010010010010010020020020030030049702970397059710970197150010020030177.517555210860560119003529700000000000067.505507.547.532.552005501310286286286128443427272723520252014.5sort_personid4.利用氣泡排序法將各公司人員依照編號排序(副程式)47[11][1][2][3][4][12][5][6][7][8][9][10]0010010010010010010020020020030030049701970297039705971097150010020030100000000000000077.517555210860560119003529767.57.547.532.5525505501310286286286128443427272723520252014.55.串連超出劑量限度的名單(副程式link_overdose)[1][2][3][4][5][6][7][8][9][10][11][12]00100100100100100100200200200300300497019702970397059710971500100200301000077.517555210860560119003529734567.57.547.532.5525507055013102862862861284434272727238910110520252014.50486.將新的資料庫存起來(副程式write_database)將資料寫入檔案上,則檔案的內容如下所示:197011970219703197051971019715210.0000000.0000000.00000077.500000210.00000035.000000175.000000860.00000029.00000055.000000560.0000007.00000067.5000001190.00000055.0000007.5000000.0000000.00000047.500000550.00000044.00000032.5000001310.00000034.00000052.000000286.00000027.00000052.000000286.00000027.00000052.000000286.00000027.0000004.500000128.00000023.0000002223313241497.顯示並儲存各公司部門人員之劑量(副程式display_write_departmen在螢幕上顯示結果,將檢查葛向劑量資料是否超出法規限度,若超出則在其劑量後方以星號(*)註記,最後將資料寫入檔案。檔案內容如下所示:9701970297039705971097150.0000000.0000000.00000077.500000*210.00000035.000000175.000000*860.000000*29.00000055.000000*560.000000*7.00000067.500000*1190.000000*55.0000007.5000000.0000000.00000012347.500000550.000000*44.00000032.5000001310.000000*34.00000052.000000*286.00000027.0000001252.000000*286.00000027.00000052.000000*286.00000027.00000014.500000128.00000023.000000508.顯示並儲存劑量超出法規之人員名單(副程式display_write_gov)在螢幕上顯示所有劑量超出法規限度人員的累積劑量資料,並將該資料寫入檔案中。檔案內容如下所示:9702970397059710177.500000210.00000035.000000175.000000860.00000029.00000055.000000560.0000007.00000067.5000001190.00000055.00000047.500000550.00000044.00000032.5000001310.00000034.00000052.000000286.00000027.00000052.000000286.00000027.00000052.000000286.00000027.000000231251六、完整的程式碼#include<stdio.h>/**/#defineMAX_ARRAY_SIZE500#definecf_deep1.5/**/#definecf_shallow2#definecf_eye1#definecriteria_deep50#definecriteria_shallow500#definecriteria_eye150/**//**/#definePERSON_READING_FILENAME"import_idreading.txt"#definePERSON_DOSE_DATABASE_FILENAME"import_database.txt"#defineDEPARTMENT_FILENAME"import_dep_id.txt"52#defineOUTPUT_DEP_FILENAME"exp_department.txt"#defineOUTPUT_GOV_FILENAME"exp_government.txt"#defineOUTPUT_NEWDATABASE_FILENAME"exp_newdatabase.txt"/**/structperson{/**/intdepid;intpid;/*/**/*/charname[20];floatrdeep;floatrshallow;floatreye;/**//**//**//**/floatbg;/**/};structdatabase{/**/intdepid;intpid;/*/**/*/charname[20];floatyrdeep;floatyrshallow;floatyreye;/**//**//**//**/intreference;/**/};structdepartment/**/{intdepid;/**/*/chardepname[20];/*};/**//*----------------*/intread_person(structpersonptemp[MAX_ARRAY_SIZE],FILE*fp);/**/53intread_database(structdatabaseytemp[MAX_ARRAY_SIZE],FILE*fp);/**/intread_department(structdepartmentdtemp[MAX_ARRAY_SIZE],FILE*fp);/**//*----------------*/voiddose_convert(structpersonptemp[MAX_ARRAY_SIZE],intnum_p);/*----------------*/intcumulate_dose(structpersonptemp[MAX_ARRAY_SIZE],structdatabaseytemp[MAX_ARRAY_SIZE],intnum_p,intnum_d);intcheck(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d,intdid,intpid);/*10*/voidsort_department(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d,intadd);/*database,*/voidsort_personid(structdatabaseytemp[MAX_ARRAY_SIZE],structdepartmentdtemp[MAX_ARRAY_SIZE],intnum_depart,intnum_database);/*database,*//*--------overdose--------*/intlink_overdose(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d);/*----------------*/voidwrite_database(structdatabaseytemp[MAX_ARRAY_SIZE],intnum_d,FILE*fp);/**/voiddisplay_write_department(structdatabaseytemp[MAX_ARRAY_SIZE],structdepartmentdtemp[MAX_ARRAY_SIZE],intnum_depart,intnum_database,FILE*fp);/**/voiddisplay_write_gov(structdatabaseytemp[MAX_ARRAY_SIZE],structdepartmentdtemp[MAX_ARRAY_SIZE],intnum_depart,intheadindex,FILE*fp);/**//*==================================================================*//**//*=================================================================*/main(){54/**/FILE*person_data_fp;structpersonpdata[MAX_ARRAY_SIZE];intnum_person;/**/FILE*database_data_fp;structdatabaseydata[MAX_ARRAY_SIZE];intnum_database;/**/FILE*depart_data_fp;structdepartmentddata[MAX_ARRAY_SIZE];intnum_depart;/**/intheadindex;/**/FILE*database_data2_fp;/*database*/database_data2_fp=fopen(OUTPUT_NEWDATABASE_FILENAME,"a");FILE*to_department_fp;/**/to_department_fp=fopen(OUTPUT_DEP_FILENAME,"a");FILE*to_government_fp;/**/to_government_fp=fopen(OUTPUT_GOV_FILENAME,"a");/**/if(!(person_data_fp=fopen(PERSON_READING_FILENAME,"r"))){printf("personaldosefileisnotexist\n");}if(!(database_data_fp=fopen(PERSON_DOSE_DATABASE_FILENAME,"r"))){printf("databasefileisnotexist\n");}55if(!(depart_data_fp=fopen(DEPARTMENT_FILENAME,"r"))){printf("company/departmentfileisnotexist\n");}/**/num_person=read_person(pdata,person_data_fp);fclose(person_data_fp);/**/num_database=read_database(ydata,database_data_fp);/*fclose(database_data_fp);*/num_depart=read_department(ddata,depart_data_fp);fclose(depart_data_fp);/**//**/dose_convert(pdata,num_person);/**/num_database=cumulate_dose(pdata,ydata,num_person,num_database);/**/sort_personid(ydata,ddata,num_depart,num_database);/**/headindex=link_overdose(ydata,num_database);/**/write_database(ydata,num_database,database_data2_fp);/**/display_write_department(ydata,ddata,num_depart,num_database,to_department_fp);/**/display_write_gov(ydata,ddata,num_depart,headindex,to_government_fp);getch();}/*=================================================================*/56/**//*=================================================================*//*-----------------------------------------------------------------------*//*/*/*read_person*/""*/*//*-----------------------------------------------------------------------*/intread_person(structpersonptemp[MAX_ARRAY_SIZE],FILE*fp){inti;i=0;while(i<MAX_ARRAY_SIZE)/*/*iMAX_ARRAY_SIZE*/{fscanf(fp,"%d%d%s%f%f%f%f",&ptemp[i+1].depid,&ptemp[i+1].pid,ptemp*/&ptemp[i+1].name,&ptemp[i+1].rdeep,&ptemp[i+1].rshallow,&ptemp[i+1].reye,&ptemp[i+1].bg);if(!feof(fp))/**/{i++;}/*i1*/else{returni;}/*i*/}}/*-----------------------------------------------------------------------*//*/*read_database*/*//*-----------------------------------------------------------------------*/intread_database(structdatabaseytemp[MAX_ARRAY_SIZE],FILE*fp)57{inti;i=0;while(i<MAX_ARRAY_SIZE){fscanf(fp,"%d%d%s%f%f%f",&ytemp[i+1].depid,&ytemp[i+1].pid,&ytemp[i+1].name,&ytemp[i+1].yrdeep,&ytemp[i+1].yrshallow,&ytemp[i+1].yreye);if(!feof(fp)){i++;}else{returni;}}}/*-----------------------------------------------------------------------*//*/*read_department*/*//*-----------------------------------------------------------------------*/intread_department(structdepartmentdtemp[MAX_ARRAY_SIZE],FILE*fp){inti;i=0;while(i<MAX_ARRAY_SIZE){fscanf(fp,"%d%s",&dtemp[i+1].depid,&dtemp[i+1].depname);if(!feof(fp)){i++;}else58{}returni;}}/*-----------------------------------------------------------------------------------------------------*//*/*dose_convert*/*//*------------------------------------------------------------------------------------------------------*/voiddose_convert(structpersonptemp[MAX_ARRAY_SIZE],intnum_p){inti;for(i=1;i<=num_p;i++){/**/ptemp[i].rdeep=((ptemp[i].rdeep)-(ptemp[i].bg))*cf_deep;ptemp[i].rshallow=((ptemp[i].rshallow)-(ptemp[i].bg))*cf_shallow;ptemp[i].reye=((ptemp[i].reye)-(ptemp[i].bg))*cf_eye;}}/*-----------------------------------------------------------------------------------------------------------*//*/*/*/*/*/*/*/*/*/*/*/*cumulate_dose*/*/*/check*/(>0)*/(=0)*/*/add1*/sort_department*/*/(num_d)add*/(num_d)*/59/*-------

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论