钱能C++教材习题答案十三

   /2005-05-08

 

Account::Account(unsigned accNo,float balan)
{
        acntNumber=accNo;
        balance=balan;
        pNext=0;
        count++;
        if(pFirst==0)
                pFirst=this;
        else
        {
                Account * pS=pFirst;
                for(;pS->pNext;pS=pS->pNext);
                pS->pNext=this;
        }
        pNext=0;
}

unsigned Account::AccountNo()
{
        return acntNumber;
}

float Account::AcntBalan()
{
        return balance;
}

Account * Account::First()
{
        return pFirst;
}

Account * Account::Next()
{
        return pNext;
}

int Account::NoAccounts()
{
        return count;
}

void Account:isplay()
{
        cout<<"Account number:"<<acntNumber
                <<"    balance:"<<balance<<endl;
}

void Account:esposit(float amount)
{
        balance+=amount;
}

void Account::Withdrawal(float amount)
{
        return;
}
//****************************************************************************
class Savings:public Account
{
        public:
                Savings(unsigned accNo,float balan=0.0);
                virtual void Withdrawal(float amount);
                void Display();
        protected:
                static float minbalance;
};
//****************************************************************************
float Savings::minbalance=500.0;
void Savings:isplay()
{
        cout<<"Savings number:"<<acntNumber
                <<"    balance:"<<balance
                <<"    minbalance:"<<minbalance<<endl;
}
Savings::Savings(unsigned accNo,float balan):Account(accNo,balan)
{

}

void Savings::Withdrawal(float amount)
{
        if(balance+minbalance<amount)
                cout<<"Insufficient funds:balance"<<balance
                        <<",withdramal"<<amount<<endl;
        else
                balance-=amount;
}
//****************************************************************************
enum REMIT{remitByPost,remitByCable,other};

class Checking:public Account
{
        public:
                Checking(unsigned accNo,float balan=0.0);
                virtual void Withdrawal(float amount);
                void SetRemit(REMIT re);
                void Display();
        protected:
                REMIT remittance;
};
//****************************************************************************
void Checking:isplay()
{
        cout<<"Checking number:"<<acntNumber
                <<"    balance:"<<balance
                <<"    remittance:"<<remittance<<endl;
}
Checking::Checking(unsigned accNo,float balan):Account(accNo,balan)
{
        remittance=other;
}

void Checking::Withdrawal(float amount)
{
        float temp=amount;
        if(remittance==remitByPost)
                temp=amount+30;
        else if(remittance==remitByCable)
                temp=amount+60;

        if(balance<temp)
                cout<<"Insufficient funds:balance"<<balance
                        <<"   ,withdrawal"<<temp<<endl;
        else
                balance-=temp;
}

void Checking::SetRemit(REMIT re)
{
        remittance=re;
}
//****************************************************************************

void main()
{
        Savings s0(0,0);
        Savings s1(12,123);
        Savings s2(123,123);
        Savings s3(124,123);
        Savings s4(125,123);

        Checking c0(0,0);
        Checking c1(12,123);
        Checking c2(123,123);
        Checking c3(124,123);
        Checking c4(125,123);
       
        int i;
        cout<<"1---储蓄帐户    2---结算帐户";
        cout<<"            请选择帐户类型:";
        cin>>i;
        cout<<endl;
while (1)
{
        Account *  p=s0.First();       
        Account *  q=c0.First();
        if (i==1)
        {
                int j;
                cout<<"请选择交易方式:1---存款    2---取款  :";
                cin>>j;
                cout<<endl;
                if (j==1)
                {
                        unsigned k;
                        cout<<"请输入帐户号码:";
                        cin>>k;
                        for( ;(p!=NULL)&&(p->AccountNo()!=k);        p=p->Next() )
                        {
                                ;
                        }
                       
                        if(p==NULL)
                        {
                                float x;
                                cout<<"请输入存款数量:";
                                cin>>x;
                                p=new Savings(k,x);
                        }
                        else
                        {
                                float y;
                                cout<<"请输入存款数量:";
                                cin>>y;
                                p->Desposit(y);
                        }
                }

               if (j==2)
                {
                        unsigned k;
                        cout<<"请输入帐户号码:";
                        cin>>k;
                        for( ;(p!=NULL)&&(p->AccountNo()!=k);        p=p->Next() )
                        {
                                ;
                        }
                        if(p==NULL)
                        {
                                cout<<"该帐户不存在";
                                break;


相关话题/

  • 领限时大额优惠券,享本站正版考研考试资料!
    大额优惠券
    优惠券领取后72小时内有效,10万种最新考研考试考证类电子打印资料任你选。涵盖全国500余所院校考研专业课、200多种职业资格考试、1100多种经典教材,产品类型包含电子书、题库、全套资料以及视频,无论您是考研复习、考证刷题,还是考前冲刺等,不同类型的产品可满足您学习上的不同需求。 ...
    本站小编 Free壹佰分学习网 2022-09-19