資源簡介
關于裝備可靠性分析中的故障樹程序,需要的可以看一看,寫的不好請多包涵。
C++控制臺程序

代碼片段和文件信息
#include?
#include?
#include?
using?namespace?std;
typedef?struct?CTBox{?
int?type;//0-與;1-或;2-葉子節點;3-根節點
????int?child;
string?data;
????CTBox?*?Next;?//孩子鏈表頭指針
}?CTBox*pCTBox;
typedef?struct{
????CTBox?nodes[100];
????int?nr;?//結點數葉子節點數
}Tree;
bool?equal(char?*?testchar?*?temp);//函數原型
bool?noleaf(Tree?ftaint?pos);//識別非葉子節點
int?findFTA(Tree?ftachar?*?temp);//匹配字符對應節點在向量中的序號
int?findFTAstr(Tree?ftastring?str);//匹配str對應節點的向量序號
int?findRoot(Tree?ftastring?table[100][100]?int?j);//尋找第一個非葉子節點-2-沒有,-1-空表,0,1,2-有
int?MoveRootStr(Tree?ftastring?table[100][100]int?iint?j);//把分支節點移到開頭
int?CountFlag(string?table[100][100]int?iint?j);//計算*個數
void?OutPut(string?table[100][100]int?j);//輸出割集
bool?IfHasRoot(Tree?ftastring?table[100][100]int?iint?j);
void?main()
{
cout<<“************************************************\n“;
cout<<“|?????????????????故障樹程序???????????????????|\n“;
cout<<“|??????????????王濤201105017009????????????????|\n“;
cout<<“|??????????????下行法求最小割集????????????????|\n“;
cout<<“************************************************\n“;
int?i=0j=0k=0l=0count=0;//循環變量
Tree?fta;
cout<<“input?the?number?of?nodes(n)?and?leaves(r):\n??????[n-r=number?of?statements]\n“;
cin>>fta.n>>fta.r;//輸入節點數
cout<<“input?the?statements:\n“;
char?input[100];
char?temp[50];
int?root=0;//建樹到哪了
for(i=0;i {
cin>>input;
int?len=0;//計算input的長度
for(len=0;;len++)
if(input[len]==‘\0‘)
break;
int?temk;
for(k=0;input[k]!=‘=‘;k++)
{
temp[k]=input[k];
}
temp[k]=‘\0‘;
if(count==0)?//第一句付給根
{
fta.nodes[0].data.assign(temp);
count++;
}
root=findFTA(ftatemp);//給哪個節點連接子節點
for(l=0;l {
if(input[l]==‘*‘)
{
fta.nodes[root].type=0;
break;
}
if(input[l]==‘+‘)
{
fta.nodes[root].type=1;
break;
}
}
int?sum=0;
CTBox?*?temchild*pre;
pre=&(fta.nodes[root]);
while(input[k]!=‘\0‘)
{
k++;//g1=‘g‘2+g3
temk=k;
for(k=k;input[k]!=‘+‘?&&?input[k]!=‘*‘?&&?input[k]!=‘\0‘;k++)
{
temp[k-temk]=input[k];
sum++;
}
temp[k-temk]=‘\0‘;
fta.nodes[count].data.assign(temp);
count++;//指向向量的游標begin?with?0
????temchild=new?CTBox;//不能?直接CTBox?temchild否則它只新建temchild一次
temchild->child=count-1;
temchild->Next=NULL;
if(sum==1)
{
pre->Next=temchild;
pre=temchild;
}
else
{
pre->Next=temchild;
pre=temchild;
}
}
}//end?of?建立故障樹
for(j=0;j {
if(fta.nodes[j].type!=1?&&?fta.nodes[j].type!=0)
fta.nodes[j].type=2;
}
cout<<“************************************************\n“;
cout<<“故障樹向量如下:\n【序號-節點名-節點類型(0-與門、1-活門、2-葉子)】\n“;
for(j=0;j cout< cout<<“************************************************\n“;
//*************下行法求割集********
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-05-11?09:42??下行法求最小割集\
?????文件???????10240??2014-05-11?09:42??下行法求最小割集\Thumbs.db
?????文件????????9549??2014-04-24?00:02??下行法求最小割集\WangTao_FTA_test.cpp
?????文件??????131127??2014-05-11?09:42??下行法求最小割集\輸入實例.png
評論
共有 條評論