Skip to content

Instantly share code, notes, and snippets.

@Ambratolm
Created June 25, 2017 14:30
Show Gist options
  • Save Ambratolm/d3b303d769664352a9b39ebcd5073291 to your computer and use it in GitHub Desktop.
Save Ambratolm/d3b303d769664352a9b39ebcd5073291 to your computer and use it in GitHub Desktop.
1. Définir une classe Point caractérisée par son abscisse et son ordonné. 2. Définir à l’aide des getters et les setters les méthodes d’accès aux attributs de la classe. 3. Définir le constructeur par défaut et d’initialisation de la classe. Le constructeur par défaut affecte 0 aux attributs. 4. Définir la méthode Norme ( ) qui retourne la dista…
class Point
{
private int x, y;
public void setx(int x)
{
this.x = x;
}
public int getx()
{
return x;
}
public void sety(int y)
{
this.y = y;
}
public int gety()
{
return y;
}
public Point(int x=0, int y=0)
{
this.x = x;
this.y = y;
}
public double norme()
{
// R² = x² + y² => Norme = RC(R) = RC(x²+y²)
return Math.Sqrt((x*x)+(y*y));
}
}
class Program
{
static void Main(string[] args)
{
Point P = new Point();
Action<string> msgr = s => Console.WriteLine(s);
Action<string> msg = s => Console.Write(s);
//-------------------------------------------------
msgr("Calcul de la norme d'un point dans le plan :");
msg("Entrez l'abscisse (x) du point: "); P.setx(int.Parse(Console.ReadLine()));
msg("Entrez l'ordonnée (y) du point: "); P.sety(int.Parse(Console.ReadLine()));
msgr("La norme du point est: " + P.norme());
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment