大家来帮我看一下如何把.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"<<"请选择其他功能:";
}
}
}
}
}