类的数组
我写的程序里变异好多问题啊;求教高手帮我更该下啊#include<iostream>
using namespace std;
#include<string.h>
const NUM=100;
class Account
{
private:
char mName[20]; //银行账户的户名
long mSN; //本账户的帐号
float mBalance; //本账户当前的余额
static int id;
public:
Account(char name[],long num,float amount); //类的构造函数
~Account(); //类的析构函数
void deposit(); //往账户中存款
int withdraw(float amount); //从账户中取款
float getBalance(); //查询余额
};
//构造函数的实现
Account::Account(char name[],long num,float amount)
{
strcpy(mName,name);
mSN=num;
mBalance=amount;
}
//存款函数的实现
void Account::deposit()
{
float money;
cout<<"请输入存款金额";
cin>>money;
mBalance+=money;
}
//取款函数的实现
int Account::withdraw(float amount)
{
if(amount>mBalance)
cout<<"账户余额不足,请充值!!";
else
{
mBalance+=amount;
cout<<"取款成功";
}
}
//查询函数的实现
float Account::getBalance()
{
cout<<"您的账户余额为:"<<mBalance;
}
//显示菜单的实现
void menu()
{
system("cls");
cout<<"*************************"<<endl;
cout<<"*************************"<<endl;
cout<<"1.开户"<<endl;
cout<<"2.取款"<<endl;
cout<<"3.存款"<<endl;
cout<<"4.查询"<<endl;
cout<<"5.退出"<<endl;
cout<<"*************************"<<endl;
cout<<"*************************"<<endl;
}
//对账户操作时寻找正确的账户
int judge(Account a[],int m)
{
long mark;
int i,n;
cout<<"请输入您的账号:";
cin>>mark;
for(i=0;i<m;i++)
{
if(a[i].mSN==mark)
{
n=i;
return n;
}
else
cout<<"您输入的账号有误!!";
}
}
//主函数的实现
void main()
{
int choice;
int NO;
float money;
Account::id=0;
Account obj[NUM];
while(1)
{ menu();
cout<<"请输入您的选择:";
cin>>choice;
switch(choice){
case 1:
char name[20]; //用户姓名
long num; //用户账号
float amount; //账户进额
cout<<"请输入您的信息:"<<endl;
cout<<"姓名:";
cin>>name;
cout<<"账号:";
cin>>num;
cout<<"金额:";
cin>>amount;
strcpy(obj[Account::id].mName,name);
obj[Account::id].mSN=num;
obj[Account::id].mBalance=account;
Account::id++;
break;
case 2:
NO=judge(obj[],i);
cout<<"请输入您的取款金额:";
cin>>money;
obj[NO].withdraw(money);
break;
case 3:
NO=judge(obj[],i);
cout<<"请输入您的存款金额:";
obj[NO].deposit();
break;
case 4:
NO=judge(obj[],i);
obj[NO].getBalance();
break;
case 5:
return 0;
}