Skip to content
Snippets Groups Projects
Commit dc20534e authored by BOGUET Thomas's avatar BOGUET Thomas
Browse files

rendu td3

parent fd2c1f5f
No related branches found
No related tags found
No related merge requests found
......@@ -54,7 +54,7 @@ function deb5(): number {
}
console.log(deb5());
// exercice6.ts
// exercice6
let tab1 = [1, 2, 3];
let tab2 = tab1;
tab1[1] = 5;
......@@ -65,3 +65,21 @@ let tab4 = [...tab3];
tab3[1] = 5;
console.log(tab3, tab4);
// exercice7
function deb7(x: number, y: number): number {
let val = 0;
for (let i = 0; i < y; i++) {
val += x;
}
return val;
}
console.log(deb7(5, 3));
// exercice8.ts
function deb8(n: number): number {
if (n === 0) {
return 1;
}
return n * deb8(n - 1);
}
console.log(deb8(5));
\ No newline at end of file
......@@ -190,4 +190,15 @@ Règle fondamentale :
Toujours faire un git pull avant de faire un git push.
Toujours commiter vos modifications avant de faire un git pull.
La séquence idéale est : commit → pull → push.
\ No newline at end of file
La séquence idéale est : commit → pull → push.
TD 3
Débug:
Arrêt du programme : Le programme s'interrompt à l'endroit défini, permettant d'inspecter la mémoire et les variables.
Suivi des variables : L'exécution pas à pas permet de vérifier l'évolution des valeurs et de détecter d'éventuelles erreurs.
Portée des variables : Des variables du même nom peuvent exister dans des contextes différents, ce qui est observable avec le débogueur.
\ No newline at end of file
//ex1
function creeInitiales(nom: string, prenom: string): string {
if (!nom && !prenom) throw new VideError("Le nom et le prénom ne peuvent pas être vides.");
if (!nom) throw new VideError("Le nom ne peut pas être vide.");
if (!prenom) throw new VideError("Le prénom ne peut pas être vide.");
return nom[0].toUpperCase() + prenom[0].toUpperCase();
}
class VideError extends Error {
constructor(message: string) {
super(message);
this.name = "VideError";
}
}
console.log("Boguet", "Thomas")
console.log("", "Thomas")
//ex2
class Etudiant {
INE: string;
nom: string;
prenom: string;
constructor(INE: string, nom: string, prenom: string) {
this.INE = INE;
this.nom = nom;
this.prenom = prenom;
}
setINE(INE: string): void {
if (INE.length != 11) {
throw new Error("Format incorrect");
}
for (let i = 0; i < tab.length; i++) {
if (INE)
}
this.INE = INE;
}
}
let etudiant = new Etudiant("1234567890A", "Dupont", "Jean");
try {
etudiant.setINE("1234567890AB");
} catch (e) {
console.log(e.message);
}
// ex 3
function datedef(date: string): number[] {
let tab = date.split("/");
let jour = Number(date[0]);
let mois = Number(date[1]);
let ann = Number(date[2]);
return [jour, mois, ann];
}
let date = "22/05/1994";
//Ex 4
function calcule(tableau: Array<number>, indice: number, operateur: string, operande: number): number {
switch (operateur) {
case "+":
return tableau[indice] + operande;
case "-":
return tableau[indice] - operande;
case "*":
return tableau[indice] * operande;
case "/":
return tableau[indice] / operande;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment