




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優質文檔-傾情為你奉上實驗六:設備管理-device.c實驗目的:1、對理論課中學習的設備管理中的概念作進一步的理解; 2、明白設備管理的主要任務; 3、了解設備管理任務的主要實現方法; 4、通過編程,學會獨占設備的分配、回收等主要算法的原理;實驗內容:1、 編寫程序,由必要的數據結構、主函數、設備分配函數及設備回收函數構成,實現對獨占設備的分配與回收的模擬。2、 模擬實驗的程序包括建立設備類表和設備表的程序段,分配設備和回收設備的函數,分配設備要求輸入作業名、設備類名和相對號;回收設備要求輸入作業名和設備類名。#include#include#include#include#includ
2、e#define false 0#define true 1#define n 3#define m 5struct char type10; int count; int remain; int address; equip_typen;struct int number; int status; int remain; char jobname10; int lnumber;equipmentm;allocate(char *job,char *type,int mm) int i,t,j; i=0; while(i=n) printf(No the device,device alloc
3、ate errno); return(false); if(equip_typei.remain1) printf(there is no much device,the request of device is failure); return(false); t=equip_typei.address; while(!(equipmentt.status=1&equipmentt.remain=0) t+; equip_typei.remain-; equipmentt.remain=1; strcpy(equipmentt.jobname,job); equipmentt.lnumber
4、=mm; reclaim(char *job,char *type) int i,t,j,k,nn; i=0; while(i=n) printf(there is no this device,the device reclaim is failure); return(false); t=equip_typei.address; j=equip_typei.count; k=0; nn=t+j; for(;tnn;t+) if(strcmp(equipmentt.jobname,job)=0&equipmentt.remain=1) equipmentt.remain=0; k+; equ
5、ip_typei.remain=equip_typei.remain+k; if(k=0) printf(job is not use this device); main() char job10; int i,mm,a; char type10; strcpy(equip_type0.type,input) ; equip_type0.count=2; equip_type0.remain=2; equip_type0.address=0; strcpy(equip_type1.type,printer); equip_type1.count=3; equip_type1.remain=3
6、; equip_type1.address=2; strcpy(equip_type2.type,disk); equip_type2.count=4; equip_type2.remain=4; equip_type2.address=5; for(i=0;i10;i+) equipmenti.number=i; equipmenti.status=1; equipmenti.remain=0; while(1) printf(n0-exit, 1-allocate, 2-recycle, 3-display); printf(nplease select the function:); s
7、canf(%d,&a); switch(a) case 0: exit(0); case 1: printf(please input the name of the job,type,N-device:n); scanf(%s%s%d,job,type,&mm); allocate(job,type,mm); break; case 2: printf(please input the name of the job and the type of the device:n); scanf(%s%s,job,type); reclaim(job,type); break; case 3: p
8、rintf(n the table of output device:n); printf(device type device number Idle device numbern); for(i=0;in;i+) printf(%8s%9d%8dn,equip_typei.type,equip_typei.count,equip_typei.remain); printf(-n); printf(output device table:n); printf(juedui-Nomber best/bed allocated/No-allocated Name-job xiang-dui-No
9、mbern); for(i=0;im;i+) printf(%3d%7d%8d%10s%7dn, equipmenti.number,equipmenti.status,equipmenti.remain,equipmenti.jobname,equipmenti.lnumber); 執行結果截圖中文注釋device003.c文件#include#include#include#include#include#define false 0#define true 1#define n 3 /假設系統有3類設備#define m 5 /假設系統有5個設備struct char type10; /
10、設備類名 int count; /擁有設備數量 int remain; /現存的可用設備數量 int address; /該類設備在設備表中的起始地址 equip_typen; /設備類表定義,假設系統有n個設備類型struct int number; /設備絕對號 int status; /設備狀態可否使用 int remain; /設備是否已分配 char jobname10; /占有設備的作業名 int lnumber; /設備相對號equipmentm; /設備表定義,假設系統有m個設備allocate(char *job,char *type,int mm) int i,t,j; /
11、查詢該類型設備 i=0; while(i=n) printf(無該類設備,設備分配請求失敗); return(false); /所需設備現在可用數量不足 if(equip_typei.remain1) printf(該類設備數量不足,設備分配請求失敗); return(false); t=equip_typei.address; /得到該類設備在設備表中的起始地址 while(!(equipmentt.status=1&equipmentt.remain=0) t+; /填寫作業名、相對號,狀態更改為“已分配” equip_typei.remain-; equipmentt.remain=1;
12、 strcpy(equipmentt.jobname,job); equipmentt.lnumber=mm; /設備分配函數reclaim(char *job,char *type) int i,t,j,k,nn; i=0; while(i=n) printf(無該類設備,設備回收失敗); return(false); t=equip_typei.address; /得到該類型設備在設備表中的起始地址 j=equip_typei.count; /得到該設備的數量 k=0; nn=t+j; for(;tnn;t+) if(strcmp(equipmentt.jobname,job)=0&equ
13、ipmentt.remain=1) equipmentt.remain=0; k+; equip_typei.remain=equip_typei.remain+k; if(k=0) printf(作業沒有使用該類設備); /設備回收函數main() char job10; int i,mm,a; char type10; /設備類初始化 strcpy(equip_type0.type,input) ; /設備類型:輸入設備 equip_type0.count=2; equip_type0.remain=2; equip_type0.address=0; strcpy(equip_type1.
14、type,printer); /設備類型:打印機 equip_type1.count=3; equip_type1.remain=3; equip_type1.address=2; strcpy(equip_type2.type,disk); /設備類型:磁盤 equip_type2.count=4; equip_type2.remain=4; equip_type2.address=5; for(i=0;i10;i+) equipmenti.number=i; equipmenti.status=1; equipmenti.remain=0; while(1) printf(n0-退出, 1
15、-分配, 2-回收, 3-顯示); printf(n清選擇功能項:); scanf(%d,&a); switch(a) case 0: /a=0程序結束 exit(0); case 1: /a1 分配設備 printf(請輸入作業名、作業所需設備類型和設備相對號:n); scanf(%s%s%d,job,type,&mm); allocate(job,type,mm); /分配設備 break; case 2: /a2 回收設備 printf(請輸入作業名和作業要歸還的設備類型:n); scanf(%s%s,job,type); reclaim(job,type); break; case 3: /a3 顯示設備類表和設備表的內容 printf(n 輸出設備類表:n); printf( 設備類型 設備數量 空閑設備數量n); for(i=0;in;i+) printf(%8s%9d%8dn,equip_typei.type,equip_typei.count,equip_type
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 羽毛球場地租賃合同范文榜樣
- 技術總監合同翻譯
- 多功能會議室租賃合同
- 廚衛設備定制合同協議
- 自愿放棄繳納社保協議合同
- 【世界銀行】指導說明
- 企業與員工勞動合同范例
- 2025簡易水泥廠承包合同范本
- 2025園林綠化工程項目施工監理合同
- 2025寫字樓租賃合同業主使用
- 空調維保投標方案(技術方案)
- 幼兒園中班語言繪本《來喝水吧》微課件
- 允許一切發生:過不緊繃松弛的人生
- 三農產品直播帶貨策劃方案-
- 《囊螢夜讀》-課件
- 西雙版納羅盤再生能源有限公司云南景洪市城市生活垃圾處理場沼氣發電項目環評報告
- 老人智能手環方案可行性研究報告
- 河南省建筑工程定額說明和計算規則
- ICICLE之禾陳列調研
- GB/T 42172-2022精油產品標簽標識通則
- 課程思政教學展示-空巢老人學與思
評論
0/150
提交評論