save and load
This commit is contained in:
4
matricies/matrice3x3.mat
Normal file
4
matricies/matrice3x3.mat
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
3 3
|
||||||
|
1 2 3
|
||||||
|
4 5 6
|
||||||
|
1 2 3
|
||||||
4
matricies/matrice3x3echelonne.mat
Normal file
4
matricies/matrice3x3echelonne.mat
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
3 3
|
||||||
|
1 0 -1
|
||||||
|
0 1 2
|
||||||
|
0 0 0
|
||||||
43
src/Matrix.h
43
src/Matrix.h
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static bool EqualZero(T var) {
|
static bool EqualZero(T var) {
|
||||||
@@ -19,9 +20,17 @@ class Matrix {
|
|||||||
std::vector<T> m_Data;
|
std::vector<T> m_Data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Matrix(const std::string& fileNameInput) {
|
||||||
|
Load(fileNameInput);
|
||||||
|
}
|
||||||
Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes), m_Dimension(lignes * colonnes) {
|
Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes), m_Dimension(lignes * colonnes) {
|
||||||
m_Data.resize(m_Dimension);
|
m_Data.resize(m_Dimension);
|
||||||
}
|
}
|
||||||
|
Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<T>&& initList) :
|
||||||
|
m_Lignes(lignes), m_Colonnes(colonnes), m_Dimension(lignes * colonnes) {
|
||||||
|
m_Data = initList;
|
||||||
|
m_Data.resize(m_Dimension);
|
||||||
|
}
|
||||||
~Matrix() {}
|
~Matrix() {}
|
||||||
|
|
||||||
void Print() const {
|
void Print() const {
|
||||||
@@ -52,15 +61,35 @@ class Matrix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void Save(const std::string& fileName) {
|
||||||
void DivideLine(T div, std::size_t line){
|
std::ofstream out{fileName};
|
||||||
for (size_t i = 0; i < count; i++)
|
if (!out) {
|
||||||
{
|
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out << m_Lignes << " " << m_Colonnes << "\n";
|
||||||
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
|
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
||||||
|
out << at(i, j) << " ";
|
||||||
|
}
|
||||||
|
out << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Load(const std::string& filename) {
|
||||||
|
std::ifstream in{filename};
|
||||||
|
if (!in) {
|
||||||
|
std::cerr << "Impossible de charger la matrice !\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
in >> m_Lignes >> m_Colonnes;
|
||||||
|
m_Data.resize(m_Lignes * m_Colonnes);
|
||||||
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
|
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
||||||
|
in >> at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
void GaussJordan() {
|
void GaussJordan() {
|
||||||
int r = -1;
|
int r = -1;
|
||||||
|
|||||||
21
src/main.cpp
21
src/main.cpp
@@ -1,25 +1,16 @@
|
|||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
Matrix<float> mat(3, 3);
|
Matrix<float> mat{"matrice3x3.mat"};
|
||||||
mat.at(0, 0) = mat.at(2, 0) = 1;
|
|
||||||
mat.at(0, 1) = mat.at(2, 1) = 2;
|
|
||||||
mat.at(0, 2) = mat.at(2, 2) = 3;
|
|
||||||
|
|
||||||
mat.at(1, 0) = 4;
|
|
||||||
mat.at(1, 1) = 5;
|
|
||||||
mat.at(1, 2) = 6;
|
|
||||||
|
|
||||||
mat.Print();
|
mat.Print();
|
||||||
|
//mat.Save("matrice3x3.mat");
|
||||||
mat.GaussJordan();
|
mat.GaussJordan();
|
||||||
std::cout << "\nResultat :\n";
|
std::cout << "\nResultat :\n";
|
||||||
mat.Print();
|
mat.Print();
|
||||||
|
mat.Save("matrice3x3echelonne.mat");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
void prompt() {
|
||||||
test();
|
|
||||||
|
|
||||||
std::cout << "hello world!" << std::endl;
|
|
||||||
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
||||||
std::size_t lignes;
|
std::size_t lignes;
|
||||||
std::cin >> lignes;
|
std::cin >> lignes;
|
||||||
@@ -36,6 +27,10 @@ int main(int argc, char** argv) {
|
|||||||
mat.GaussJordan();
|
mat.GaussJordan();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
mat.Print();
|
mat.Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
test();
|
||||||
|
prompt();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user