我正在做这个项目银行系统
该系统跟踪客户在银行的账户。每个帐户都有一个编号、名称和余额。系统提供以下功能:创建新账户、提现、存款和关闭账户。
系统界面如下:
选择:
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;
}
}
}
最佳答案
问题 1:
您在获取余额的方法和您正在调用的方法中输入错误,将 Bank::disp_det()
重命名为 Bank::getbalance()
void Bank::getbalance()
{
cout<<"Account Details";
cout<<"Name of the depositor : "<<name<<endl;
cout<<"Account Number : "<<acno<<endl;
cout<<"Balance : $"<<balance<<endl;
}
问题 2:
您不是通过 Bank
的对象调用 Bank::getbalance
,因为它是一个成员函数,您应该按如下方式调用它:
case 4:
obj.getbalance();
break;
关于c++:如何获得余额(在银行系统中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166639/