Last active
June 25, 2017 19:48
-
-
Save Ambratolm/497d0986cc48a68f66d9e9738fc12a0e to your computer and use it in GitHub Desktop.
1. Définir une classe Rectangle ayant les attributs suivants : Longueur et Largeur. 2. Définir à l’aide des propriétés les méthodes d’accès aux attributs de la classe. 3. Ajouter un constructeur d’initialisation. 4. Ajouter les méthodes suivantes : Périmètre() : retourne le périmètre du rectangle. Aire() : retourne l'aire du rectangle. EstCarre(…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle | |
{ | |
private double longueur, largeur; | |
public double Largeur | |
{ | |
get { return largeur; } | |
set { largeur = value; } | |
} | |
public double Longueur | |
{ | |
get { return longueur; } | |
set { longueur = value; } | |
} | |
public Rectangle(double longueur=0, double largeur=0) | |
{ | |
this.longueur = longueur; | |
this.largeur = largeur; | |
} | |
public void AfficherRectangle() | |
{ | |
string carre_ou_non = (EstCarre() == true) ? "Il s'agit d'un carré !" : "Il ne s'agit pas d'un carré."; | |
Console.ForegroundColor = ConsoleColor.White; | |
Console.WriteLine("\n\tLongueur : " + longueur + | |
"\n\tLargeur : " + largeur + | |
"\n\tPérimètre : " + Perimetre() + | |
"\n\tAire : " + Aire() + "\n\t" + | |
carre_ou_non); | |
Console.ResetColor(); | |
} | |
private bool EstCarre() | |
{ | |
if (longueur == largeur) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
private double Aire() | |
{ | |
return longueur * largeur; | |
} | |
private double Perimetre() | |
{ | |
return 2 * (longueur + largeur); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
start: | |
Rectangle abcd = new Rectangle(); | |
Console.WriteLine("Caractéristiques d'un rectangle"); | |
Console.WriteLine(""); | |
Console.Write("Entrez la longueur: "); abcd.Longueur = double.Parse(Console.ReadLine()); | |
Console.Write("Entrez la largeur: "); abcd.Largeur = double.Parse(Console.ReadLine()); | |
abcd.AfficherRectangle(); | |
Console.ReadKey(); | |
Console.Clear(); | |
goto start; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment