From fc686f751fc224b331bae2f1ee7b26b603c04634 Mon Sep 17 00:00:00 2001 From: robot <33337344+hanzenglong@users.noreply.github.com> Date: Thu, 14 Dec 2017 19:31:22 +0800 Subject: [PATCH] C++for P11,P12andP13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这是之前修改的三个程序,之后尝试修改P34,但不能成功,现在仅上传这些 --- Codes/p11/p11.cpp | 155 ++++++++++++++++++++++++++++++++++++++++++++++ Codes/p12/p12.cpp | 26 ++++++++ Codes/p13/p13.cpp | 30 +++++++++ 3 files changed, 211 insertions(+) create mode 100644 Codes/p11/p11.cpp create mode 100644 Codes/p12/p12.cpp create mode 100644 Codes/p13/p13.cpp 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