C# 0 The Complete Reference


TwoDShape  and  Triangle



Download 4,07 Mb.
Pdf ko'rish
bet384/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   380   381   382   383   384   385   386   387   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

TwoDShape

 and 


Triangle

. Both 


add constructors that take an object as a parameter.

// Pass a derived class reference to a base class reference.

using System;

class TwoDShape {

  double pri_width;

  double pri_height;

  // Default constructor.

  public TwoDShape() {

    Width = Height = 0.0;

  }


  // Constructor for TwoDShape.

  public TwoDShape(double w, double h) {

    Width = w;

    Height = h;

  }

  // Construct object with equal width and height.



  public TwoDShape(double x) {

    Width = Height = x;

  }

www.freepdf-books.com




292

 

P a r t   I :  



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

  // Construct a copy of a TwoDShape object.

  public TwoDShape(TwoDShape ob) {

    Width = ob.Width;

    Height = ob.Height;

  }


  // Properties for Width and Height.

  public double Width {

     get { return pri_width; }

     set { pri_width = value < 0 ? -value : value; }

  }

  public double Height {



     get { return pri_height; }

     set { pri_height = value < 0 ? -value : value; }

  }

  public void ShowDim() {



    Console.WriteLine("Width and height are " +

                       Width + " and " + Height);

  }

}

// A derived class of TwoDShape for triangles.



class Triangle : TwoDShape {

  string Style;

  // A default constructor.

  public Triangle() {

    Style = "null";

  }


  // Constructor for Triangle.

  public Triangle(string s, double w, double h) : base(w, h) {

    Style = s;

  }


  // Construct an isosceles triangle.

  public Triangle(double x) : base(x) {

    Style = "isosceles";

  }


  // Construct a copy of a Triangle object.

  public Triangle(Triangle ob) : base(ob) {

    Style = ob.Style;

  }


  // Return area of triangle.

  public double Area() {

    return Width * Height / 2;

  }


www.freepdf-books.com


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   380   381   382   383   384   385   386   387   ...   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