【发布时间】:2011-09-04 05:31:07
【问题描述】:
我正在做这个项目银行系统
该系统跟踪客户在银行的账户。每个帐户都有一个编号、名称和余额。系统提供以下功能:新建账户、提现、充值、关闭账户。
系统界面如下:
选择:
1- 添加新帐户
2- 提现
3- 存款
4- 获得平衡
5- 退出
当用户选择 1 时,系统会生成一个新 ID,然后要求用户输入该帐户的名称。初始余额设置为零。
当用户选择2时,系统要求用户输入账户ID和提现金额。如果此金额大于余额,则会显示此交易因余额不足而失败的消息。如果余额足够,它会减少提取的金额。
当用户选择 3 时。系统要求用户输入帐户 ID 和要存入的金额。系统会按此金额增加余额。
当用户选择 4 时,系统要求用户输入账户 ID,然后打印账户名称和余额。
每完成一项任务,系统就会返回上面的主菜单,直到用户选择 5。
# include <iostream>
#include <string>
using namespace std;
# include<iomanip>
class Bank
{
private:
char name;
int acno;
float balance;
public:
void newAccount();
void withdraw();
void deposit();
void getbalance();
void disp_det();
};
//member functions of bank class
void Bank::newAccount()
{
cout<<"New Account";
cout<<"Enter the Name of the depositor : ";
cin>>name;
cout<<"Enter the Account Number : ";
cin>>acno;
cout<<"Enter the Amount to Deposit : ";
cin >>balance;
}
void Bank::deposit()
{
float more;
cout <<"Depositing";
cout<<"Enter the amount to deposit : ";
cin>>more;
balance+=more;
}
void Bank::withdraw()
{
float amt;
cout<<"Withdrwal";
cout<<"Enter the amount to withdraw : ";
cin>>amt;
balance-=amt;
}
void Bank::disp_det()
{
cout<<"Account Details";
cout<<"Name of the depositor : "<<name<<endl;
cout<<"Account Number : "<<acno<<endl;
cout<<"Balance : $"<<balance<<endl;
}
// main function , exectution starts here
void main(void)
{
Bank obj;
int choice =1;
while (choice != 5 )
{
cout<<"Enter \n 1- to create new account \n 2- Withdraw\n 3- Deposit \n 4- get balance\n 5 Exit"<<endl;
cin>>choice;
switch(choice)
{
case '1' :obj.newAccount();
break;
case '2' :obj.withdraw();
break;
case 3: obj.deposit();
break;
case 4: getbalance();
break;
case 5:
break;
default: cout<<"Illegal Option"<<endl;
}
}
}
【问题讨论】:
-
请格式化您的问题并具体说明您需要什么。
-
在switch语句的最后,当我想得到余额时,它变成了一个错误!案例4:getbalance();休息;