-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTP.php
189 lines (178 loc) · 4.81 KB
/
TP.php
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" lang="fr">
<title>TP de PHP objet - Thierry Champot</title>
</head>
<body>
<?php
include_once 'TableauxValeurs.php';
include_once 'FonctionsAleatoires.php';
class Personne
{
protected $nom;
protected $prenom;
protected $adresse;
protected $age;
static protected $id=0;
public function __construct($Nom,$Prenom,$Adresse,$Age){
$this->__set("nom",$Nom);
$this->__set("prenom",$Prenom);
$this->__set("adresse",$Adresse);
$this->__set("age",$Age);
$this->id = self::$id ++;
}
public function __set($Prop,$Val){
$this->$Prop = $Val;
}
public function __get($Prop){
return $this->$Prop;
}
public function __toString(){
return
"Nom : ".$this->nom.",<br>".
"Prénom : ".$this->prenom.",<br>".
"Adresse : ".$this->adresse.",<br>".
"Age : ".$this->age."<br>".
"Id : ".$this->id."<br>";
}
}
class Etudiant extends Personne
{
private $_uFRInscription;
private $_ville;
private $_coursSuivis;
public function __construct(Personne $Pers,$uFRInscription,$ville){
parent::__construct(
$Pers->__get("nom"),
$Pers->__get("prenom"),
$Pers->__get("adresse"),
$Pers->__get("age")
);
$this->__set("_uFRInscription",$uFRInscription); //
$this->__set("_ville",$ville); //
$this->_coursSuivis=[];
}
public function __set($Prop,$Val){
$this->$Prop = $Val;
}
public function __get($Prop){
return $this->$Prop;
}
public function __toString(){
return
"Nom : ".$this->nom.",<br>".
"Prénom : ".$this->prenom.",<br>".
"Adresse : ".$this->adresse.",<br>".
"Age : ".$this->age.",<br>".
"est incrit à l'UFR de : ".$this->_uFRInscription.",<br>".
"de la ville de ".$this->_ville.",<br>".
"et porte l'ID n°".$this->_id.".<br>"
// " et suit les cours suivants :".$this->_coursSuivis
;
}
}
class Professeur extends Personne
{
private $_salaire;
private $_uFRInscription;
private $_ville;
private $_coursDonnes;
public function __construct(Personne $Pers,$Salaire,$uFRInscription,$ville){
parent::__construct(
$Pers->__get("nom"),
$Pers->__get("prenom"),
$Pers->__get("adresse"),
$Pers->__get("age")
);
$this->__set("_salaire",$Salaire);
$this->__set("_uFRInscription",$uFRInscription);
$this->__set("_ville",$ville);
$this->_coursDonnes = [];
}
public function __set($Prop,$Val){
$this->$Prop = $Val;
}
public function __get($Prop){
return $this->$Prop;
}
public function __toString(){
return
"Nom : ".$this->nom.",<br>".
"Prénom : ".$this->prenom.",<br>".
"Adresse : ".$this->adresse.",<br>".
"Age : ".$this->age.".<br>".
"perçoit un salaire de : ".$this->_salaire.",<br>".
"pour enseigner à l'UFR de : ".$this->_uFRInscription.",<br>".
"de la ville de ".$this->_ville.",<br>".
"et porte l'ID n°".$this->id
;
}
}
class Cours
{
private $_theme;
private $_uFR;
private $_Professeur;
private $_listeEtudiants = array();
public function __construct($Theme,$UFR,$professeur,$ListeEtudiants){
$this->__set("_theme",$Theme);
$this->__set("_uFR",$UFR);
$this->__set("_Professeur",$professeur);
$this->__set("_Professeur",$professeur);
$this->__set("_listeEtudiants",$ListeEtudiants);
}
public function __set($Prop,$Val){
$this->$Prop = $Val;
}
public function __get($Prop){
return $this->$Prop;
}
public function __toString(){
return "Thème : ".$this->theme.", Prénom : ".$this->uFR.".<br>";
}
}
echo "création de 20 personnes : <br>";
for ($i=1; $i <= 20; $i++) {
$personne[$i] = new Personne(
// nom aléatoire dans la liste
valTabSimpleAlea($tabNoms)." ",
// prénom aléatoir dans la liste
valTabSimpleAlea($tabPrenoms)." ",
// adresse aléatoire par concaténation de n°.type voie.nom rue.ville.code postal possible
rand(1,200)." ".valTabSimpleAlea($tabTypeVoies)." ".valTabSimpleAlea($tabNomsVoies),
rand(20,40)
);
}
echo"Création de 10 étudiants : <br>";
for ($i=1; $i <= 10; $i++) {
$etudiant[$i] = new Etudiant(
$personne[$i],
$tabUniversites["DSP"], // UFR en full texte
$tabCodesVillesUFR["NTE"] // ville
);
}
echo"Création de 10 professeurs : <br>";
for ($i=11; $i <= 20; $i++) {
$professeur[$i] = new Professeur(
$personne[$i],
rand(2500,3500)." €", // générateur de salaire
$tabUniversites["DSP"], // nom complet d'UFR
$tabCodesVillesUFR["NTE"] //ville
);
}
echo "Création d'un cours : <br>";
$cours[] =
new Cours(
valTabSimpleAlea(
$tabCoursUFR["DSP"]),
$tabUniversites["DSP"],
$professeur[rand(11,20)],
$etudiant
);
var_dump($etudiant);
var_dump($professeur);
var_dump($cours);
?>
</body>
</html>