diff --git a/Codes/p11/p11.cpp b/Codes/p11/p11.cpp new file mode 100644 index 0000000..3744ccc --- /dev/null +++ b/Codes/p11/p11.cpp @@ -0,0 +1,155 @@ +#include +#include +#include +using std::string; + + +double temp[4][5]; +double temp1[5][6]; + + +double compEntropy(double a[][5]) //ěŘ +{ + double sum = 0; + int n = sizeof(a) / sizeof(double); + for(int i = 0;i < 4;i++) + for(int j = 0;j < 5;j++) + sum+=-a[i][j]*(log(a[i][j])/log(2)); + return sum; +} + +void output(double a[][5],int nRow,int nCol) //matrix output +{ + for(int i = 0;i < nRow;i++) + { + for(int j = 0;j < nCol;j++) + cout< +int main() +{ + double p[2],p1[2]; + double pCan = 0.001; + double pNon = 0.999; + char *z = "positive"; + //z = 'negative'; + double pPosCan = 0.8; + double pPosNon = 0.1; + if("positive"==z) + { + p[0] = pPosCan * pCan; + p[1] = pPosNon * pNon; + } + else + { + p[0] = (1-pPosCan) * pCan; + p[1] = (1-pPosNon) * pNon; + } + p1[0] = p[0] / (p[0]+p[1]); + p1[1] = p[1] / (p[0]+p[1]); + cout<<"The probability of having cancer given the positive test:\n"< + +int ave(int a[],int n) +{ + int sum = 0; + for(int i=0;i