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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
//nom generique ClasseEtudiant
{
public class etudiant// definition classe principale etudiant
{
// declaration dates membres qui peuvent etre acceder par d'autres programmes
//private string nom; - vedem noi ce facem la private :(
public string nom,prenom, sexe, ville;
public int age;
public float note;
//utilisation pointeur this pour acceder chaque membre de la classe enfant
public etudiant(string nom,string prenom, string sexe, string ville,int age, int note)
{ this.nom = nom;
this.prenom = prenom;
this.sexe=sexe;
this.ville=ville;
this.age=age;
this.note=note;
}
public etudiant() // implementation constructeur implicit
{
nom = "";
prenom = "";
sexe = "";
ville = "";
age = 0;
note = 0;
}
public etudiant(string n, string p, string s, string v, int a, float not) //implementation constructeur avec parametre
{
nom = n;
prenom = p;
sexe = s;
ville = v;
age = a;
note = not;
}
// fonction quelle_note retourne une valeur de type float
public float quelle_note() // fonction quel_note pour voir la promovation d'un examen
{
if (note >= 5 && note <= 10)
Console.WriteLine("\nL'etudiant a promove l'examen");
else
Console.WriteLine("\nL'etudiant n'a pas promove l'examen");
return note;
}
//affichage informations etudiants - en ce cas 3 dates membres //nom,prenom, note pour chaque objet de la classe etudiant-donc pour //chaque etudiant on affiche seulement ces 3 informations(nom,prenom et //note)
public void informations() // functie membru afisare informatii
{//0,1,2= arguemnte, format- specificator de format
Console.WriteLine(string.Format("{0} {1} : {2}", nom, prenom, note));
}
}
// definir une classe derivee pour la classe parent etudiant
public class enfant_etudiant: etudiant
{ public enfant_etudiant() : base() // base - cuvant rezervat pt a prelua date membru sau functii membru din clasa parinte
{
Console.WriteLine("Constructeur pour la classe derive");
}
//definition constructeur avec parametre pour la classe derive enfant_etudiant
public enfant_etudiant(string n1, string p1, string s1, string v1, int a1, float not1) //implementation constructeur avec parametre
{
nom = n1;
prenom = p1;
sexe = s1;
ville = v1;
age = a1;
note = not1;
}
//fonction membre si un etudiant a une note comprise entre 7 ou 10 (ou non)
public float quelle_note1() // fonction quel_note pour voir la promovation d'un examen
{
if (note >= 7 && note <= 10)
Console.WriteLine("\nL'etudiant a recu une note comprise entre 7 et 10");
else
Console.WriteLine("\nL'etudiant n'a pas recu une note comprise entre 7 et 10");
return note;
}
public float meme_note()
{value=8.02;
get
{return note; //on affiche la valeur de la date membre note
}
set
{if (value==8.02)
note = 8.02;
}
}
//fonction membre informations etudiants nom, prenom,sexe, note
public void informations2() // functie membru afisare informatii
{//0,1,2,3= arguemnts, format- specificator de format
Console.WriteLine(string.Format("{0} {1} : {2} {3} ", nom, prenom,sexe, note));
}
}
static class Program
{
//Programme principal C#
public static void Main(string[] args) //dans le programme principale on va creer 4 objets nomme a,a1,a2 et a3 pour la classe nomme etudiant
//instantions des objets - en ce cas nous avons 4 objets
{
etudiant a = new etudiant("Prevost", "Marcel", "M", "Paris", 20, 3.02f);
etudiant a1 = new etudiant("Prevost", "Eugene", "M", "Lille", 21, 9f);
etudiant a2 = new etudiant("Lafont", "Virginie", "F", "Marseille", 22, 8f);
etudiant a3 = new etudiant("Colpin", "Michel", "M", "Rennes", 29, 8.02f);
etudiant a4 = new etudiant("Michel", "Francois", "M", "Rennes", 29, 8.02f);
enfant_etudiant a5= new enfant_etudiant("Micheline", "Francois", "M", "Rennes", 29, 8.01f);
enfant_etudiant a6 = new enfant_etudiant("Pauline", "Francois", "M", "Rennes", 29, 6.02f);
Console.WriteLine("\n");
Console.WriteLine("\nObjets pour la classe principale:\n");
a.informations(); //apelare functii din clasa parinte pt.obiect precizat (obiect a in acest caz)
a1.informations();
a2.informations();
a3.informations();
a4.informations();
a.quelle_note();
Console.WriteLine("\nObjets pour la classe derive:\n");
a5.informations2();
a6.informations2();
a5.quelle_note1();
a5.meme_note();
// affichage pour la classe derive
//enfant_etudiant enfant_etudiant = new enfant_etudiant();
//enfant_etudiant.print();
//((etudiant) enfant_etudiant).print();
Console.ReadLine();
}
}
} |
Partager