【发布时间】:2019-08-14 22:07:50
【问题描述】:
我必须编写以下程序来控制银行帐户(作为作业):
使用命名类 Account 创建程序原型。每个类都有一个所有者名称和余额。
应将以下银行业务添加到程序中: 所有者可以从其帐户中提取金额。添加帐户信息。所有者可以在他的帐户中存入一笔金额。所有者可以将金额转移到另一个帐户。所有者可以查看账户余额。
为了测试程序,必须执行以下程序: 创建两个对象帐户 A1 和 A2;在 A1 中存入 500。在 A2 中存入 200。从 A1 中取出 100。显示 A1 的余额。从 A2 中取出 50。显示 A2 的余额。将 150 从 A1 转移到 A2。
这就是我所做的。我还没有添加ant类,很不完整。
#include <iostream>
using namespace std;
int main () {
int password = 30718042;
int OperationNumber, amount, CurrentBalance, AccountNumber, selection;
cout <<"Welcome FATIH HANCER, please enter your password: ";
cin >> password;
while (password != 30718042) {
cout <<"Please enter your password again. ";
cin >> password;
}
while (password == 30718042) {
cout <<"Please enter your operation number: "<<endl<<"1. Withdraw"<<endl<<"2. Deposit"<<endl<<"3. Transfer"<<endl<<"4. Check the balance"<<endl;
cin >> OperationNumber;
if (OperationNumber == 1) {
cout <<"Please enter the amount you would like to withdraw. "<<endl;
cin >> amount;
int CurrentBalance -= amount;
cout <<"Deposit action is completed. Your new balance is "<<CurrentBalance<<endl;
}
cout <<"\nIf there is another operation to do, please press 1. Otherwise, you will be redirected to the main menu. "<<endl;
cin >> selection;
if (selection != 1) {
cout <<"Thank you for preferring us. "<<endl;
break;
}
}
if (OperationNumber == 2) {
cout <<"Please enter the amount you would like to deposit."<<endl;
cin >> amount;
int CurrentBalance += amount;
cout <<"Deposit action is completed. Your new balance is "<<CurrentBalance<<endl;
}
if (OperationNumber == 3) {
cout <<"Please enter the account number of whom you would like to transfer."<<endl;
cin >> AccountNumber;
while (AccountNumber == 30718059) {
cout <<"Please enter the amount of money you would like to transfer to ABDULRAHMAN SUBH's account"<<endl;
cin >> amount;
int CurrentBalance -= amount;
cout <<"Deposit action is completed. Your new balance is "<<CurrentBalance<<endl;
break;
};
}
while (AccountNumber != 30718059) {
cout <<"The user couldn't be found. ";
break;
}
if (OperationNumber == 4) {
cout <<"Your balance is "<<CurrentBalance<<endl;
}
return 0;
}
如何修复[Error] expected initializer before '-=' token?
此外,我希望余额可以通过提款、存款和转帐进行更改。
【问题讨论】: