From b9bb6caa73083da8fc0d74d366dd9262da081c3d Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Mon, 25 May 2020 23:32:31 -0400 Subject: [PATCH] made functions static to files *BUG* in CPP lint github action --- .../Gaussian_elimination.cpp | 52 ++++++++----------- ...ection_method.CPP => bisection_method.cpp} | 2 +- .../false-position.cpp | 21 ++++---- .../newton_raphson_method.cpp | 5 +- .../secant_method.cpp | 2 +- .../successive_approximation.cpp | 5 +- 6 files changed, 40 insertions(+), 47 deletions(-) rename computer_oriented_statistical_methods/{Bisection_method.CPP => bisection_method.cpp} (96%) diff --git a/computer_oriented_statistical_methods/Gaussian_elimination.cpp b/computer_oriented_statistical_methods/Gaussian_elimination.cpp index 58e634505..ecfbfacc9 100644 --- a/computer_oriented_statistical_methods/Gaussian_elimination.cpp +++ b/computer_oriented_statistical_methods/Gaussian_elimination.cpp @@ -1,29 +1,23 @@ #include -using namespace std; -int main() -{ +int main() { int mat_size, i, j, step; - cout << "Matrix size: "; - cin >> mat_size; + std::cout << "Matrix size: "; + std::cin >> mat_size; double mat[mat_size + 1][mat_size + 1], x[mat_size][mat_size + 1]; - cout << endl - << "Enter value of the matrix: " << endl; - for (i = 0; i < mat_size; i++) - { - for (j = 0; j <= mat_size; j++) - { - cin >> mat[i][j]; //Enter (mat_size*mat_size) value of the matrix. + std::cout << std::endl << "Enter value of the matrix: " << std::endl; + for (i = 0; i < mat_size; i++) { + for (j = 0; j <= mat_size; j++) { + std::cin >> + mat[i][j]; // Enter (mat_size*mat_size) value of the matrix. } } - for (step = 0; step < mat_size - 1; step++) - { - for (i = step; i < mat_size - 1; i++) - { + for (step = 0; step < mat_size - 1; step++) { + for (i = step; i < mat_size - 1; i++) { double a = (mat[i + 1][step] / mat[step][step]); for (j = step; j <= mat_size; j++) @@ -31,24 +25,20 @@ int main() } } - cout << endl - << "Matrix using Gaussian Elimination method: " << endl; - for (i = 0; i < mat_size; i++) - { - for (j = 0; j <= mat_size; j++) - { + std::cout << std::endl + << "Matrix using Gaussian Elimination method: " << std::endl; + for (i = 0; i < mat_size; i++) { + for (j = 0; j <= mat_size; j++) { x[i][j] = mat[i][j]; - cout << mat[i][j] << " "; + std::cout << mat[i][j] << " "; } - cout << endl; + std::cout << std::endl; } - cout << endl - << "Value of the Gaussian Elimination method: " << endl; - for (i = mat_size - 1; i >= 0; i--) - { + std::cout << std::endl + << "Value of the Gaussian Elimination method: " << std::endl; + for (i = mat_size - 1; i >= 0; i--) { double sum = 0; - for (j = mat_size - 1; j > i; j--) - { + for (j = mat_size - 1; j > i; j--) { x[i][j] = x[j][j] * x[i][j]; sum = x[i][j] + sum; } @@ -57,7 +47,7 @@ int main() else x[i][i] = (x[i][mat_size] - sum) / (x[i][i]); - cout << "x" << i << "= " << x[i][i] << endl; + std::cout << "x" << i << "= " << x[i][i] << std::endl; } return 0; } diff --git a/computer_oriented_statistical_methods/Bisection_method.CPP b/computer_oriented_statistical_methods/bisection_method.cpp similarity index 96% rename from computer_oriented_statistical_methods/Bisection_method.CPP rename to computer_oriented_statistical_methods/bisection_method.cpp index 266083de1..089828c9a 100644 --- a/computer_oriented_statistical_methods/Bisection_method.CPP +++ b/computer_oriented_statistical_methods/bisection_method.cpp @@ -1,7 +1,7 @@ #include #include -float eq(float i) { +static float eq(float i) { return (std::pow(i, 3) - (4 * i) - 9); // original equation } diff --git a/computer_oriented_statistical_methods/false-position.cpp b/computer_oriented_statistical_methods/false-position.cpp index 5e15e92cc..c5a314508 100644 --- a/computer_oriented_statistical_methods/false-position.cpp +++ b/computer_oriented_statistical_methods/false-position.cpp @@ -1,9 +1,11 @@ -#include -#include +#include +#include #include -float eq(float i) { + +static float eq(float i) { return (pow(i, 3) - (4 * i) - 9); // origial equation } + int main() { float a, b, z, c, m, n; system("clear"); @@ -12,12 +14,13 @@ int main() { if (z >= 0) { b = i; a = --i; - goto START; - } + break; } - START: + } + std::cout << "\nFirst initial: " << a; std::cout << "\nSecond initial: " << b; + for (int i = 0; i < 100; i++) { float h, d; m = eq(a); @@ -26,10 +29,10 @@ int main() { a = c; z = eq(c); if (z > 0 && z < 0.09) { // stoping criteria - goto END; + break; } } - END: + std::cout << "\n\nRoot: " << c; - system("pause"); + return 0; } diff --git a/computer_oriented_statistical_methods/newton_raphson_method.cpp b/computer_oriented_statistical_methods/newton_raphson_method.cpp index a2a57768e..47d276490 100644 --- a/computer_oriented_statistical_methods/newton_raphson_method.cpp +++ b/computer_oriented_statistical_methods/newton_raphson_method.cpp @@ -1,10 +1,11 @@ #include #include -float eq(float i) { +static float eq(float i) { return (std::pow(i, 3) - (4 * i) - 9); // original equation } -float eq_der(float i) { + +static float eq_der(float i) { return ((3 * std::pow(i, 2)) - 4); // derivative of equation } diff --git a/computer_oriented_statistical_methods/secant_method.cpp b/computer_oriented_statistical_methods/secant_method.cpp index bd805ed36..c353ef850 100644 --- a/computer_oriented_statistical_methods/secant_method.cpp +++ b/computer_oriented_statistical_methods/secant_method.cpp @@ -1,7 +1,7 @@ #include #include -float eq(float i) { +static float eq(float i) { return (pow(i, 3) - (4 * i) - 9); // original equation } diff --git a/computer_oriented_statistical_methods/successive_approximation.cpp b/computer_oriented_statistical_methods/successive_approximation.cpp index 85c42c9fb..efbcc3bbf 100644 --- a/computer_oriented_statistical_methods/successive_approximation.cpp +++ b/computer_oriented_statistical_methods/successive_approximation.cpp @@ -1,9 +1,8 @@ - #include #include -float eq(float y) { return ((3 * y) - (cos(y)) - 2); } -float eqd(float y) { return ((0.5) * ((cos(y)) + 2)); } +static float eq(float y) { return ((3 * y) - (cos(y)) - 2); } +static float eqd(float y) { return ((0.5) * ((cos(y)) + 2)); } int main() { float y, x1, x2, x3, sum, s, a, f1, f2, gd;