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
|
<html>
<head>
<title> Calcul de moyenne </title>
<style type="text/css">
h2 {
color:blue;
font-family:verdana;
font-style:italique;
}
body {
text-align:center;
}
</style>
</head>
<body>
<?php
# declaration et initialisation de la table note
$note=array(
"Paul" => array(14.5, 15, 12),
"Aly" => array(10, 15, 17),
"Sidi" => array(12, 13, 16),
"Lucie" => array(14, 14, 13.5)
);
# declaration de la fonction moyenne
function moyenne ($resultat=array()){
reset($resultat);
$noteSTAT=0;
$noteGDI=0;
$noteBD=0;
while(list($cle,$valeur)=each($resultat)) # on parcours la table d'entrée par paire (clef,valeur)
{
#$moy_etud [$cle]= ($valeur[1]+$valeur[2]+$valeur[3])/3;
$somnote=0;
for($i=0 ; $i<count($valeur) ; $i++) {
$somnote=$somnote+$valeur[$i]; #on parcours la table valeur et on somme les notes
}
$moy_etud [$cle]= sprintf("%.3f",$somnote/count($valeur)); // sprintf pour arrondir la note moyenne
$noteSTAT=$noteSTAT+$valeur[0]; # on recupre la note de la matiere stat et idem pour les deux autres matieres
$noteGDI=$noteGDI+$valeur[1];
$noteBD=$noteBD+$valeur[2];
}
$moy_mat['STAT']=sprintf("%.3f",$noteSTAT/count($resultat)); # calcul de la moyenne de la matiere stat
$moy_mat['GDI']=sprintf("%.3f",$noteGDI/count($resultat));
$moy_mat['BG']=sprintf("%.3f",$noteBD/count($resultat));
$note_groupe=0; # somme de toutes les moyennes
echo ' <h2> Moyenne par etudiant </h2>';
while(list($etudiant,$moyenne)=each($moy_etud))
{ echo' <B> '.$etudiant.' : </B> '.$moyenne.' <br/> ';
$note_groupe=$note_groupe + $moyenne ;
}
$moy_groupe = sprintf("%.3f",$note_groupe/count($moy_etud));
echo ' <h2> Moyenne du groupe </h2>';
echo ' <B> M : </B> '.$moy_groupe.' <br/>';
echo '<h2> Moyenne par matiere </h2>';
while(list($matiere,$moyenne)=each($moy_mat)) {
echo ' <B> '.$matiere.' : </B> '.$moyenne.' <br/>';
}
} # fin de la fonction moyenne
moyenne($note); # appel de la fonction moyenne
?>
</body>
</html> |
Partager