Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include const double CFACTOR = 0.9; const double CDELTA = 0.000006; const int CNW = 4;

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions