1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| // fichier Polynomial.h
//=====================
#ifndef POLYNOMIAL_H__
#define POLYNOMIAL_H__
#include <array>
class Polynomial {
public:
Polynomial() = default;
Polynomial( std::array<int,5*5>const& t );
void affiche()const;
private:
std::array<std::array<int,5>,5> matrix;
};
#endif // POLYNOMIAL_H__
// fichier Polynomial.cpp
//=======================
#include "Polynomial.h"
#include <iostream>
#include <cstdlib>
Polynomial::Polynomial( std::array<int,5*5>const& t ) {
std::size_t a{};
for ( auto& subtab : matrix ) {
for ( int& x : subtab ) {
x = t[a++];
}
}
}
void Polynomial::affiche()const {
for ( auto const& subtab : matrix ) {
for ( int x : subtab ) {
std::cout << x << ' ';
}
endl( std::cout );
}
};
// fichier Main.cpp
//=================
#include "Polynomial.h"
#include <iostream>
#include <array>
int main() {
std::array array1{1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5};
Polynomial p1{array1};
for ( std::size_t i{} ; i < array1.size() ; i++ ) {
if ( i % 5 == 0 ) {
std::cout << array1[i] << ' ';
}
}
endl( std::cout );
p1.affiche();
} |