用c++写一个游乐园系统,游客需要注册,登录,充值后买票,票的种类为单人票,团购票和月票,买完票后提示顾客余额,并计算游乐场一天的营业额
时间: 2023-12-10 18:06:11 浏览: 36
好的,这是一个比较大的项目,需要分步骤来完成。
首先,我们需要设计一个游客类,其中包含游客的基本信息,如用户名、密码、余额等:
```cpp
class Tourist {
public:
Tourist(string username, string password, double balance) :
_username(username), _password(password), _balance(balance) {}
string getUsername() { return _username; }
string getPassword() { return _password; }
double getBalance() { return _balance; }
void setBalance(double balance) { _balance = balance; }
private:
string _username;
string _password;
double _balance;
};
```
接下来,我们需要实现一个注册函数和一个登录函数:
```cpp
vector<Tourist> tourists;
void register() {
string username, password;
double balance;
cout << "请输入用户名:";
cin >> username;
cout << "请输入密码:";
cin >> password;
cout << "请输入余额:";
cin >> balance;
tourists.push_back(Tourist(username, password, balance));
cout << "注册成功!" << endl;
}
Tourist* login() {
string username, password;
cout << "请输入用户名:";
cin >> username;
cout << "请输入密码:";
cin >> password;
for (int i = 0; i < tourists.size(); i++) {
if (tourists[i].getUsername() == username && tourists[i].getPassword() == password) {
cout << "登录成功!" << endl;
return &tourists[i];
}
}
cout << "用户名或密码错误!" << endl;
return NULL;
}
```
然后,我们需要实现一个充值函数:
```cpp
void recharge(Tourist* tourist) {
double balance;
cout << "请输入充值金额:";
cin >> balance;
tourist->setBalance(tourist->getBalance() + balance);
cout << "充值成功!当前余额为:" << tourist->getBalance() << endl;
}
```
接下来,我们需要实现一个购买票的函数,包括单人票、团购票和月票三种:
```cpp
void buyTicket(Tourist* tourist) {
int type;
cout << "请选择票的种类:1. 单人票 2. 团购票 3. 月票" << endl;
cin >> type;
switch (type) {
case 1:
if (tourist->getBalance() < 100) {
cout << "余额不足,购买失败!" << endl;
break;
}
tourist->setBalance(tourist->getBalance() - 100);
cout << "购买单人票成功!当前余额为:" << tourist->getBalance() << endl;
break;
case 2:
if (tourist->getBalance() < 80) {
cout << "余额不足,购买失败!" << endl;
break;
}
tourist->setBalance(tourist->getBalance() - 80);
cout << "购买团购票成功!当前余额为:" << tourist->getBalance() << endl;
break;
case 3:
if (tourist->getBalance() < 500) {
cout << "余额不足,购买失败!" << endl;
break;
}
tourist->setBalance(tourist->getBalance() - 500);
cout << "购买月票成功!当前余额为:" << tourist->getBalance() << endl;
break;
default:
cout << "输入错误!" << endl;
break;
}
}
```
最后,我们需要实现一个计算营业额的函数:
```cpp
double calculateRevenue() {
int count1 = 0, count2 = 0, count3 = 0;
for (int i = 0; i < tourists.size(); i++) {
if (tourists[i].getBalance() < 100) {
continue;
}
if (tourists[i].getBalance() >= 500) {
count3++;
} else if (count2 < 10) {
count2++;
} else {
count1++;
}
}
double revenue = count1 * 100 + count2 * 80 + count3 * 500;
return revenue;
}
```
以上就是一个简单的游乐园系统的实现,包括注册、登录、充值、购买票和计算营业额等功能。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)