C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet169/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   165   166   167   168   169   170   171   172   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Floors

,

Area

, and 

Occupants

, and 


the contents of these can (and often will) differ between the two objects. The following 

program demonstrates this fact:

// This program creates two Building objects.

using System;

class Building {

  public int Floors;    // number of floors

  public int Area;      // total square footage of building

  public int Occupants; // number of occupants

}

// This class declares two objects of type Building.



class BuildingDemo {

  static void Main() {

    Building house = new Building();

    Building office = new Building();

    int areaPP; // area per person

    // Assign values to fields in house.

    house.Occupants = 4;

    house.Area = 2500;

    house.Floors = 2;

    // Assign values to fields in office.

    office.Occupants = 25;

    office.Area = 4200;

    office.Floors = 3;

    // Compute the area per person in house.

    areaPP = house.Area / house.Occupants;

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

                      house.Floors + " floors\n  " +

                      house.Occupants + " occupants\n  " +

                      house.Area + " total area\n  " +

                      areaPP + " area per person");

www.freepdf-books.com



114

 

P a r t   I :  



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

    Console.WriteLine();

    // Compute the area per person in office.

    areaPP = office.Area / office.Occupants;

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

                      office.Floors + " floors\n  " +

                      office.Occupants + " occupants\n  " +

                      office.Area + " total area\n  " +

                      areaPP + " area per person");

  }


}

The output produced by this program is shown here:

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

As you can see, 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   165   166   167   168   169   170   171   172   ...   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