C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet188/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   184   185   186   187   188   189   190   191   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

MaxOccupant( )

 is called, the parameter 



minArea

 receives the minimum space 

needed for each occupant. The method divides the total area of the building by this value 

and returns the result.

The entire 

Building

 class that includes 



MaxOccupant( )

 is shown here:

/*

   Add a parameterized method that computes the



   maximum number of people that can occupy a

   building assuming each needs a specified

   minimum space.

*/

using System;



class Building {

  public int Floors;    // number of floors

  public int Area;      // total square footage of building

  public int Occupants; // number of occupants

  // Return the area per person.

  public int AreaPerPerson() {

    return Area / Occupants;

  }


  // Return the maximum number of occupants if each

  // is to have at least the specified minimum area.

  public int MaxOccupant(int minArea) {

    return Area / minArea;

  }

}

// Use MaxOccupant().



class BuildingDemo {

  static void Main() {

    Building house = new Building();

    Building office = new Building();

    // Assign values to fields in house.

    house.Occupants = 4;

    house.Area = 2500;

    house.Floors = 2;

www.freepdf-books.com



126

 

P a r t   I :  



T h e   C #   L a n g u a g e

    // Assign values to fields in office.

    office.Occupants = 25;

    office.Area = 4200;

    office.Floors = 3;

    Console.WriteLine("Maximum occupants for house if each has " +

                      300 + " square feet: " +

                      house.MaxOccupant(300));

    Console.WriteLine("Maximum occupants for office if each has " +

                      300 + " square feet: " +

                      office.MaxOccupant(300));

  }


}

The output from the program is shown here:

Maximum occupants for house if each has 300 square feet: 8

Maximum occupants for office if each has 300 square feet: 14




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   184   185   186   187   188   189   190   191   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish