Garmaine Staff asked 1 year ago

I need to write constructors for my 3×3 matrix class. I'm not sure whether I'm doing it efficiently and I do not know how to use initializer_list.. I would like a constructor that creates by default the identity matrix, and receives parameteres to set a diagonal matrix. Then I'd also like a constructor that takes a list of cofficients (with initialization_list) and puts them in the matrix. This is what I have:

#include <iostream>
#include <array>
#include <cmath>
#include <initializer_list>
#include "Vecteur.h"
using namespace std;

   class Matrice33 {

private :

   array<array<double,3>,3> matrice;

   public :

       Matrice33(double a = 1, double b=1, double c=1)

        { matrice[0][0] = a; matrice[1][1]= b; matrice [2][2]= c;
          matrice[0][1] = 0; matrice[0][2] = 0; 
          matrice[1][0] = 0; matrice[1][2] = 0;
          matrice[2][0] = 0; matrice[2][1] = 0;} \\ IS THIS THE ONLY WAY TO SET THE MATRIX OR IS 
                                                  \\THERE A QUICKER ONE?

      Matrice33(initilizer_liste<double> cosnt& coeff)

        { for( auto c : coeff) \\ I DON'T KNOW HOW TO WRITE THIS CONSTRUCTOR...

    void affiche() const { for(auto m : matrice){
                              for(auto n : m) {
                                  cout<<n<<" ";}


   int main(){

    Matrice33 mat(1.1, 1.2, 1.3,
                  2.1, 2.2, 2.3,
                  3.1, 3.2, 3.3); \\I'D LIKE THIS TO BE TAKEN AS THE LIST BY MY CONSTRUCTOR, FOR 

      Matrice33 m(2.0,3.0,1.0);
      m.affiche(); \\ WHEN I EXECUTE I DON'T GET ANY OUTPUT.. 
        return 0;