/
tableaux2D.cpp
120 lines (104 loc) · 3.98 KB
/
tableaux2D.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdexcept>
#include <iostream>
#include <vector>
using namespace std;
/** Infrastructure minimale de test **/
#define ASSERT(test) if (!(test)) cout << "Test failed in file " << __FILE__ << " line " << __LINE__ << ": " #test << endl
vector<vector<int>> tabVide (0);
vector<vector<int>> tabCarre = { { 1, 2, 3 },
{ 4, 11, 6 },
{ 9, 12, 7 } };
vector<vector<int>> tabRectangulaire = { { 1, 2, 3 },
{ 9, 12, 7 } };
vector<vector<int>> tabBizarre = { { 1, 2, 3 },
{ 4, 5 },
{ 6, 7, 8, 10 } };
/** renvoie le nombre de lignes d'un tableau 2D d'entiers
* @param t le tableau 2D d'entiers
* @return le nombre de lignes du tableau t
**/
int nombreDeLignes(vector<vector<int>> t) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction nombreDeLignes non implanté ligne 27");
}
void nombreDeLignesTest() {
ASSERT( nombreDeLignes(tabVide) == 0 );
ASSERT( nombreDeLignes(tabCarre) == 3 );
ASSERT( nombreDeLignes(tabRectangulaire) == 2 );
ASSERT( nombreDeLignes(tabBizarre) == 3 );
}
/** renvoie le nombre de colonnes d'un tableau 2D d'entiers
* @param t le tableau 2D d'entiers
* @return le nombre de colonnes du tableau t
**/
int nombreDeColonnes(vector<vector<int>> t) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction nombreDeColonnes non implanté ligne 43");
}
void nombreDeColonnesTest() {
ASSERT( nombreDeColonnes(tabVide) == 0 );
ASSERT( nombreDeColonnes(tabCarre) == 3 );
ASSERT( nombreDeColonnes(tabRectangulaire) == 3 );
ASSERT( nombreDeColonnes(tabBizarre) == 3 );
}
/** affiche tous les elements de la ligne l de t.
* @param t le tableau 2D d'entiers
* @param l un entier
**/
void afficheLigne(vector<vector<int>> t, int l) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction afficheLigne non implanté ligne 59");
}
/** affiche tous les elements de la colonne c de t.
* @param t le tableau 2D d'entiers
* @param c un entier
**/
void afficheColonne(vector<vector<int>> t, int c) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction afficheColonne non implanté ligne 68");
}
/** affiche tous les éléments de la première diagonale d'un
tableau t supposé carré
* @param t le tableau 2D d'entiers
**/
void afficheDiagonale(vector<vector<int>> t) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction afficheDiagonale non implanté ligne 77");
}
/** affiche tous les elements de t.
* @param t le tableau 2D d'entiers
**/
void affiche(vector<vector<int>> t) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction affiche non implanté ligne 85");
}
/** Test d'appartenance
* @param t un tableau d'entiers à deux dimensions
* @param x un entier
* @return un booleen: true si x apparaît dans t, false sinon
**/
bool appartient(vector<vector<int>> t, int x) {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction appartient non implanté ligne 95");
}
void appartientTest() {
// Remplacer la ligne suivante par le code adéquat
throw runtime_error("Fonction appartientTest non implanté ligne 100");
}
int main() {
cout << "Lancement tests de nombreDeLignes" << endl;
nombreDeLignesTest();
cout << "Lancement tests de nombreDeColonnes" << endl;
nombreDeColonnesTest();
cout << "Appel de afficheLigne:" << endl;
afficheLigne(tabCarre, 1);
cout << "Appel de afficheColonne:" << endl;
afficheColonne(tabCarre, 2);
cout << "Appel de afficheDiagonale:" << endl;
afficheDiagonale(tabCarre);
cout << "Appel de affiche:" << endl;
affiche(tabCarre);
cout << "Lancement tests de appartient" << endl;
nombreDeColonnesTest();
appartientTest();
}