Vous êtes sur la page 1sur 7

Correction Question de cours 1pts

1. Citez les composants du .NET Framework? a) b) c) d) e)

Le Common Language Runtime la bibliothque de classes du .NET Framework les donnes et le XML les services Web XML les formulaires Web et les Windows Forms.

2. Cest quoi une assemblie ? est ce possible davoir plusieurs versions de la mme Assembly ? Assembly est le conteneur physique de classes de votre projet

Oui cest possible davoir plusieurs versions de la mme Assembly.


3. Remplir le dessin ci-dessous en respectant lordre avec : code MSIL, compilateur, JIT, source code, Code

natif

Exercice 1
1) Imports System Public Class Salarie Public Matricule As Integer Public Categorie As Integer Public Service As Integer Public Nom As String Public Salaire As Double 2) Public Function CalculerSalaire() As String ' CalculerSalaire = "Le salaire de " + Nom + " est de " + Salaire.ToString + "." Return "Le salaire de " + Nom + " est de " + Salaire.ToString + "." End Function End Class 3) Imports System Public Class MonApplication Public Shared Sub Main() Dim sal As New Salarie sal.Matricule = 1 sal.Categorie = 2 sal.Service = 10 sal.Nom = "Alami" 1

sal.Salaire = 7500.0 Console.WriteLine("Matricule = " + sal.Matricule.ToString) Console.WriteLine("Categorie = " + sal.Categorie.ToString) Console.WriteLine("Service = " + sal.Service.ToString) Console.WriteLine("Nom = " + sal.Nom.ToString) Console.WriteLine("Salaire = " + sal.Salaire.ToString) Console.WriteLine(sal.CalculerSalaire().ToString) Console.ReadLine() End Sub End Class

Exercice 2
1) Imports System Public Class Salarie Private Matricule As Integer Private Categorie As Integer Private Service As Integer Private Nom As String Private Salaire As Double Public Function CalculerSalaire() As String CalculerSalaire = "Le salaire de " + Nom + " est de " + Salaire.ToString + "." End Function ' accesseurs Get Public Function GetMatricule() As Integer GetMatricule = Matricule 'Return Me.Matricule End Function Public Function GetCategorie() As Integer GetCategorie = Categorie End Function Public Function GetService() As Integer GetService = Service End Function Public Function GetNom() As String GetNom = Nom End Function Public Function GetSalaire() As Integer GetSalaire = Salaire End Function ' modificateurs Set Public Function SetMatricule(ByVal matric As Integer) Me.Matricule = matric End Function Public Function SetCategorie(ByVal categ As Integer) Me.Categorie = categ End Function Public Function SetService(ByVal serv As Integer) Me.Service = serv End Function Public Function SetNom(ByVal pnom As String) Me.Nom = pnom 2

End Function Public Function SetSalaire(ByVal sal As Integer) Me.Salaire = sal End Function 2) Imports System Public Class MonApplication Public Shared Sub Main() Dim sal As New Salarie sal.SetMatricule(1) sal.SetCategorie(2) sal.SetService(10) sal.SetNom("Alami") sal.SetSalaire(7500.0) Console.WriteLine("Matricule = " + sal.GetMatricule().ToString) Console.WriteLine("Categorie = " + sal.GetCategorie().ToString) Console.WriteLine("Service = " + sal.GetService().ToString) Console.WriteLine("Nom = " + sal.GetNom().ToString) Console.WriteLine("Salaire = " + sal.GetSalaire().ToString) Console.WriteLine(sal.CalculerSalaire().ToString) Console.ReadLine() End Sub End Class

Exercice 3
1) Constructeurs ' constructeur par dfaut Public Sub New() Matricule = 0 Nom = "TestNom" End Sub ' constructeur d'initialisation Public Sub New(ByVal matricule As Integer, ByVal categorie As Integer, ByVal service As Integer, ByVal nom As String, ByVal salaire As Double) Me.Nom = nom Me.Service = service Me.Salaire = salaire Me.Matricule = matricule Me.Categorie = categorie End Sub 2) Imports System Public Class MonApplication Public Shared Sub Main() Dim sal As New Salarie Console.WriteLine("Matricule = " + sal.GetMatricule().ToString) Console.WriteLine("Categorie = " + sal.GetCategorie().ToString) Console.WriteLine("Service = " + sal.GetService().ToString) Console.WriteLine("Nom = " + sal.GetNom().ToString) Console.WriteLine("Salaire = " + sal.GetSalaire().ToString) Console.WriteLine(sal.CalculerSalaire()) Console.ReadLine() ' tests constructeurs ' par dfaut 3

Dim sal2 As New Salarie Console.WriteLine("Nom = " + sal2.GetNom().ToString) Console.ReadLine() ' d'initialisation ' salari Dim s1 As New Salarie(100, 1, 20, "Rafiq", 12000.00) Console.WriteLine(s1) ' compteur d'instances Dim nInstances As Integer nInstances = Client.GetCompteur Console.WriteLine("compteur clients " & nInstances) Console.ReadLine() End Sub End Class 3) Private Shared compteur As Integer = 0 dclarer dans la classe salarie Public Sub New(ByVal numero As Integer, ByVal nom As String) Me.numeroClient = numero Me.nomClient = nom ' compteur compteur = compteur + 1 End Sub

Exercice 4
1. Public Overrides Function ToString() As String Dim s As String s = Me.Matricule.ToString + " , " + Me.Nom + "," + Me.Service.ToString + "," s = s + Me.Categorie.ToString + " , " s = s + Me.Salaire.ToString Return s End Function Public Overloads Function Equals(ByVal sal As Salarie) As Boolean ' galit de deux salaris If Me.Matricule = sal.Matricule Then Return True Else Return False End If End Function

2. Class commercial
Public Class Commercial Inherits Salarie Private chiffreAffaire As Double ' ca Private commission As Integer ' pourcentage de la commision a) ' Constructeur par dfaut Public Sub New() End Sub ' Constructeur d'initialisation ' constructeur d'initialisation le CA est augment par la mthode AugmenterCA Public Sub New(ByVal matricule As Integer, ByVal categorie As Integer, ByVal service As Integer, ByVal nom As String, ByVal salaire As Double, ByVal ca As Double, ByVal commission As Integer) MyBase.New(matricule, categorie, service, nom, salaire) Me.chiffreAffaire = ca Me.commission = commission b) Public Function GetCommission() As Integer Return Me.commission End Function Public Function GetChiffreAffaire() As Integer Return Me.chiffreAffaire End Function Public Sub SetCommission(ByVal commission As Integer) Me.commission = commission End Sub Public Sub SetChiffreAffaire(ByVal ca As Double) Me.chiffreAffaire = ca End Sub c) Surcharge Public Overrides Function CalculerSalaire() As String Dim salaireComm As Double = GetSalaire() + chiffreAffaire * commission / 100.0 Return "Le salaire de " + GetNom() + " est de " + salaireComm.ToString + "." End Function Public Overrides Function ToString() As String Dim s As String s = MyBase.ToString + "," + chiffreAffaire.ToString + "," s = s + commission.ToString Return s End Function End Sub End Class 5

d) Imports System ' Classe salari avec des Property Public Class Salarie Protected Matricule As Integer Protected Categorie As Integer Protected Service As Integer Protected Nom As String Protected Salaire As Double Public Overridable Function CalculerSalaire() As String ' overridable car rcrite dans la classe Commercial CalculerSalaire = "Le salaire de " + Nom + " est de " + Salaire.ToString + "." End Function ' accesseurs Get Public Function GetMatricule() As Integer GetMatricule = Matricule End Function Public Function GetCategorie() As Integer GetCategorie = Categorie End Function Public Function GetService() As Integer GetService = Service End Function Public Function GetNom() As String GetNom = Nom End Function Public Function GetSalaire() As Integer GetSalaire = Salaire End Function ' modificateurs Set Public Function SetMatricule(ByVal matric As Integer) Me.Matricule = matric End Function Public Function SetCategorie(ByVal categ As Integer) Me.Categorie = categ End Function Public Function SetService(ByVal serv As Integer) Me.Service = serv End Function Public Function SetNom(ByVal pnom As String) Me.Nom = pnom End Function Public Function SetSalaire(ByVal sal As Integer) Me.Salaire = sal End Function ' constructeur par dfaut Public Sub New() Matricule = 0 6

Nom = "rifaa" End Sub ' d'initialisation Public Sub New(ByVal matricule As Integer, ByVal categorie As Integer, ByVal service As Integer, ByVal nom As String, ByVal salaire As Double) Me.Nom = nom Me.Service = service Me.Salaire = salaire Me.Matricule = matricule Me.Categorie = categorie End Sub Public Overrides Function ToString() As String Dim s As String s = Me.Matricule.ToString + " , " + Me.Nom + "," + Me.Service.ToString + "," s = s + Me.Categorie.ToString + " , " s = s + Me.Salaire.ToString Return s End Function Public Overloads Function Equals(ByVal sal As Salarie) As Boolean ' galit de deux salaris If Me.Matricule = sal.Matricule Then Return True Else Return False End If End Function End Class e) Imports System Public Class MonApplication Public Shared Sub Main() Dim sal As New Salarie ' salari Dim s1 As New Salarie(100, 1, 20, "Fouzi", 1200.0) Console.WriteLine(s1) Console.ReadLine() ' commercial Dim comm As New Commercial(150, 2, 30, "alami", 1500.0, 150000.0, 10) Console.WriteLine(comm) Console.ReadLine()