{
Protected double total, free;
Public float Total//Total capacity
{
The get {return total; }
The set {total=value; }
}
The residual capacity of public float Free//
{
The get {return free; }
}
Public virtual void Write (float size)
{
If (free & gt;=the size)
Free -=the size;
The else
Console. WriteLine (" not enough space left!" );
}
Public virtual void the Delete (float size)
{
If (free + size & lt;=total)
Free +=size;
}
}
Public class HardDisk
{
Public HardDisk (float size)
{
This. Total=this. Free=size;
}
}
Public class FlashDisk
{
Public FlashDisk ()
{
This. Total=this. Free=64000;
}
}
Public class CDROM
{
Public override void the Delete (float size)
{
Console. WriteLine (" CD cannot be deleted!" );
}
}
CodePudding user response:
Public class HardDisk : Disk{
Public HardDisk (float size)
{
This. Total=this. Free=size;
}
}
Public class FlashDisk : Disk
{
Public FlashDisk ()
{
This. Total=this. Free=64000;
}
}
Public class CDROM : Disk
{
Public override void the Delete (float size)
{
Console. WriteLine (" CD cannot be deleted!" );
}
}
CodePudding user response:
You say is derived class HardDisk,So why no inheritance relationships?
CodePudding user response:
I didn't change my behind to copy, only the original, after changed to run, no main method errorCodePudding user response:
Main method don't know how to write, I always want to write these in the main, still stays on the structure of the c languageCodePudding user response:
Did you find the Program. The Main function of cs,In call
CodePudding user response:
Public class Disk
{
Private UInt64 m_TotalSize;
Private UInt64 m_UsedSize;
Private bool m_DeleteAble;
Public UInt64 TotalSize
{
The get {return m_TotalSize; }
}
Public UInt64 FreeSize
{
The get {return m_TotalSize - m_UsedSize; }
}
Public UInt64 UsedSize
{
The get {return m_UsedSize; }
Set
{
If (value & gt; TotalSize)
{
Console. WriteLine (" not enough space left!" );
return;
}
M_UsedSize=value;
}
}
Public bool DeleteAble
{
The get {return m_DeleteAble; }
The set {m_DeleteAble=value; }
}
Public virtual bool Write (UInt64 size)
{
UInt64 curUsedSize=UsedSize;
UsedSize +=size;
Return curUsedSize!=UsedSize;
}
Public virtual bool Free (UInt64 size)
{
if( ! DeleteAble)
{
Console. WriteLine (" the disk is not allowed to delete file!" );
return false;
}
If (size & gt; UsedSize)
{
Console. WriteLine (" release space should not be greater than disk use space!" );
return false;
}
UsedSize -=the size;
return true;
}
The public Disk (UInt64 size)
{
M_TotalSize=size;
M_UsedSize=0;
M_DeleteAble=true;
}
}
Public class HardDisk: Disk
{
Public HardDisk (UInt64 size=1024000) : the base (size)
{
}
}
Public class FlashDisk: Disk
{
Public FlashDisk (UInt64 size=64000) : the base (size)
{
}
}
Public class CDROM: Disk
{
Public CDROM (UInt64 size=640000) : the base (size)
{
DeleteAble=false;
}
}