Skip to content

Instantly share code, notes, and snippets.

@Ambratolm
Last active June 25, 2017 19:36
Show Gist options
  • Save Ambratolm/cdac02cfcbd469036b93398e94e5c064 to your computer and use it in GitHub Desktop.
Save Ambratolm/cdac02cfcbd469036b93398e94e5c064 to your computer and use it in GitHub Desktop.
1. Définir une classe Livre avec les attributs suivants : Titre, Auteur (Nom complet), Prix. 2. Définir à l’aide des propriétés les méthodes d’accès aux différents attributs de la classe. 3. Définir un constructeur permettant d’initialiser les attributs de la méthode par des valeurs saisies par l’utilisateur. 4. Définir la méthode Afficher ( ) p…
class Livre
{
private string titre, auteur;
private double prix;
Action<string> msgr = s => Console.WriteLine(s);
Action<string> msg = s => Console.Write(s);
public Livre(string titre="", string auteur="", double prix=0)
{
this.titre = titre;
this.auteur = auteur;
this.prix = prix;
}
public void afficher()
{
msgr( "\tNom du livre : " + titre
+ "\n\tAuteur : " + auteur
+ "\n\tPrix : " + prix );
}
public void set_titre(string titre)
{
this.titre = titre;
}
public void set_auteur(string auteur)
{
this.auteur = auteur;
}
public void set_prix(double prix)
{
this.prix = prix;
}
}
class Program
{
static void Main(string[] args)
{
Action<string> msgr = s => Console.WriteLine(s);
Action<string> msg = s => Console.Write(s);
//-------------------------------------------------
Livre kitabi = new Livre();
Console.ForegroundColor = ConsoleColor.DarkYellow;
msgr("~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Informations d'un livre ~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.ForegroundColor = ConsoleColor.Gray;
msg("Entrez titre: "); kitabi.set_titre(Console.ReadLine());
msg("Entrez auteur: "); kitabi.set_auteur(Console.ReadLine());
msg("Entrez prix: "); kitabi.set_prix(double.Parse(Console.ReadLine()));
msgr("");
Console.ForegroundColor = ConsoleColor.Yellow;
kitabi.afficher();
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment