From be251991399234d452799930870e11cdcac93b4e Mon Sep 17 00:00:00 2001 From: Luo Xiang <33339892+XiangLaw@users.noreply.github.com> Date: Sat, 9 Dec 2017 21:50:24 +0800 Subject: [PATCH 1/3] Codes.c++ --- P1.cpp | 17 +++++++++++++ P10.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P12.cpp | 35 +++++++++++++++++++++++++ P14.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++ P4.cpp | 31 ++++++++++++++++++++++ P5.cpp | 55 +++++++++++++++++++++++++++++++++++++++ p13.cpp | 43 +++++++++++++++++++++++++++++++ 7 files changed, 318 insertions(+) create mode 100644 P1.cpp create mode 100644 P10.cpp create mode 100644 P12.cpp create mode 100644 P14.cpp create mode 100644 P4.cpp create mode 100644 P5.cpp create mode 100644 p13.cpp diff --git a/P1.cpp b/P1.cpp new file mode 100644 index 0000000..3e8432e --- /dev/null +++ b/P1.cpp @@ -0,0 +1,17 @@ +#include + +int main() +{ + using namespace std; + cout<<"Enter the number n: "; + int n; + cin>>n; + double* p=new double[n]; + for (int i=0;i +#include +#include +const int nRow = 4; +const int nCol = 5; +const double pStart = 0.7; +const double pSenseCorrect = 0.7; + +int main() +{ + using namespace std; + double p[nRow][nCol]; + string Measurements[nRow][nCol]; + string world[nRow][nCol] = {{ "red","green","green","red","red" }, + { "red","red","green","red","red" }, + { "red","red","green","green","red" }, + { "red","red","red","red","red" }, }; + double prior_value = (1 - pStart) / (nRow * nCol - 1); + for (int i = 0; i < nRow; i++) + for (int j = 0; j < nCol; j++) + p[i][j] = prior_value; + p[2][1] = pStart; + for (int i = 0; i < nRow; i++) + for (int j = 0; j < nCol; j++) + Measurements[i][j] = "green"; + int hit; + double sum = 0; + double q[nRow][nCol]; + for (int ii = 0; ii < nRow; ii++) + for (int jj =0; jj< nCol; jj++) + { + if (Measurements[ii][jj] == world[ii][jj]) + hit = 1; + else + hit = 0; + q[ii][jj] = p[ii][jj] * (hit * pSenseCorrect + (1 - hit) * (1 - pSenseCorrect)); + sum = sum + q[ii][jj]; + } + for (int i =0; i < nRow; i++) + for (int j = 0; j < nCol; j++) + q[i][j] = q[i][j] / sum; + double q_max = q[1][1]; + int max_row =0; + int max_col = 0; + for (int i = 0; i < nRow; i++) + for (int j = 1; j < nCol; j++) + if (q[i][j] > q_max) + { + q_max = q[i][j]; + max_row = i; + max_col = j; + } + cout<<"The Prior: "< +#include +const double pCan = 0.001; +const double pNon = 0.999; +const double pPosCan = 0.8; +const double pPosNon = 0.1; + +int main() +{ + using namespace std; + string z; + double p[2]; + double sum; + cout<<"Enter the result of test(positive or negative): "; + cin>>z; + if(z=="positive") + { + p[0]=pPosCan * pCan; + p[1]=pPosNon * pNon; + } + else + { + p[0]=(1 - pPosCan) * pCan; + p[1]=(1 - pPosNon) * pNon; + } + sum=p[0]+p[1]; + p[0]=p[0]/sum; + p[1]=p[1]/sum; + cout<<"The probability of having cancer given the "< +const int a=2; +const int b=4; + +int main() +{ + using namespace std; + cout<<"Enter the row of matrix p : ";// к + int row; + cin>>row; + cout<<"Enter the col of matrix p : "; + int col; + cin>>col; + double** p=new double* [row]; + for (int i=0;i>p[i][j]; + double sum1=0.0; + for (int ii=0;ii +int main() +{ + using namespace std; + cout<<"Enter the number of array p: ";//pĸ + int n; + cin>>n; + cout<<"Enter the moving steps u : ";//ƶiju + int u; + cin>>u; + double* p=new double[n]; + double* q=new double[n]; + for (int i=0;i>p[i]; + } + cout<<"before moving : "< +#include +#include +double MOD(double,double); +const double pExact=0.8; +const double pOvershoot = 0.1; +const double pUndershoot = 0.1; + +int main() +{ + using namespace std; + cout<<"Enter the number of array p : "; + int n; + cin>>n; + double* p=new double[n]; + double* q=new double[n]; + for (int i=0;i>p[i]; + } + cout<<"Enter the moving steps u : "; + int u; + cin>>u; + cout<<"before moving : "<-0.000000000000001) || (y<0.000000000000001 && y>-0.000000000000001))return x; + f = x/y; + n = (long)f; + if(n>f) n=n-1; + f =x-n*y; + return f; + +} + + + diff --git a/p13.cpp b/p13.cpp new file mode 100644 index 0000000..75c7157 --- /dev/null +++ b/p13.cpp @@ -0,0 +1,43 @@ +#include "stdafx.h" +#include + +int main() +{ + using namespace std; + cout << "Enter the row of matrix p : ";// к + int row; + cin >> row; + cout << "Enter the col of matrix p : "; + int col; + cin >> col; + double** p = new double*[row]; + for (int i = 0; i> p[i][j]; + double sum = 0.0; + for (int ii = 0; ii Date: Sat, 9 Dec 2017 21:52:39 +0800 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c0b2b44..630a6bd 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ The codes and slides for the first year graduate student course, the Fundamental ## 学生更新记录: -- 霍煜豪 邮箱:591144810@qq.com 学号:201730310153。刚开始学python,改的比较慢到目前才改了16个,而且改的比较烂。。 +- 姓名:罗响 学号:201730310128 邮箱:834943826@qq.com From 7c793e5a596b38da455ddfbd384fc97e40c73b6e Mon Sep 17 00:00:00 2001 From: Luo Xiang <33339892+XiangLaw@users.noreply.github.com> Date: Sat, 9 Dec 2017 22:01:00 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 630a6bd..3d086ff 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ The codes and slides for the first year graduate student course, the Fundamental ## 学生更新记录: -- 姓名:罗响 学号:201730310128 邮箱:834943826@qq.com +- 姓名:罗响   学号:201730310128   邮箱:834943826@qq.com   改了P1、P4、P5、P10、P12、P13、P14这7个matlab例子为C++。