C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet177/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   173   174   175   176   177   178   179   180   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

AreaPerPerson( )

 that displays the 

area-per-person for a building:

// Add a method to Building.

using System;

class Building {

  public int Floors;    // number of floors

  public int Area;      // total square footage of building

  public int Occupants; // number of occupants

  // Display the area per person.

  public void AreaPerPerson() {

    Console.WriteLine("  " + Area / Occupants + " area per person");

  }

}

// Use the AreaPerPerson() method.



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;

    // Assign values to fields in office.

    office.Occupants = 25;

www.freepdf-books.com



118

 

P a r t   I :  



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

    office.Area = 4200;

    office.Floors = 3;

    Console.WriteLine("house has:\n  " +

                      house.Floors + " floors\n  " +

                      house.Occupants + " occupants\n  " +

                      house.Area + " total area");

    house.AreaPerPerson();

    Console.WriteLine();

    Console.WriteLine("office has:\n  " +

                      office.Floors + " floors\n  " +

                      office.Occupants + " occupants\n  " +

                      office.Area + " total area");

    office.AreaPerPerson();

  }

}

This program generates the following output, which is the same as before:



house has:

  2 floors

  4 occupants

  2500 total area

  625 area per person

office has:

  3 floors

  25 occupants

  4200 total area

  168 area per person

Let’s look at the key elements of this program, beginning with the 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   173   174   175   176   177   178   179   180   ...   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