帮我写一个数据结构课设,要求如下设银行有四个服务窗口,每个窗口均可以办理存款、取款、挂失、还贷业务,每种业务所需的服务时间不同,客户到达银行后,先到打号机上打号,号票上包括到达时间、编号和需要办理的业务,然后在银行内等候。每个窗口办理完一个客户的业务后,办理等候客户中排在最前面的客户的业务。写一个上述银行业务的模拟系统,通过模拟方法求出客户在银行内逗留的平均时间和每个窗口办理的客户数及办理的每种业务数。基本要求:每个客户到达银行的时间和需要办理的业务随机产生,输出一天客户在银行的平均逗留时间和每个窗口每天办理的客户数和每种业务数。测试数据:营业时间为8小时,其他模拟量自行设定。
时间: 2024-03-01 15:55:56 浏览: 47
数据结构课设模拟银行业务
4星 · 用户满意度95%
好的,这是一个比较复杂的课设,需要考虑很多细节问题。我可以给出一些思路和代码示例供您参考。
1. 定义客户和服务窗口的结构体
```c
typedef struct {
int arrive_time; // 到达时间
int service_time; // 服务时间
int service_type; // 服务类型
int id; // 编号
} Customer;
typedef struct {
int current_service_time; // 当前正在服务的客户的剩余服务时间
int current_service_type; // 当前正在服务的客户的服务类型
int total_customers; // 总共服务的客户数
int total_service_time[4]; // 每种服务类型的总服务时间
} ServiceWindow;
```
2. 随机产生客户和服务时间
```c
int get_random(int min, int max) {
return rand() % (max - min + 1) + min;
}
void generate_customer(Customer *customer, int id) {
customer->id = id;
customer->arrive_time = get_random(0, 480); // 营业时间为8小时,即480分钟
customer->service_type = get_random(0, 3);
switch (customer->service_type) {
case 0: // 存款
customer->service_time = get_random(1, 5);
break;
case 1: // 取款
customer->service_time = get_random(2, 6);
break;
case 2: // 挂失
customer->service_time = get_random(5, 10);
break;
case 3: // 还贷
customer->service_time = get_random(10, 20);
break;
default:
break;
}
}
```
3. 实现银行模拟系统的主要逻辑
```c
#define MAX_CUSTOMERS 1000
int main() {
Customer customers[MAX_CUSTOMERS];
int total_customers = 0;
ServiceWindow windows[4];
for (int i = 0; i < 4; i++) {
windows[i].current_service_time = 0;
windows[i].current_service_type = -1;
windows[i].total_customers = 0;
for (int j = 0; j < 4; j++) {
windows[i].total_service_time[j] = 0;
}
}
int current_time = 0;
int next_customer_id = 0;
while (current_time < 480 || total_customers < MAX_CUSTOMERS) { // 营业时间为8小时
// 产生新客户
if (current_time < 480 && total_customers < MAX_CUSTOMERS && rand() % 5 == 0) {
generate_customer(&customers[total_customers], next_customer_id);
next_customer_id++;
total_customers++;
}
// 处理客户
for (int i = 0; i < 4; i++) {
if (windows[i].current_service_time > 0) {
windows[i].current_service_time--;
if (windows[i].current_service_time == 0) {
windows[i].total_customers++;
windows[i].total_service_time[windows[i].current_service_type] += customers[i].service_time;
windows[i].current_service_type = -1;
}
} else {
int earliest_customer_index = -1;
for (int j = 0; j < total_customers; j++) {
if (customers[j].arrive_time <= current_time) {
if (earliest_customer_index == -1 || customers[j].arrive_time < customers[earliest_customer_index].arrive_time) {
earliest_customer_index = j;
}
}
}
if (earliest_customer_index != -1) {
for (int j = 0; j < 4; j++) {
if (windows[j].current_service_time == 0) {
windows[j].current_service_time = customers[earliest_customer_index].service_time;
windows[j].current_service_type = customers[earliest_customer_index].service_type;
customers[earliest_customer_index] = customers[total_customers - 1];
total_customers--;
break;
}
}
}
}
}
current_time++;
}
// 输出模拟结果
int total_service_time[4] = {0};
int total_customers_served = 0;
int total_time_spent = 0;
printf("窗口\t服务类型\t客户数\t服务时间\n");
for (int i = 0; i < 4; i++) {
printf("%d\t存款\t\t%d\t%d\n", i + 1, windows[i].total_customers, windows[i].total_service_time[0]);
printf("\t取款\t\t%d\t%d\n", windows[i].total_customers, windows[i].total_service_time[1]);
printf("\t挂失\t\t%d\t%d\n", windows[i].total_customers, windows[i].total_service_time[2]);
printf("\t还贷\t\t%d\t%d\n", windows[i].total_customers, windows[i].total_service_time[3]);
total_customers_served += windows[i].total_customers;
total_time_spent += windows[i].total_service_time[0] + windows[i].total_service_time[1] + windows[i].total_service_time[2] + windows[i].total_service_time[3];
total_service_time[0] += windows[i].total_service_time[0];
total_service_time[1] += windows[i].total_service_time[1];
total_service_time[2] += windows[i].total_service_time[2];
total_service_time[3] += windows[i].total_service_time[3];
}
printf("总客户数:%d\n", total_customers);
printf("平均逗留时间:%d\n", total_time_spent / total_customers_served);
printf("服务类型\t客户数\t服务时间\n");
printf("存款\t\t%d\t%d\n", total_customers_served, total_service_time[0]);
printf("取款\t\t%d\t%d\n", total_customers_served, total_service_time[1]);
printf("挂失\t\t%d\t%d\n", total_customers_served, total_service_time[2]);
printf("还贷\t\t%d\t%d\n", total_customers_served, total_service_time[3]);
return 0;
}
```
这只是一个简单的示例代码,可能还有些需要完善的地方。希望能对您有所帮助!
阅读全文