如何用C语言实现银行数据结构模拟系统?
- 内容介绍
- 文章标签
- 相关推荐
本文共计725个文字,预计阅读时间需要3分钟。
C语言实现银行模拟系统+实现代码:以下是一个简化的C语言实现的银行模拟系统代码示例。
c#include #include
#define MAX_CUSTOMERS 100
typedef struct { int account_number; char name[50]; float balance;} Customer;
Customer bank[MAX_CUSTOMERS];int customer_count=0;
void add_customer(int account, const char *name, float initial_balance) { if (customer_count void deposit(int account, float amount) { for (int i=0; i void withdraw(int account, float amount) { for (int i=0; i =amount) { bank[i].balance -=amount; printf(Withdrew %.2f from account %d.\n, amount, account); return; } else { printf(Insufficient funds in account %d.\n, account); return; } } } printf(Account %d not found.\n, account);} void display_balance(int account) { for (int i=0; i int main() { // 示例:添加几个客户 add_customer(1001, Alice, 1000.0); add_customer(1002, Bob, 500.0); // 示例:存款 deposit(1001, 200.0); // 示例:取款 withdraw(1002, 100.0); // 示例:显示余额 display_balance(1001); display_balance(1002); return 0;} 这段代码定义了一个简单的银行模拟系统,包括添加客户、存款、取款和显示余额的功能。注意,这里没有实现持久化存储,即程序结束后客户信息会丢失。此外,代码中没有错误处理机制,实际应用中需要添加更多的健壮性检查。 C语言数据结构实现银行模拟 实现代码:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define MAX_WIN 20
#define MAX_STAY 100
typedef struct customer *link;
struct customer
{
int stay;
link next;
};
link GUY(int stay, link next)
{
link c = malloc(sizeof *c);
c->stay = stay;
c->next = next;
return c;
}
link win[MAX_WIN];
void morning()
{
int i;
for(i = 0; i < MAX_WIN; i++)
{
win[i] = NULL;
}
}
void come(int w, int stay)
{
if(win[w] == NULL)
{
win[w] = GUY(stay, NULL);
win[w]->next = win[w];
}
else
win[w] = win[w]->next = GUY(stay, win[w]->next);
}
void leave(int w)
{
if(win[w]->next == win[w])
{
free(win[w]);
win[w] = NULL;
}
else
{
link t = win[w]->next;
win[w]->next = t->next;
free(t);
}
}
void guys()
{
int i;
link t;
system("clear");
for(i = 0; i < MAX_WIN; i++, puts(" "))
{
printf("WIN%3d:_", i);
if((t = win[i]) == NULL)
continue;
for(; t->next != win[i]; t = t->next)
{
printf("%4d", t->next->stay);
}
}
Sleep(1);
}
void later()
{
int i;
for(guys(), i = 0; i < MAX_WIN; i++)
{
if(win[i] == NULL)
continue;
if(win[i]->next->stay > 0)
(win[i]->next->stay)--;
else
leave(i);
}
}
int main()
{
srand(time(NULL));
for(morning; ;later())
{
come(rand()%MAX_WIN, rand()%MAX_STAY+1);
}
return 0;
}
由于这里是生成的随机数,所以程序会一直在变化。按住ctrl +c 终止程序 以上就是C语言数据结构实现银行模拟的实例详解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
本文共计725个文字,预计阅读时间需要3分钟。
C语言实现银行模拟系统+实现代码:以下是一个简化的C语言实现的银行模拟系统代码示例。
c#include #include
#define MAX_CUSTOMERS 100
typedef struct { int account_number; char name[50]; float balance;} Customer;
Customer bank[MAX_CUSTOMERS];int customer_count=0;
void add_customer(int account, const char *name, float initial_balance) { if (customer_count void deposit(int account, float amount) { for (int i=0; i void withdraw(int account, float amount) { for (int i=0; i =amount) { bank[i].balance -=amount; printf(Withdrew %.2f from account %d.\n, amount, account); return; } else { printf(Insufficient funds in account %d.\n, account); return; } } } printf(Account %d not found.\n, account);} void display_balance(int account) { for (int i=0; i int main() { // 示例:添加几个客户 add_customer(1001, Alice, 1000.0); add_customer(1002, Bob, 500.0); // 示例:存款 deposit(1001, 200.0); // 示例:取款 withdraw(1002, 100.0); // 示例:显示余额 display_balance(1001); display_balance(1002); return 0;} 这段代码定义了一个简单的银行模拟系统,包括添加客户、存款、取款和显示余额的功能。注意,这里没有实现持久化存储,即程序结束后客户信息会丢失。此外,代码中没有错误处理机制,实际应用中需要添加更多的健壮性检查。 C语言数据结构实现银行模拟 实现代码:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define MAX_WIN 20
#define MAX_STAY 100
typedef struct customer *link;
struct customer
{
int stay;
link next;
};
link GUY(int stay, link next)
{
link c = malloc(sizeof *c);
c->stay = stay;
c->next = next;
return c;
}
link win[MAX_WIN];
void morning()
{
int i;
for(i = 0; i < MAX_WIN; i++)
{
win[i] = NULL;
}
}
void come(int w, int stay)
{
if(win[w] == NULL)
{
win[w] = GUY(stay, NULL);
win[w]->next = win[w];
}
else
win[w] = win[w]->next = GUY(stay, win[w]->next);
}
void leave(int w)
{
if(win[w]->next == win[w])
{
free(win[w]);
win[w] = NULL;
}
else
{
link t = win[w]->next;
win[w]->next = t->next;
free(t);
}
}
void guys()
{
int i;
link t;
system("clear");
for(i = 0; i < MAX_WIN; i++, puts(" "))
{
printf("WIN%3d:_", i);
if((t = win[i]) == NULL)
continue;
for(; t->next != win[i]; t = t->next)
{
printf("%4d", t->next->stay);
}
}
Sleep(1);
}
void later()
{
int i;
for(guys(), i = 0; i < MAX_WIN; i++)
{
if(win[i] == NULL)
continue;
if(win[i]->next->stay > 0)
(win[i]->next->stay)--;
else
leave(i);
}
}
int main()
{
srand(time(NULL));
for(morning; ;later())
{
come(rand()%MAX_WIN, rand()%MAX_STAY+1);
}
return 0;
}
由于这里是生成的随机数,所以程序会一直在变化。按住ctrl +c 终止程序 以上就是C语言数据结构实现银行模拟的实例详解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

