c++模拟atm机界面程序
时间: 2023-12-30 21:02:58 浏览: 47
好的,以下是一个简单的 C++ ATM 机界面程序的代码示例:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
// 假设银行卡号为 "123456",密码为 "1234"
string cardNo = "123456";
string password = "1234";
string inputCardNo, inputPassword;
int balance = 10000;
cout << "欢迎使用 ATM 机,请插入银行卡:" << endl;
cin >> inputCardNo;
if (inputCardNo != cardNo) {
cout << "银行卡号输入错误!" << endl;
return 0;
}
cout << "请输入密码:" << endl;
cin >> inputPassword;
if (inputPassword != password) {
cout << "密码输入错误!" << endl;
return 0;
}
cout << "登录成功!" << endl;
cout << "请选择操作:" << endl;
cout << "1. 查询余额" << endl;
cout << "2. 取款" << endl;
cout << "3. 存款" << endl;
int option;
cin >> option;
switch (option) {
case 1:
cout << "您的余额为:" << balance << endl;
break;
case 2:
int amount;
cout << "请输入取款金额:" << endl;
cin >> amount;
if (amount > balance) {
cout << "余额不足!" << endl;
} else {
balance -= amount;
cout << "取款成功!" << endl;
cout << "当前余额为:" << balance << endl;
}
break;
case 3:
int deposit;
cout << "请输入存款金额:" << endl;
cin >> deposit;
balance += deposit;
cout << "存款成功!" << endl;
cout << "当前余额为:" << balance << endl;
break;
default:
cout << "无效选项!" << endl;
break;
}
cout << "谢谢使用!" << endl;
return 0;
}
```
这个程序模拟了一个简单的 ATM 机操作,包括登录、查询余额、取款和存款等操作,你可以根据需要进行修改。注意,这只是一个简单的示例程序,实际情况中需要更加完善和安全的实现。