| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 668 人关注过本帖
标题:请假一下,这道题怎么做啊
只看楼主 加入收藏
yueqi933
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-5-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
请假一下,这道题怎么做啊
使用抽象类,实现银行账户的概念,包括的字段有“账号”、“储户姓名”、“存款余额”,包括的方法有“存款”、“取款”、“查询”、“计算存款的利息”。实现银行定期存款账户、银行活期存款账户。要求:输出这两个账户的信息(帐号,储户姓名,存款余额,存款的利息)   附:   活期是0.5%   定期:三个月2.85%半年3.05%一年3.25%二年4.15%三年4.75%五年5.25%
用C++写
搜索更多相关主题的帖子: 定期存款 活期存款 姓名 银行 账号 
2011-05-28 23:36
记叙、继续
Rank: 4
等 级:业余侠客
帖 子:56
专家分:226
注 册:2011-5-17
收藏
得分:0 
这道在c+语言教程上面有,你不防去新华书店看看,手机上就不方便写出来拉
2011-05-29 03:01
yueqi933
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-5-28
收藏
得分:0 
大家帮帮忙啊...这题怎么做啊
2011-05-29 13:59
df19861017
Rank: 2
等 级:论坛游民
帖 子:15
专家分:29
注 册:2010-9-30
收藏
得分:0 
使用继承不就搞定了吗?父类中将方法定义为虚函数
2011-05-29 14:15
yueqi933
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-5-28
收藏
得分:0 
求余额的帮忙看下要怎么改啊
class Account
{
public:Account(double Initialbalance){balance=Initialbalance;}
double GetBalance(){return balance;}
private:
double balance;
};
void main()
{
double balance=(balance*(1+0.005))
class Account Checking(Account);
cout<<"账户余额:"<<Checking.GetBalance()<<"\n";
}
2011-05-29 14:19
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:20 
程序代码:
#include <windows.h>
#include <iostream>
using namespace std;

const LPSTR Msg = "系统提示信息...";
CHAR buffer[20];

class Account
{
public:
    VOID SaveMoney(UINT money);//存款
    BOOL DrawMoney(UINT money);//取款
    virtual VOID Query();//查询
    virtual DOUBLE Interest() = 0;//计算存款利息
protected:
    LPSTR m_ID;//账号
    LPSTR m_Name;//姓名
    UINT m_ReSum;//余额
};

VOID Account::SaveMoney(UINT money)
{
    m_ReSum += money;
    ZeroMemory(buffer, sizeof(CHAR)*20);
    wsprintf(buffer, "存款成功! 存款金额为: %u", money);
    MessageBox(NULL, buffer, Msg, MB_OK);
}

BOOL Account::DrawMoney(UINT money)
{
    ZeroMemory(buffer, sizeof(CHAR)*20);

    if (money > m_ReSum)
    {
        MessageBox(NULL, "余额不足", Msg, MB_OK);
        return FALSE;
    }
    m_ReSum -= money;
    wsprintf(buffer, "取款成功! 取款金额为: %u", money);
    MessageBox(NULL, buffer, Msg, MB_OK);

    return TRUE;
}

VOID Account::Query()
{
    cout << "\t账号: " << m_ID << endl;
    cout << "\t姓名: " << m_Name << endl;
    cout << "\t余额: " << m_ReSum << endl;
}

class FixAccount:public Account
{
public:
    FixAccount(LPSTR id, LPSTR name, UINT money, UINT months);
    ~FixAccount();
    VOID Query();//查询
    DOUBLE Interest();//计算存款利息
protected:
    UINT m_Month;
};
FixAccount::FixAccount(LPSTR id, LPSTR name, UINT money, UINT months)
{
    HANDLE heap = GetProcessHeap();

    m_ID = (LPSTR) HeapAlloc (heap, HEAP_ZERO_MEMORY, lstrlen(id)+1);
    CopyMemory(m_ID, id, lstrlen(id));
    m_Name = (LPSTR) HeapAlloc (heap, HEAP_ZERO_MEMORY, lstrlen(name)+1);
    CopyMemory(m_Name, name, lstrlen(name));
    m_ReSum = money;
    m_Month = months;
}
FixAccount::~FixAccount()
{
    HANDLE heap = GetProcessHeap();

    HeapFree( heap, HEAP_NO_SERIALIZE, m_ID);
    m_ID = NULL;
    HeapFree( heap, HEAP_NO_SERIALIZE, m_Name);
    m_Name = NULL;
}
VOID FixAccount::Query()
{
    Account::Query();
    cout << "\t时间: " << m_Month << endl;
    cout << "\t利息: " << Interest() << endl;
}
DOUBLE FixAccount::Interest()
{
    if (m_Month >= 60)
    {
        return 0.0525;
    }
    else if (m_Month >= 36)
    {
        return 0.0475;
    }
    else if (m_Month >= 24)
    {
        return 0.0415;
    }
    else if (m_Month >= 12)
    {
        return 0.0325;
    }
    else if (m_Month >= 6)
    {
        return 0.0305;
    }
    else if (m_Month >= 3)
    {
        return 0.0285;
    }
    else
    {
        return 0;
    }
}

class CurrAccount:public Account
{
public:
    CurrAccount(LPSTR id, LPSTR name, UINT money);
    ~CurrAccount();
    VOID Query();//查询
    DOUBLE Interest();//计算存款利息
};
CurrAccount::CurrAccount(LPSTR id, LPSTR name, UINT money)
{
    HANDLE heap = GetProcessHeap();

    m_ID = (LPSTR) HeapAlloc (heap, HEAP_ZERO_MEMORY, lstrlen(id)+1);
    CopyMemory(m_ID, id, lstrlen(id));
    m_Name = (LPSTR) HeapAlloc (heap, HEAP_ZERO_MEMORY, lstrlen(name)+1);
    CopyMemory(m_Name, name, lstrlen(name));
    m_ReSum = money;
}
CurrAccount::~CurrAccount()
{
    HANDLE heap = GetProcessHeap();

    HeapFree( heap, HEAP_NO_SERIALIZE, m_ID);
    m_ID = NULL;
    HeapFree( heap, HEAP_NO_SERIALIZE, m_Name);
    m_Name = NULL;
}
VOID CurrAccount::Query()
{
    Account::Query();
    cout << "\t利息: " << Interest() << endl;
}
DOUBLE CurrAccount::Interest()
{
    return 0.005;
}

VOID Factory(Account *account)
{
    account->Query();
//    account->SaveMoney(1);
//    account->DrawMoney(1);
    cout << endl;
}

INT main(VOID)
{
//    FixAccount *fix=NULL;
//    CurrAccount *cur=NULL;
    Factory(new FixAccount("54321", "红色的吉他", 1000, 64));
    Factory(new CurrAccount("9958", "蓝色的外套", 1110));

    return 0;
}
2011-05-29 16:19
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
余额 不知道应该做成什么样子滴  自己根据具体的情况改吧
2011-05-29 16:22
laigaoat2005
Rank: 4
等 级:业余侠客
帖 子:388
专家分:226
注 册:2007-4-5
收藏
得分:0 
啊,做好了关网了。来电了,怎么帖子都结了?
还是把心血发出来吧,汗!
程序代码:
/*Author laigaoat2005    Debug cfree 5.0 date:2011 5 29
******************************************************
** 呵呵,没有挣到分,倒让我好好复习了继承
******************************************************
//*/

#include <string>
#include <iostream>
using namespace std;
//使用抽象类实现银行账户的概念,包括字段有 账号 储户姓名 存款余额
//包括的方法有 存款 取款 查询 计算存款的利息
//实现银行定期存款账户、银行活期存款账户。
//要求:输出这两个账户的信息(帐号,储户姓名,存款余额,存款的利息)  
//附:活期是0.5%   定期:三个月2.85% 半年3.05% 一年3.25% 二年4.15% 三年4.75% 五年5.25% 用C++写
class account;
class account_ding;
class account_huo;
ostream& operator<<(account_huo&,ios os);
ostream& operator<<(account_ding&,ios os);
class account{
public:
    void deposit(float);//存款
    void draw(float);//取款
    float query();//查询余额
    virtual float evaluate(int){}; //计算利息    
protected:
    account(int, string&, float,int);
    int _number; //帐号 (只是示范,用float.实际帐号数位很长且不能重复,float是不行的。 )
    string _name;  //姓名
    float _balance; //余额
    int _month;  //
    float _interest; //利息
   
    float _rate;  //利率    
private:
    account(); //禁止空名帐户
};
account::account(int _num, string& _nam, float _bal,int _mon)
        :_number(_num),_name(_nam),_balance(_bal),_month(_mon),_rate(0.005){}
void account::deposit(float _money)
{
    _balance += _money;
}
void account::draw(float _money)
{
    _balance -= _money;
}
float account::query()
{
    return _balance;
}

class account_huo:public account
{
friend ostream& operator<<(ostream& os, account_huo&);
public:
    account_huo( int, string&, float) ;
    virtual float evaluate(float);
};
account_huo::account_huo( int _num, string& _nam, float _bal):account(_num,_nam,_bal,0){}
float account_huo::evaluate(float mon)
{
    return _balance*_rate*mon;  //最好弄个成员存起来。也不知道算利息是不是这么算的,汗! 

}

class account_ding:public account{
friend ostream& operator<<(ostream& os, account_ding&);
public:
    account_ding(int, string&, float,int);
    virtual float evaluate(int);   
};

account_ding::account_ding( int _num, string& _nam, float _bal,int _mon):account(_num,_nam,_bal,_mon){}
float account_ding::evaluate(int mon)
{
    switch(mon)
    {
        case 3:
            _rate=0.0285;
            break;
        case 6:
            _rate=0.0305;
            break;
        case 12:
            _rate=0.0325;
            break;
        case 24:
            _rate=0.0415;
            break;
        case 36:
            _rate=0.0475;
            break;
        case 60:
            _rate=0.0525;
            break;
        default:
            printf("参数有错!\n");
            return 0;
    }
    return _balance*_rate*mon;
}

ostream& operator<<(ostream& os, account_ding& acc)
{   
    os << "帐号: " << acc._number   << endl
       << "姓名: " << acc._name       << endl
       << "余额: " << acc._balance   << endl
       << "时期: " << acc._month       <<  "个月        (说明:0为活期(也可以加个if直接写活期))" <<endl
       << "利率: " << acc._interest     << endl
       << "利息: " << acc._rate         << endl  <<  endl  ;
       //*/
    return     os;
}
ostream& operator<<(ostream& os, account_huo& acc)
{   
    os << "帐号: " << acc._number  << endl
       << "姓名: " << acc._name        << endl
       << "余额: " << acc._balance   << endl
       << "时期: " << acc._month       << "个月         (说明:0为活期(也可以加个if直接写活期))" <<endl
       << "利率: " << acc._interest      << endl
       << "利息: " << acc._rate         << endl  <<  endl  ;
       //*/
    return     os;
}

int main()
{
    string A("客户姓名A");
    string B("客户姓名B");
        //参数有: int _num, string& _nam, float _bal,int _mon
    //account_huo( int, string&, float) ;
    account_huo user_A(56,A,888);
    account_ding user_b(57,B,999,24);
    cout << user_A << user_b;
    return 0;
}

 
2011-05-29 20:34
快速回复:请假一下,这道题怎么做啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023391 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved