資源簡介
C語言寫的銀行業務模擬代碼,使用隊列,動態存儲結構。
代碼片段和文件信息
#include??
#include??
#include
#include
#include?
#define?OK??1????//離開事件
#define?ERROR??0
#define?OVERFLOW?2
//全局變量:
int?total_money;//銀行現存資金總額
int?total_time=0;?//客戶逗留總時間
float?use_time;//每個顧客平均所用時間
int?money;//每個顧客辦理的款數
int?close_time;//銀行營業時問
int?space_time;//下一用戶到達的時間間隔
int?spend_time;//辦理業務所需時間
int?event_Type;//事件類型
int?number=1;//辦理業務的次序
SYSTEMTIME?sys;//獲取時間的變量
struct?Line1//隊列1元素(表示前來辦理業務的客戶)
{
int?arrive_time;//到達時間
int?event_Type;//事件類型,0表示存款,1表示取款。
int?spend_time;//辦理業務時間
int?money;//交易金額
}come;
struct?Line2//隊列2元素?(表示取款不能被滿足,等待隊列里的客戶)
{
????int?arrive_time;//到達時間
????int?spend_time;//辦理業務時間
????int?money;//交易金額
}wait;
struct?Node1//使隊列1的個體成為鏈塊結構
{
struct?Line1?data;//存儲元素個體信息
struct?Node1?*next;
}Node1;
struct?Node2//使隊列2的個體成為鏈塊結構
{
struct?Line2?data;
struct?Node2?*next;
}Node2;
struct?Point1//用于連接隊列1
{
struct?Node1?*front;//隊頭
struct?Node1?*rear;//隊尾
}link1;
struct?Point2//用于連接隊列2
{
struct?Node2?*front;//隊頭
struct?Node2?*rear;//隊尾
}link2;
void?time_now()?//獲取當前系統時間
{?
GetLocalTime(&sys);?
}
void?print_time()//打印系統時間
{
if(sys.wDayOfWeek==0)
{
sys.wDayOfWeek=7;
}
printf(“\n\n\n\n\n\n\n\n\n\n\n\n“);
printf(“\n\n▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃“);
printf(“\n\n◆◆◆◆◆◆◆◆◆◆◆◆【?%4d/%02d/%02d?%02d:%02d:%02d?星期%1d?】◆◆◆◆◆◆◆◆◆◆◆◆“sys.wYearsys.wMonthsys.wDaysys.wHoursys.wMinutesys.wSecondsys.wDayOfWeek);
printf(“\n\n▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃▃“);
printf(“\n\n\n\n\n\n\n\n\n“);
printf(“按任意鍵開始模擬...“);
getch();
}
void?srandd()
{
srand(time(NULL));
}
void?at_random()//產生隨機數
{
money=rand()%10000+100;//設置客戶要辦理的款額為50~100050元
space_time=rand()%5;?//設置下一個客戶到達的時間為0~5分鐘
spend_time=rand()%25+5;//設置辦理業務所需時間為5~30分鐘
event_Type=rand()%2;//設置辦理業務為取或存中隨機一種
}
int?InitLine1()//初始化?申請空間
{
link1.front=link1.rear=(struct?Node1*)malloc(sizeof(struct?Node1));
????if(!link1.front)?exit(OVERFLOW);
????link1.front->next=NULL;
????return?OK;
}
int?InitLine2()
{
link2.front=link2.rear=(struct?Node2*)malloc(sizeof(struct?Node2));
????if(!link2.front)?exit(OVERFLOW);
????link2.front->next=NULL;
????return?OK;
}
int?destoryLine1()//釋放空間
{
while(link1.front)
????{?
link1.rear=link1.front->next;
free(link1.front);
link1.front=link1.rear=NULL;//把不用的指針指向NULL
}
return?OK;
}
int?destoryLine2()
{
while(link2.front)
????{?
link2.rear=link2.front->next;
free(link2.front);
link2.front=link2.rear=NULL;
}
return?OK;
}
int?flag1=0;
void?comingLine1()
{
struct?Node1?*new_come;//用于模擬新進入銀行的客戶
new_come=(struct?Node1*)malloc(sizeof(struct?Node1));
if(!new_come)?exit(OVERFLOW);
at_random();//調用隨機數函數,產生所需隨機數
new_come->data.arrive_time=total_time;//將產生的隨機數傳給新到客戶
total_time?+=?space_time;//該客戶到達時間即為當前銀行已運營時間
new_come->data.event_Type=event_Type;
new_come->data.spend_time=spend_time;
if(event_Type==1)
{
new_come->data.money=money-(2
- 上一篇:簡單文件管理系統的實現
- 下一篇:kdtree的源碼C語言版
評論
共有 條評論