0% found this document useful (0 votes)
13 views

Using System

The document defines two classes - appartement (apartment) and immeuble (building). The appartement class stores attributes of a single apartment like its number, floor, and number of bedrooms. The immeuble class represents a full building by storing an array of appartement objects and providing methods to input data, output data, and calculate the total number of bedrooms across all apartments. The Main method demonstrates creating an immeuble with 2 apartments, collecting input for each, outputting the details, and displaying the total bedrooms.

Uploaded by

marwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Using System

The document defines two classes - appartement (apartment) and immeuble (building). The appartement class stores attributes of a single apartment like its number, floor, and number of bedrooms. The immeuble class represents a full building by storing an array of appartement objects and providing methods to input data, output data, and calculate the total number of bedrooms across all apartments. The Main method demonstrates creating an immeuble with 2 apartments, collecting input for each, outputting the details, and displaying the total bedrooms.

Uploaded by

marwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
class Program
{
public class appartement
{
public int num;
public int etage;
public int nbp;
public appartement() : this(0, 0, 0) { }
public appartement(int x, int y, int z)
{
num = x;
etage = y;
nbp = z;
}
public void saisir()
{
Console.WriteLine("donner un num");
num = Int32.Parse(Console.ReadLine());
Console.WriteLine("donner un etage");
etage = Int32.Parse(Console.ReadLine());
Console.WriteLine("donner nbp");
nbp = Int32.Parse(Console.ReadLine());
}

public void afficher()


{
Console.WriteLine("le num est:" + num + "l'etage est:" + etage + "nbp
est:" + nbp);
}

public class immeuble


{
int nbapp;
appartement[] lesapp;

public immeuble(int nb)


{
nbapp = nb;
lesapp = new appartement[nb];
for (int i = 0; i < nb; i++) { lesapp[i] = new appartement(); }

}
public void saisir()
{
for (int i = 0; i < lesapp.Length; i++)
{
lesapp[i] = new appartement();
lesapp[i].saisir();

}
}
public void afficher()
{
foreach (appartement b in lesapp)
b.afficher();
}
public int NbTotale()
{
int ps = 0;
foreach (appartement b in lesapp)
{
ps = ps + b.nbp;
}
return ps;
}

static void Main(string[] args)


{
//appartement a = new appartement();
// a.saisir();
// a.afficher();

immeuble i = new immeuble(2);


i.saisir();
i.afficher();
Console.WriteLine("le nombre totale:" + i.NbTotale());
Console.ReadLine();
}

}
}

You might also like