Question: Convert the C code to use Advanced C++ Language Features and the Standard Template Library (STL). The code may not compile on your compiler and
Convert the C code to use Advanced C++ Language Features and the Standard Template Library (STL). The code may not compile on your compiler and in that case please fix the problem yourself. There are no errors intentionally inserted into the code. It is not necessary to name the algorithms. #include
void calculate(double matrix[CWW][CWW], double value[CWW]) { double newValue[CNW]; int i, j; while (true) { for (i = 0; i < CNW; i++) { value[i] = (1.0 - CFACTOR) / NCW; for (j = 0; j < CNW; j++) { if (matrix[j][i] > 0) { newValue[i] += CFACTOR * value[j] / matrix[j][i]; } } } double sum = 0; for (i = 0; i < CNW; i++) { sum += newValue[i]; } double error = 0; for (i = 0; i < CNW; i++) { newValue[i] += (1.0 - sum) / NCW; error += fabs(newValue[i] - value[i]); } if (error < CFACTOR) { break; } for (i = 0; i < CNW; i++) { value[i] = newValue[i]; } } } int main() { double matrix[CNW][CNW] = { {0, 1, 0, 0}, {0.25, 0, 0.75, 0}, {0.25, 0.25, 0.25, 0.25}, {0, 0, 0.5, 0} }; double value[CNW] = { 1.0, 1.0, 1.0, 1.0 }; calculate(matrix, value); printf("Values: "); for (int i = 0; i < CNW; i++) { printf("Amount %d: %lf ", i, value[i]); } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
