#include <iostream>
#include "vecteur.h"
#include "matrice.h"

using namespace std;

extern void demo_vecteur();
extern void demo1_matrice();
extern void demo2_matrice();
extern void demo3_matrice();
extern void demo4_matrice();

int main_exo5_6(void)
{
      demo_vecteur();
      // demo1_matrice();
      // demo2_matrice();
      // demo3_matrice();
      //demo4_matrice();
}

void demo_vecteur()
{
    Vecteur a(0,5);
    cin >> a;
    Vecteur b(a);
    Vecteur c(0,5);
    cin >> c;

    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
    cout << "c = " << c << endl;

    c = a;
    a[3] = 666;
    // a[-2] = 7777;  // erreur à l'execution grâce à l'assertion

    cout << "c = " << c << endl;
    cout << "a = " << a << endl;

    c[0] = 2;
    c[1] = 6;
    c[2] = 3;
    c[3] = 1;
    c[4] = c[3];
    cout << "c = " << c << endl;

    Vecteur d(0,5);
    d = a;
    cout << "d = " << d << endl;

    const Vecteur vconst(3,8);
//   cin >> vconst;
//  vconst[2] = 666;
    cout << "vconst = " << vconst << endl;

    cout << "produit scalaire a = " << a<< " et b = " << b << endl;
    cout << produit_scalaire(a, b) << endl;
}

void demo1_matrice()
{
    Matrice M1(2,3);

    cin >> M1;
    cout << M1 << endl;

    Vecteur v(0,3);
    v = M1[1];
    cout << v << endl;

    cout << "M1[1][2] = " << M1[1][2] << endl;

    M1[0][1] = 666;
    cout << M1 << endl;

    Matrice M2(M1);
    M1[1][1] = 0;
    cout << M2 << endl;

    Matrice M3(4,2);
    cin >> M3;
    cout << M3;

//   M3 = M1; PLANTAGE dimensions différentes
    M1[1][1] = 666;
    cout << "M1 = " << M1 << endl;
    cout << "M3 = " << M3 << endl;
}

void demo2_matrice()
{
    Matrice M1(2,3);
    cin >> M1;
    cout << M1 << endl;

    Vecteur v(0,3);
    v = M1[1];
    cout << v << endl;

    M1[0] = v;
    cout << M1[0] << endl;
    cout << "M1[1][2] = " << M1[1][2] << endl;

    M1[0][1] = 666;
    cout << M1 << endl;

    Matrice M2(M1);
    M1[1][1] = 0;
    cout << M2 << endl;

    Matrice M3(2,3);
    cin >> M3;
    cout << M3 << endl;

    M3 = M1;
    M1[1][1] = 666;
    cout << "M1 = " << M1 << endl;
    cout << "M3 = " << M3 << endl;
}

void demo3_matrice()
{
    Matrice M1(3,4), M2(3,4);
    cin >> M1 >> M2;
    cout << "M1 = \t" << M1 << endl;
    cout << "M2 = \t" << M2 << endl;
    cout << "M1 + M2 = \t" << (M1 + M2) << endl;

    Matrice M3(4,3), M4(3,2);
    cin >> M3 >> M4;
    cout << "M3 = \t" << M3 << endl;
    cout << "M4 = \t" << M4 << endl;
    cout << "M3 * M4 = \t" << (M3 * M4) << endl;

    Vecteur v(0,3);
    cin >> v;
    cout << "produit scalaire M3[1] = " << M3[1] << " et v = " << v << endl;
    cout << produit_scalaire(M3[1], v) << endl;
}

void demo4_matrice()
{
    Matrice M(3,5);
    cin >> M;
    cout << M << endl;

    cout << M[2]; // R_Value
    Vecteur v = M[2]; // R_Value
    cout << " v = M[2] = " << v << endl;

    int a = M(2,3);
    M(2,3) = 666;
    cout << "a = " << a << endl;
    cout << "M(2,3) = " << M(2,3) << endl;
}
