| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3626 人关注过本帖
标题:大家来帮我看一下如何把.h文件和.cpp文件,分别放到头文件和源文件中去
取消只看楼主 加入收藏
liuguanglei
Rank: 2
等 级:论坛游民
帖 子:41
专家分:26
注 册:2012-8-15
结帖率:80%
收藏
已结贴  问题点数:10 回复次数:0 
大家来帮我看一下如何把.h文件和.cpp文件,分别放到头文件和源文件中去
//大家来帮我看一下如何把.h文件和.cpp文件,分别放到头文件和源文件中去
//这个程序没有问题的
//对银行账户的对象划分
这个作为.h文件
class Accout
{
private:
    int data;
    int balance;
    int password;
    int password2;
    int ID;//这里应该用数组表示
    double annualInterestRate;
    string name;
public:
    Accout()
    {
        password=0;
        balance=0;
        annualInterestRate=0;
    }
    //对字符操作有点问题
/*    char setname(string myname)
    {
        name=myname;
    }*/
    void setpassword(int mypassword2)
    {
       password2=mypassword2;
    }
    void setdata(int mydata)   
    {
        data=mydata;
    }
    void setID(int myid)
    {
        ID=myid;
    }
    void setdeposit(int mydeposit)
    {
        balance=mydeposit;
    }
    void setmessage(int mypassword)
    {
        password=mypassword;
        
    }
    void setwithdrawals(int mywithdrawals)
    {
        
        if(mywithdrawals>=balance)
            cout<<"您的余额不足!\n";
        else
        {
            cout<<"成功!";
            balance-=mywithdrawals;
        }
    }
    void setannualInterestRate(double myannualInterestRate)
    {
        annualInterestRate=myannualInterestRate;
    }
    int getID()
    {
        return ID;
    }
    int getbalance()
    {
        return balance;
    }
    int getdeposit()
    {
        return balance+(balance*annualInterestRate)*data;
    }
    int getpassword()
    {
        return password;
    }
    int getpassword2()
    {
        return password2;
    }
    //char getname()
    //{
    //    return name;
    //}
};
这个作为.cpp文件
void main()
{
     Accout ti;
     int n,m;
     int k;
     ti.setannualInterestRate(0.005);
     cout<<"****************************个人银行管理系统*****************************"<<endl;
     cout<<endl;
     cout<<endl;
     cout<<"*****************************创建一个用户********************************"<<endl;
     cout<<"请输入您要创建的账号:";
     cin>>n;
     ti.setID(n);
     int i;
     int j;
     printf("请创建您的密码:");
     cin>>i;
     ti.setmessage(i);
     cout<<"您的账户已经创建成功!"<<endl;
//     ti.setname("liuguanglei");
     cout<<"你的当前账户余额为0!"<<"\n";
     cout<<endl;
   while(1)
     {
        cout<<"请您再次输入密码!\n";
        cin>>j;
        ti.setpassword(j);
        if(ti.getpassword()!=ti.getpassword2())
         cout<<"密码错误!";
             else
             {
                  cout<<"请您选择您要操作的菜单:"<<endl;
                  cout<<"1-存款\n"<<"2-取款\n"<<"3-查看余额\n"<<"4-转账操作\n";
                  cout<<endl;
    while(1)
     {
          cin>>m;
          switch(m)
          {
              case 1:cout<<"请输入要存款的数目:\n";
                     cin>>n;
                     cout<<"请输入存款的天数:";
                     cin>>k;
                     ti.setdeposit(n);
                     ti.setdata(k);
                     cout<<"成功!\n"<<"请选择其他功能:\n";break;
              case 2:
                     cout<<"请你输入要取款的金额:";
                     cin>>m;
                     ti.setwithdrawals(m);
                     cout<<"请选择其他功能:\n";break;
              case 3:
                     cout<<"你当前的账户余额为:"<<ti.getdeposit()<<"\n";
                     cout<<"返回!\n";break;
              case 4:
                     cout<<"目前本ATM机在不支持转账功能!!!\n"<<"请选择其他功能:";
          }
    }
             }
   }
}
搜索更多相关主题的帖子: password private balance 
2012-11-20 23:36
快速回复:大家来帮我看一下如何把.h文件和.cpp文件,分别放到头文件和源文件中去 ...
数据加载中...
 
   



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

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