From 066bc64ab9a4757ea80402b37cf17d7b5541f56a Mon Sep 17 00:00:00 2001 From: Morph01 <145839520+Morph01@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:01:24 +0100 Subject: [PATCH] first commit (gaussjordan is bugged) --- .gitignore | 8 +++ .vscode/launch.json | 16 +++++ .vscode/settings.json | 49 +++++++++++++ .vscode/tasks.json | 28 ++++++++ src/main.cpp | 164 ++++++++++++++++++++++++++++++++++++++++++ xmake.lua | 75 +++++++++++++++++++ 6 files changed, 340 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 src/main.cpp create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1521057 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4d87bd4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "xmake", + "request": "launch", + "name": "Debug XMake target", + "target": "Pivot", + "cwd": "${workspaceFolder}", + "stopAtEntry": true + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d926cc3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,49 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..08d9005 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc build active file", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..aa2e204 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,164 @@ +#include +#include +#include + +template +class Matrix +{ +private: + std::size_t m_Lignes; + std::size_t m_Colonnes; + std::size_t m_Dimension; + std::vector m_Data; + +public: + Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes), m_Dimension(lignes * colonnes) + { + m_Data.resize(m_Dimension); + } + ~Matrix() {} + + void Print() const + { + for (size_t i = 0; i < m_Lignes; ++i) + { + std::cout << "[ "; + for (size_t j = 0; j < m_Colonnes; ++j) + { + std::size_t indice = i * m_Lignes + j; + std::cout << at(i, j) << " "; + } + std::cout << "]"; + std::cout << std::endl; + } + } + void Insert() + { + for (size_t i = 0; i < m_Lignes; ++i) + { + for (size_t j = 0; j < m_Colonnes; ++j) + { + std::cin >> at(i, j); + } + std::cout << std::endl; + } + } + + void DivideLine(T div, std::size_t line){ + for (size_t i = 0; i < count; i++) + { + /* code */ + } + + } + + void GaussJordan() + { + int r = -1; + for (std::size_t j = 0; j < m_Colonnes; ++j) + { + std::size_t k = 0; + // Rechercher + for (std::size_t i = r + 1; i < m_Lignes; ++i) + { + if (at(i, j) > at(k, j)) + { + k = i; + } + } + Matrix mat_pivot(1, 1); + mat_pivot.at(0, 0) = at(k, j); + if (at(k, j) != 0) + { + ++r; + // Diviser + for (std::size_t z = 0; z < m_Colonnes; ++z) + { + at(k, z) /= mat_pivot.at(0, 0); + } + if (k != r) + { + // Echanger + for (std::size_t z = 0; z < m_Colonnes; ++z) + { + std::swap(at(k, z), at(r, z)); + } + } + for (std::size_t i = 0; i < m_Lignes; ++i) + { + if (i != r) + { + //Soustraire + for (std::size_t z = 0; z < m_Colonnes; ++z) + { + at(i, z) -= at(r, z) * at(i, j); + } + } + } + } + } + } + + T &operator[](std::size_t indice) + { + return at(indice); + } + + T &at(std::size_t ligne, std::size_t colonne) + { + return m_Data[ligne * m_Lignes + colonne]; + } + + T at(std::size_t ligne, std::size_t colonne) const + { + return m_Data[ligne * m_Lignes + colonne]; + } + + /*std::vector::iterator begin() { + return m_Data.begin(); + } + + std::vector::iterator end() { + return m_Data.end(); + }*/ +}; + +/* +void test() +{ + Matrix mat(2, 2); + mat.at(0, 0) = 4; + mat.at(0, 1) = 3; + mat.at(1, 0) = 2; + mat.at(1, 1) = 1; + + mat.Print(); + mat.GaussJordan(); + mat.Print(); +} +*/ + +int main(int argc, char **argv) +{ + //test(); + + std::cout << "hello world!" << std::endl; + std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl; + std::size_t lignes; + std::cin >> lignes; + std::cout << "Quelle est le nombre de colonnes de votre matrice ?" << std::endl; + std::size_t colonnes; + std::cin >> colonnes; + std::size_t dimension = lignes * colonnes; + std::cout << "Rentrez les coefficients de la matrice" << std::endl; + Matrix mat(lignes, colonnes); + + mat.Insert(); + + mat.Print(); + mat.GaussJordan(); + std::cout << std::endl; + mat.Print(); + + return 0; +} diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..023943f --- /dev/null +++ b/xmake.lua @@ -0,0 +1,75 @@ +add_rules("mode.debug", "mode.release") + +target("Pivot") + set_kind("binary") + add_files("src/*.cpp") + +-- +-- If you want to known more usage about xmake, please see https://xmake.io +-- +-- ## FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add debug and release modes +-- add_rules("mode.debug", "mode.release") +-- +-- -- add macro definition +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "c++11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add system link libraries +-- add_syslinks("z", "pthread") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- +