以下是示例代码:

public class Account
{
    public int CreditNo { get; set; }
    public double Balance { get; set; }

    public Account(int creditNo, double balance)
    {
        CreditNo = creditNo;
        Balance = balance;
    }

    public virtual void Deposit(double amount)
    {
        Balance += amount;
    }

    public virtual bool Withdraw(double amount)
    {
        if (Balance >= amount)
        {
            Balance -= amount;
            return true;
        }
        else
        {
            return false;
        }
    }

    public double GetBalance()
    {
        return Balance;
    }
}

public class VipAccount : Account
{
    public VipAccount(int creditNo, double balance) : base(creditNo, balance)
    {
    }

    public override bool Withdraw(double amount)
    {
        if (Balance >= amount - 1000)
        {
            Balance -= amount;
            return true;
        }
        else
        {
            return false;
        }
    }
}

在以上代码中,Account类和VipAccount类都继承自同一个基类Account,而VipAccount类对Withdraw方法进行了重写,以实现允许透支1000元的功能。在使用时,可以通过实例化Account类或VipAccount类来创建普通账户或VIP账户,然后调用它们的方法进行存款、取款和查询余额等操作。

用c#编写在银行储蓄管理系统中普通账户Account和VIP账户VipAccount都包含账户CreditNo、余额Balance等基本数据信息都提供创建账户、存款Withdraw、取款Deposit和查询余额功能但二者的区别是:普通账户的账号介于100000~500000之间取款时不允许透支余额不能0VIP账户的账号在500000~1000000之间取款时允许透支1000元即取款之后余额必须大于

原文地址: https://www.cveoy.top/t/topic/b8bU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录