




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、實驗六:設備管理-device.c實驗目的:1、對理論課中學習的設備管理中的概念作進一步的理解; 2、明白設備管理的主要任務; 3、了解設備管理任務的主要實現(xiàn)方法; 4、通過編程,學會獨占設備的分配、回收等主要算法的原理;實驗內(nèi)容:1、 編寫程序,由必要的數(shù)據(jù)結(jié)構(gòu)、主函數(shù)、設備分配函數(shù)及設備回收函數(shù)構(gòu)成,實現(xiàn)對獨占設備的分配與回收的模擬。2、 模擬實驗的程序包括建立設備類表和設備表的程序段,分配設備和回收設備的函數(shù),分配設備要求輸入作業(yè)名、設備類名和相對號;回收設備要求輸入作業(yè)名和設備類名。#include#include#include#include#include#define fals
2、e 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 allocate errno); r
3、eturn(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=mm; reclaim(
4、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+; equip_typei.rema
5、in=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; equip_type1
6、.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:); scanf(%d,&a);
7、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: printf(n the t
8、able 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-Nombern); for(i
9、=0;im;i+) printf(%3d%7d%8d%10s%7dn, equipmenti.number,equipmenti.status,equipmenti.remain,equipmenti.jobname,equipmenti.lnumber); 執(zhí)行結(jié)果截圖中文注釋device003.c文件#include#include#include#include#include#define false 0#define true 1#define n 3 /假設系統(tǒng)有3類設備#define m 5 /假設系統(tǒng)有5個設備struct char type10; /設備類名 int coun
10、t; /擁有設備數(shù)量 int remain; /現(xiàn)存的可用設備數(shù)量 int address; /該類設備在設備表中的起始地址 equip_typen; /設備類表定義,假設系統(tǒng)有n個設備類型struct int number; /設備絕對號 int status; /設備狀態(tài)可否使用 int remain; /設備是否已分配 char jobname10; /占有設備的作業(yè)名 int lnumber; /設備相對號equipmentm; /設備表定義,假設系統(tǒng)有m個設備allocate(char *job,char *type,int mm) int i,t,j; /查詢該類型設備 i=0;
11、while(i=n) printf(無該類設備,設備分配請求失敗); return(false); /所需設備現(xiàn)在可用數(shù)量不足 if(equip_typei.remain1) printf(該類設備數(shù)量不足,設備分配請求失敗); return(false); t=equip_typei.address; /得到該類設備在設備表中的起始地址 while(!(equipmentt.status=1&equipmentt.remain=0) t+; /填寫作業(yè)名、相對號,狀態(tài)更改為“已分配” equip_typei.remain-; equipmentt.remain=1; strcpy(equip
12、mentt.jobname,job); equipmentt.lnumber=mm; /設備分配函數(shù)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; /得到該設備的數(shù)量 k=0; nn=t+j; for(;tnn;t+) if(strcmp(equipmentt.jobname,job)=0&equipmentt.remai
13、n=1) equipmentt.remain=0; k+; equip_typei.remain=equip_typei.remain+k; if(k=0) printf(作業(yè)沒有使用該類設備); /設備回收函數(shù)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)
14、; /設備類型:打印機 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-分配, 2-回收, 3-
15、顯示); printf(n清選擇功能項:); scanf(%d,&a); switch(a) case 0: /a=0程序結(jié)束 exit(0); case 1: /a1 分配設備 printf(請輸入作業(yè)名、作業(yè)所需設備類型和設備相對號:n); scanf(%s%s%d,job,type,&mm); allocate(job,type,mm); /分配設備 break; case 2: /a2 回收設備 printf(請輸入作業(yè)名和作業(yè)要歸還的設備類型:n); scanf(%s%s,job,type); reclaim(job,type); break; case 3: /a3 顯示設備類表和設備表的內(nèi)容 printf(n 輸出設備類表:n); printf( 設備類型 設備數(shù)量 空閑設備數(shù)量n); for(i=0;in;i+) printf(%8s%9d%8dn,equip_typei.type,equip_typei.count,eq
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 各產(chǎn)品種類銷售數(shù)據(jù)統(tǒng)計表
- 文化創(chuàng)意項目推廣與服務合同
- 餐飲公司合作合同書
- 農(nóng)業(yè)生產(chǎn)機械化推進作業(yè)指導書
- 公司內(nèi)部培訓通知及安排
- 農(nóng)業(yè)金融合作與支持協(xié)議書
- 太陽照常升起電影讀后感
- 食品衛(wèi)生與安全測試題及答案詳解
- 房地產(chǎn)前期策劃協(xié)議
- 高中英語課本短劇表演實踐課教學教案
- 安徽省江南十校2024屆高三3月聯(lián)考數(shù)學試卷 含解析
- 人教版 七年級英語下冊 UNIT 1 單元綜合測試卷(2025年春)
- 2025年遼寧醫(yī)藥職業(yè)學院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 《痛經(jīng)的預防保健》課件
- 幼兒園三會一課會議記錄
- MOOC 中國傳統(tǒng)藝術-篆刻、書法、水墨畫體驗與欣賞-哈爾濱工業(yè)大學 中國大學慕課答案
- 人教版pep小學四年級英語下冊全冊完整
- 閩教版2023版3-6年級全8冊英語單詞表
- 高中有機化學必修模塊與選修模塊的銜接
- BBC美麗中國英文字幕
- 《自然保護區(qū)綜合科學考察規(guī)程》
評論
0/150
提交評論