1. 程式人生 > 實用技巧 >Celery Worker log 中記錄 task_id

Celery Worker log 中記錄 task_id

一、作業資訊

這個作業屬於哪個課程https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/
這個作業要求在哪裡 https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/homework/11478
這個作業的目標 編寫一個ATM管理系統
學號 3180701237

二、題目要求

編寫一個ATM管理系統,語言不限,要求應包括以下主要功能:
(1)開戶,銷戶
(2)查詢賬戶餘額
(3)存款
(4)取款
(5)轉賬(一個賬戶轉到另一個賬戶)等...

三、程式碼提

開戶

void oaa(struct per *head)
{
	head=NULL;
	FILE *fp;   //定義檔案指標
	struct per *p1=NULL,*p2=NULL;   //p1,p2為定義連結串列指標
	p1=(struct per*)malloc(sizeof(struct per));  
	      printf("請輸入您的姓名:\n");  
		  scanf("%s",p1->name);
		  printf("請輸入您的卡號:\n");
		  scanf("%s",p1->ID);
		  printf("請設定您銀行卡密碼:\n");
		  scanf("%s",p1->code);
		  p1->money=0;
		  p1->next=NULL;
		  printf("您的個人資訊為");
		     printf("姓名:%s \n卡號:%s \n餘額:%4d\n",p1->name,p1->ID,p1->money);
          if(NULL==head)           
		  {
			  head=(struct per *)malloc(sizeof(struct per));
			  head->next=p1;    //頭插法
		  }
		  else    //為新增客戶開闢記憶體單元
		  {
			  for(p2=head;p2->next!=NULL;p2=p2->next); //尾插法
			  p2->next=p1;
		  }
		  if((fp=fopen("save.txt","ab+"))==NULL)
		  {
			  printf("cannot poen file\n");
			  return;
		  }
		  if(fwrite(p1,sizeof(struct per),1,fp)!=1)  //將連結串列資訊寫入檔案中
			  printf("file write error\n");
		      fclose(fp);
			  printf("\n");
			  printf("恭喜您開戶成功,請登入\n");
			  system("pause");
			  system("cls");
			  login(head);
}

登入

void login(struct per *head)
{
	char d[20];
	char code[20];
	int i,j;
	FILE *fp;     
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)   //開啟一個二進位制檔案,為讀方式
	{
		printf("不能開啟檔案\n");   
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))       
 
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;   //如果沒讀到資料,跳出迴圈
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p; 
		p=p->next; 
		
	}
	q->next=NULL;  //最後一個結點的後繼指標為空
	fclose(fp);
	printf("  **********************\n");
	printf("  ***歡迎來到建設銀行***\n");
	printf("  **********************\n");
	for(j=1;j<4;j++)      //限制卡號輸入的次數的迴圈
	{
		printf("請輸入您的卡號\n");
		scanf("%s",d);
		for(q=head;q!=NULL;q=q->next)   
		{
			if(strcmp(q->ID,d)!=0)  
			{
			continue;  
			}
					else
		{
			for(i=1;i<4;i++)   
			{
				printf("\n\n請輸入您的密碼\n");
				scanf("%s",code);
				if(strcmp(q->code,code)!=0)      //核對密碼
				{
					printf("密碼不正確。請重新輸入密碼\n");
					system("pause");
					system("cls");
					continue;    //若密碼不對,跳出迴圈
				}
				else
				{
					system("cls");
					menu(head);  
				}
			}
			printf("\n\n\n您輸入密碼三次錯誤\n");
			system("pause");
			system("cls");
			exit(0);
		}
	}
		
	
	printf("\n\n\n您輸入的卡號有誤,請重試\n");
	system("pause");
	system("cls");
}
printf("您的卡號三次輸入錯誤,謝謝使用\n");
exit(0);
}
 

選單

void menu(struct per *head)
{
	head=NULL;
	int i;      //i為客戶選擇輸入的變數
	while(1)
	{
		printf("請選擇您需要辦理的業務\n");     
		printf("*********************************\n");
		printf("**  1 取款   *****   2 查詢    **\n");
		printf("*********************************\n");
		printf("**  3 轉賬   *****   4 修改密碼**\n");
		printf("*********************************\n");
		printf("**  5 存款   *****   6 退出    **\n");
		printf("*********************************\n");
		scanf("%d",&i);
		if(i<6||i>0)
		{
			switch(i)
			{
			case 1:withdrawal(head);       
			       system("pause");
				   system("cls");
				   break;
			case 2:system("cls");
				   query(head);  
				   break;
            case 3:system("cls");
				   taccount(head);  
				   break;
            case 4:system("cls");
				   cpassword(head);  
				   break;
            case 5:system("cls");
				   deposit(head);  
				   break;
            case 6:system("cls");
				   tuichu();  
				   break;
			}
		}
		else
		{
			printf("您的輸入有誤\n");
			system("pause");
			system("cls");
		}
	}
}

存款

void deposit(struct per *head)
{
	int i;
	head=NULL;   
	FILE *fp;  
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  //開啟一個二進位制檔案,為讀方式
	{
		printf("不能開啟檔案\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))   
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;   
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;   
		p=p->next;   
	}
	q->next=NULL;   
	fclose(fp);
	system("cls");
	printf("您卡上餘額%d元\n",q->money);   
	printf("************************************\n");
    printf("**  1: 100元    *****    2:200元  **\n");
	printf("************************************\n");
    printf("**  3: 300元    *****    4:400元  **\n");
	printf("************************************\n");
    printf("**  5: 500元    *****    6:600元  **\n");
	printf("************************************\n");
    printf("請選擇您要存入的金額\n");
	scanf("%d",&i);
	if(i>6||i<=0)
	{
		printf("對不起,您的輸入有誤\n\n");
		return;
	}
	else
	{
		i=100*i;
		q->money+=i;
		if((fp=fopen("save.txt","wb+"))==NULL)  
		{
			printf("cannot open file\n");
		}
		if(fwrite(q,sizeof(struct per),1,fp)!=1)  //將修改的密碼重新寫入檔案
			printf("file write error\n");
	    	printf("您已經成功存取%d元\n",i);
			q->next=NULL;
			fclose(fp);
			system("pause");
			system("cls");
	}
}

取款

void withdrawal(struct per *head)
{
	head=NULL;   
	int i;
	FILE *fp;         
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL) //開啟一個二進位制檔案,為讀方式
	{
		printf("不能開啟檔案\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));  
	head=p;
	while(!feof(fp))   
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;  
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;  
		p=p->next; 
	}
	q->next=NULL; 
	fclose(fp);
	system("cls");
	printf("************************************\n");
    printf("**  1: 100元    *****    2:200元  **\n");
	printf("************************************\n");
    printf("**  3: 300元    *****    4:400元  **\n");
	printf("************************************\n");
    printf("**  5: 500元    *****    6:600元  **\n");
	printf("************************************\n");
    printf("請按要求選擇您要取款的金額\n");
	scanf("%d",&i);
	if(i>6||i<=0)    //限制輸入範圍
	{
		printf("對不起,您的輸入有誤\n\n");
		return;
	}
	else
	{
		i=100*i;  //對應選項乘以一百為取款金額
		if(i>q->money)
		{
			printf("對不起,您的金額不足\n");
			system("pause");
			system("cls");
			menu(head);  
		}
		else
		{
			q->money-=i;  //對金額進行處理
			if((fp=fopen("save.txt","wb+"))==NULL)  
			{
				printf("cannot open file\n");
				return;
			}
			if(fwrite(q,sizeof(struct per),1,fp)!=1) //將修改的資訊重新寫入檔案
				printf("file write error\n");
			printf("您已經成功取走%d元\n");
			q->next=NULL;
			fclose(fp);   
		}
		
	}
}

轉賬

void taccount(struct per *head)
{
	head=NULL;
	FILE *fp;  
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  
	{
		printf("不能開啟檔案\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));  
	head=p;
	while(!feof(fp))    
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;   
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;   
		p=p->next;   
	}
	q->next=NULL;  
	fclose(fp);
	int i,j,k;
	printf("請輸入帳號號碼\n");
	scanf("%d",&i);
	printf("請再次輸入帳號號碼\n");   //核對卡號
	scanf("%d",&j);
	if(i!=j)
	{
		printf("兩次賬號不同,請重新輸入\n");
		taccount(head);
	}
	else
	{
		system("cls");
	printf("************************************\n");
    printf("**  1: 100元    *****    2:200元  **\n");
	printf("************************************\n");
    printf("**  3: 300元    *****    4:400元  **\n");
	printf("************************************\n");
    printf("**  5: 500元    *****    6:600元  **\n");
	printf("************************************\n");
    printf("請輸入轉賬金額\n");
	scanf("%d",&k);
	if(k>6||k<=0)
	{
		printf("對不起,您的輸入有誤\n\n");
		return;
	}
	else
	{
		k=k*100;
		if(k>q->money)    //對餘額進行判斷
		{
			printf("對不起,您的餘額不足\n");
			system("pause");
			system("cls");
			menu(head);
		}
		else
		{
			printf("您已成功轉賬%d元\n",k);
			q->money-=k;
			if((fp=fopen("save.txt","wb+"))==NULL)
			{
				printf("cannot open file\n");
				return;
			}
			if(fwrite(q,sizeof(per),1,fp)!=1)  //將資料重新寫入檔案
				printf("file write error\n");
			q->next=NULL;
			fclose(fp);
			system("pause");
			system("cls");
		}
	}
	}
}

查詢

void query(struct per *head)
{
	head=NULL;  
	FILE *fp;  
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  
	{
		printf("不能開啟檔案\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))   
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;    
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;   
		p=p->next;   
	}
	q->next=NULL;  
	fclose(fp);
	printf("您卡上餘額%d元\n\n",q->money);
	system("pause");
	system("cls");
}
 

修改密碼

void cpassword(struct per *head)
{
	head=NULL;         
	char code[20];
	FILE *fp; 
	struct per *p,*q=NULL;
	if((fp=fopen("save.txt","rb+"))==NULL)  //開啟一個二進位制檔案,為讀方式
	{
		printf("不能開啟檔案\n");  
	}
	p=(struct per*)malloc(sizeof(struct per));   
	head=p;
	while(!feof(fp))    
	{
		if(1!=fread(p,sizeof(struct per),1,fp))
			break;    
		p->next=(struct per *)malloc(sizeof(struct per));  
		q=p;  
		p=p->next;  
	}
	q->next=NULL;  
	fclose(fp);
	printf("請輸入您的原密碼\n");
	scanf("%s",code);
	if(strcmp(q->code,code)==0)   //核對密碼
	{
		{
			printf("密碼正確\n");
			printf("請輸入您的新密碼:\n");
			scanf("%s",q->code);
			if((fp=fopen("save.txt","wb+"))==NULL)  
			{
				printf("cannot open file\n");
			}
			if(fwrite(q,sizeof(struct per),1,fp)!=1)    
				printf("file write error\n");
			fclose(fp);
			printf("修改密碼成功\n\n\n\n\n");
		}
	}
	else
	{
		printf("您輸入的密碼與原密碼不同\n");
		return;
		system("pause");
	}
	q->next=NULL;
}

銷戶

void close(struct person **Phead)   
{
	char k[20];   
	struct person *p=*Phead,*t;
	if(NULL==(*Phead))    
	{
		printf("沒有客戶資訊可刪除!\n");
		return;
	}
	printf("請輸入要刪除的客戶卡號:\n");
	scanf("%s",k);
	if(p->client.ID==k) 
		*Phead=(*Phead)->next,free(p);
	else
	{
		while(NULL==p->next&&p->next->client.ID!=k)   
			p=p->next;  
		if(p->next==NULL)
			printf("對不起,沒有該客戶!\n");
		else
		{
			t=p->next;  
			p->next=p->next->next;
		}
	}
}

主函式

 
int main()
{
	char x;
	char choose; //choose為定義輸入選擇的變數
	int flag=1;
	struct person *Phead=NULL; 
	struct per *head=NULL;   
	printf("**歡迎使用ATM自動取款機系統**\n");
    printf("——————————————\n");
	printf("|   1  開戶                 |\n");
    printf("——————————————\n");
	printf("|   2  登陸                 |\n");
    printf("——————————————\n");
	printf("|   3  前臺客戶資訊查詢中心 |\n");
    printf("——————————————\n");
	printf("|   請選擇您的需求         |\n");
    printf("———————————————\n");
	scanf("%s",&x);
	system("cls");
 
	switch(x)
	{
	case '1':system("cls");
	         oaa(head);   //呼叫開戶函式
			 break;
 
	case '2':system("cls");
	         login(head);   //呼叫登陸函式
			 break;
 
	case '3':system("cls");
	         menu();   //呼叫後臺選單函式
			 break;
	}
	while(flag)
	{
		system("cls");
		menu();       //呼叫後臺選單函式
		choose=getchar();
		switch(choose)
		{
		case '1':setup(&Phead);
			     output(Phead); //呼叫後臺輸出函式
				 system("pause");
				 system("cls");
				 break;
    	case '2':query1(Phead); //呼叫後臺卡號查詢函式
				 system("pause");
				 system("cls");
				 break;
    	case '3':query2(Phead); //呼叫後臺姓名查詢函式
				 system("pause");
				 system("cls");
				 break;
    	case '4':
			     query3(Phead); //呼叫後臺餘額查詢函式
				 system("pause");
				 system("cls");
				 break;
    	case '5':close(&Phead); //呼叫後臺刪除使用者函式
				 system("pause");
				 system("cls");
				 break;
	    case '6':
			     add(&Phead); //呼叫後臺增加使用者函式
				 system("pause");
				 system("cls");
				 break;
	    case '7':output(Phead); //呼叫後臺輸出函式函式
				 system("pause");
				 system("cls");
				 break;
	    case '8':output(Phead); 
				 system("pause");
				 system("cls");
				 break;
    	case '0':flag=0;
			     printf("The end.\n");
				 break;
		}
	}
}
四、執行截圖

五、個人小結
1.psp
psp2.1任務內容計劃完成需要的時間(min)實際完成需要的時間(min)
Planning 計劃 30 60
Estimate 估計這個任務需要多少時間,並規劃大致工作步驟 6 6
Development 開發 120 120
Analysis 需求分析(包括學習新技術) 10 10
Design Spec 生成設計文件 20 20
Design Review 設計複審 5 10
Coding Standard 程式碼規範 5 8
Design 具體設計 15 22
Coding 具體編碼 40 35
Code Review 程式碼複審 5 4
Test 測試(自我測試,修改程式碼,提交修改) 20 15
Reporting 報告 10 10
Test Report 測試報告 2 3
Size Measurement 計算工作量 3 3
Postmortem & Process improvement Plan 事後總結,並提出過程改進計劃 4 4
2.作業心得
通過這次學習,我對c語言程式設計有了更深刻的理解。