【問題2】(5分)
若系統(tǒng)中有多個發(fā)送進程和接收進程,進程間的工作流程如圖4-2所示,其中空(1)~(4)的內(nèi)容與圖4-1相同。發(fā)送進程產(chǎn)生消息并順序地寫入環(huán)形緩沖區(qū)BUFFER,接受者進程順序地從BUFFER中取消息,且每條消息只能讀取一次。為了保證進程間的正常通訊,增加了信號量SA和SB。
、 請說明信號量SA和SB的物理意義,并在圖4-2中的空(5)和空(6)處填入正確的內(nèi)容。
、 請從圖4-2的(a)~(1)中選擇四個位置正確地插入P(SA)、V(SA)、P(SB)、V(SB)。
【圖4-2]】
【問題3】(6分)
設系統(tǒng)中只有進程A和進程B,除了互斥地使用CPU和打印機R外,進程A和B不使用其他資源。另外,進程B的優(yōu)先級比A高,而進程A先于B準備好。進程A和B的執(zhí)行情況如圖4-3所示,其中粗實線表示進程在執(zhí)行中,細實線表示打印機R在使用中。(每個進程具有三種狀態(tài):運行,就緒和阻塞)
請說明進程A和B在圖4-3所示的T1、T2、T3、T4時刻所處的狀態(tài);若是阻塞狀態(tài),請說明阻塞原因。
【圖4-3】
試題五(15分,每空3分)
閱讀下列函數(shù)說明和C代碼,將應填入(n)處的字句寫在答題紙的對應欄內(nèi)。
【說明】
函數(shù)int Toplogical (LinkedWDigraph G)的功能是對圖G中的頂點進行拓撲排序,并返回關鍵路徑的長度。其中圖G表示一個具有n個頂點的AOE-網(wǎng),圖中頂點從1~n依次編號,圖G的存儲結構采用鄰接表表示,其數(shù)據(jù)類型定義如下:
typedef struct Gnode{ /*鄰接表的表結點類型*/
int adjvex; /*鄰接頂點編號*/
int weight; /*弧上的權值*/
struct Gonde*nextare; /*指示下一個弧的結點*/
}Gnode;
typedef struct Adjlist{ /*鄰接表的頭結點類型*/
char vdata; /*頂點的數(shù)據(jù)信息*/
struct Gnode*Firstadj; /*指向鄰接表的第一個表結點*/
}Adjlist;
typedef struct LinkedWDigraph{ /*圖的類型*/
int n ,e; /*圖中頂點個數(shù)和邊數(shù)*/
struct Adjlist head; /*指向圖中第一個頂點的鄰接表的頭結點*/
}LinkedWDigraph;
例如,某AOE-網(wǎng)如圖5-1所示,其鄰接表存儲結構如圖5-2所示。
【函數(shù)】
int Toplogical(LinkedWDigraph G)
{Gnode *p;
int j,w,top=0;
int Stack,ve,*indegree;
ve=(int )mallloc(G.n+1)*sizeof(int));
indegree=(int*)malloc((G.n+1)*sizeof(int)); /*存儲網(wǎng)中個頂點的入度*/
Stack=(int*)malloc((G.n+1)*sizeof(int)); /*存儲入度為0的頂點的編號*/
If (!ve||!indegree||!Stack) exit(0);
for (j=1;j<=G.n;j++){
ve[j]=0;indegree[j]=0;
} /*for*/
for (j=1;j<=G.n;j++) { /*求網(wǎng)中各頂點的入度*/
p=G.head[j].Firstadj;
while (p) {
__(1)__; p=p->nextarc;
} /*while*/
} /*for*/
for (j=1;j<=G.n;j++) /求網(wǎng)中入度為0的頂點并保存其編號*/
if (!indegree[j]) Stack[++top]=j;
while (top>0){
w=__(2)__;
printf(“%c”,G.head[w].vdata);
p=G.head[w].Firstadj;
while (p) {
__(3)__;
if (!indegree[p->adjvex])
Stack[++top]=p->adjvex;
If(__(4)__)
Ve[p->adjvex]=ve[w]+p->weight;
P=p->nextarc;
}/*while*/
return(5);
} /*Toplogical*/
試題六(15分,每空3分)
閱讀下列函數(shù)說明和C++代碼,將應填入(__n__)處的字句寫在答題紙的對應欄內(nèi)。
【說明】
通常情況下,用戶可以對應用系統(tǒng)進行配置,并將配置信息保存在配置文件中,應用系統(tǒng)在啟動時首先將配置文件加載到內(nèi)存中,這些內(nèi)存配置信息應該有且僅有一份。
下面的代碼應用了單身模式(Singleton)以保證Configure類只能有一個實例。這樣,Configure類的使用者無法定義該類的多個實例,否則會產(chǎn)生編譯錯誤。
【C++代碼】
#include <iostream.h>
class Configure {
__(1)__;
Configure() {}; //構造函數(shù)
Public;
Static Configure*Instance();
Public;
Int GetConfigureData() {return data;} //獲取配置信息
Int SetConfigureDate(int m_data)
{ data=m_data; return data; } //設置配置信息
private:
static Configure*_instance;
int data; //配置信息
};
__(2)__=NULL;
Configure * Configure;;Instance() {
If (_instance= =NULL) {
_instance=__(3)__;
//加載配置文件并設置內(nèi)存配置信息,此處省略
}
return__(4)__;
}
void main() {
Configure*t=NULL;
t=__(5)__;
int d=t->GetConfigureData();
//獲取配置信息后進行其它工作,此處省略
}
試題七(15分,每空3分)
【說明】
類Queue表示隊列,類中的方法如下表所示。
isEmpty() |
判斷隊列是否為空。如果隊列不為空,返回true;否則,返回false。 |
Enpueue(object newNode) |
入隊操作。 |
Dequeue() |
出隊操作。如果隊列為空,則拋出異常。 |
類Node表示隊列中的元素;類emptyQueueException給出了隊列操作中的異常處理操作。
【JAVA代碼】
public class testmain { //主類
public static viod main (string args[]){
Queue q= new queue;
q.enqueue(“first!”);
q.enqueue(“second!”);
q.enqueue(“third!”);
__(1)__ {
while(true)
system.out.println(q.dequeue());
}
catch(__(2)__){}
}
public class queue { //隊列
node m_firstnode;
public queue(){m_firstnode=null;}
public Boolean isempty(){
if (m_firstnode= =null) return true;
else return false;
}
public viod enqueue(object newnode){ //入隊操作
node next = m_firstnode;
if (next = = null) m_firstnode=new node(newnode);
else {
while(next.getnext()!=null) next=next.getnext();
next.setnext(new node(newnode));
}
}
public object dequeue() __(3)__ { //出隊操作
object node;
if (is empty())
__(4)__; //隊列為空,拋出異常
else {
node =m_firstnode.getobject();
m_firstnode=m_firstnode.getnext();
return node;
}
}
}
public class node{
object m_data;
node m_next;
public node(object data) {m_data=data; m_next=null;}
public node(object data,node next) {m_data=data; m_next=next;}
public void setobject(object data) {m_data=data; }
public object getobject(object data) {return m_data;}
public void setnext(node next) {m_next=next;}
public node getnext() {return m_next;}
}
public class emptyqueueexception extends (5) {
public emptyqueueexception() {
system.out.println(“隊列已空!”);
}
}
答 案
轉帖于:軟件水平考試_考試吧
- 推薦給朋友
- 收藏此頁
·2008年下半年軟考信息系統(tǒng)項目管理師試題(下午II) (2008-12-21 22:39:30)
·2008年下半年計算機軟考網(wǎng)絡工程師試題(下午) (2008-12-21 22:26:13)
·2008下半年軟考系統(tǒng)分析師考試試題(下午)II (2008-12-21 22:20:49)
·2008年下半年計算機軟考程序員試題(下午) (2008-12-21 22:18:18)
·2008年下半年計算機軟考程序員試題(上午) (2008-12-21 22:11:38)
如果軟件水平考試網(wǎng)所轉載內(nèi)容不慎侵犯了您的權益,請與我們聯(lián)系
![](/images/800mail.gif)