1. 程式人生 > 實用技巧 >GitLab API使用小結

GitLab API使用小結

一.作業資訊

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

二.題目要求

編寫一個ATM管理系統,語言不限,要求應包括以下主要功能:

(1)開戶,銷戶

(2)查詢賬戶餘額

(3)存款

(4)取款

(5)轉賬(一個賬戶轉到另一個賬戶)等...

三.程式碼

#include<stdlib.h>
#include<string.h>
#pragma warning(disable:4996)/*將4966警報置為失效*/
#define CNUM 100
struct Customer/*賬戶的結構體*/
{
	char account[16];/*使用者賬號*/
	char name[9];/*使用者姓名*/
	char password[7];/*賬戶密碼*/
	char IDnumber[19];/*使用者身份證號*/
	float yue;/*賬戶餘額*/
};
typedef struct 
{
	char account[16];/*交易的賬號*/
	char Ttime[50];/*交易時間*/
	char type[5];/*交易型別*/
	float Tmoney;/*交易金額*/
	float Tyue;/*交易後的餘額*/
} Transaction;/*交易記錄的結構體*/
Transaction T[1000];/*定義交易記錄的結構體陣列,可以儲存1000條交易記錄*/
struct Customer C[100];/*定義賬戶的結構體陣列,可以註冊100個賬戶*/
int Cnum = 0;/*賬戶序號*/
int Tnum = 0; /*交易序號*/
int Dxiabiao = 0;/*當前登入的賬戶下標*/
 
int menu();        /*宣告主選單函式*/
void help();     /*宣告幫助函式*/
void zhuce();      /*宣告註冊函式*/
void denglu();     /*宣告登入函式*/
void load();  /*宣告裝載資料函式*/
void save();     /*宣告儲存資料函式*/
int denglu_menu(); /*宣告登入選單函式*/
void credit();    /*宣告存款函式*/
void debit();     /*宣告取款函式*/
void quary();     /*宣告查詢函式*/
void print();   /*宣告列印函式*/
void updatepassword(); /*宣告修改密碼函式*/
int quary_menu();      /*宣告查詢選單函式*/
void quary_yue();      /*宣告查詢餘額函式*/
void quary_mingxi();   /*宣告查詢明細函式*/
void quary_credit();  /*宣告查詢存款函式*/
void quary_debit();   /*宣告查詢取款函式*/

主函式

{
	system("color 3F");/*設定背景顏色為藍色*/
	printf("\n\t****************************************************\n");
	printf("\n\t*****               歡迎使用ATM終端機!         *****\n");
	printf("\n\t****************************************************\n");
	system("pause");/*暫停功能*/
	system("cls");/*清屏*/
	for (;;)/*空迴圈語句*/
	{
		switch (menu()) /*主選單選擇判斷*/
		{
		case 1:zhuce(); break;/*呼叫註冊函式*/
		case 2:denglu(); break;/*呼叫登入函式*/
		case 3:load(); break;/*呼叫載入資料的函式*/
		case 4:save(); break;/*呼叫儲存資料的函式*/
		case 5:help(); break;/*呼叫幫助函式*/
		case 0:printf("\t\t歡迎使用ATM終端機管理系統。謝謝!\n"); 
			system("pause");
			exit(0);/*結束程式*/
		}
	}
}

定義主選單函式

{
	char c;
	do
	{
		system("cls"); /*每次選擇執行前清屏*/
		printf("\n\n\n\t\t**************************\n");
		printf("\t\t**          主選單      **\n"); /*主選單選擇*/
		printf("\t\t**************************\n");
		printf("\t\t--------------------------\n");
		printf("\t\t**        1. 註冊       **\n");
		printf("\t\t**        2. 登入       **\n");
		printf("\t\t**        3. 載入資料   **\n");
		printf("\t\t**        4. 儲存資料   **\n");
		printf("\t\t**        5. 系統幫助   **\n");
		printf("\t\t**        0. 退出       **\n");
		printf("\t\t--------------------------\n");
		printf("\t\t**************************\n");
		printf("\t\t請作出選擇(0-5):");
		c = getchar(); /*讀入選擇*/
	} while (c<'0' || c>'5');
	return(c - '0'); /*c變為空後返回重新選擇*/
}

定義幫助函式

void help()
{
	system("cls");
	printf("\n\t\t******************************\n");
	printf("\n\t\t*   歡迎使用ATM機幫助功能    *\n");
	printf("\n\t\t* 1.如有記錄,先用載入功能   *\n");
	printf("\n\t\t* 2.註冊記得要儲存資料       *\n");
	printf("\n\t\t* 3.登入後可選擇功能存款、取 *\n");
	printf("\n\t\t*   款列印票據或查詢         *\n");
	printf("\n\t\t* 4.登入後可查詢賬戶餘額     *\n");
	printf("\n\t\t* 注:一切操作切勿忘記儲存   *\n");
	printf("\n\t\t******************************\n");
	system("pause");
}

定義註冊函式

{
	int baiwei, shiwei, gewei, len;/*定義賬號的後三位*/
	char password2[7];/*註冊時第二次輸入的密碼*/
	int  j = 0;
	strcpy(C[Cnum].account, "123456543210");/*複製賬號的前12位*/
	baiwei = Cnum / 100;
	shiwei = Cnum / 10 % 10;
	gewei = Cnum % 10;
	C[Cnum].account[12] = baiwei + '0';
	C[Cnum].account[13] = shiwei + '0';
	C[Cnum].account[14] = gewei + '0';
	C[Cnum].account[15] = '\0';
	system("cls");/*執行前清屏*/
	printf("\n\n\n\t\t註冊————ZHUCE\n\n\n");
	printf("\t\t請輸入姓名:");
	scanf("%s", C[Cnum].name);
	do
	{
		printf("\t\t請輸入6位數密碼:");
		scanf("%s", C[Cnum].password);
		len = strlen(C[Cnum].password);
		if (len != 6)/*判斷密碼是否為6位*/
		{
			printf("\t\t您的密碼不是6位數!\n");
			system("pause");
			return;
		}
		//此處用字串長度函式來判斷密碼的位數
		printf("\t\t請再次輸入密碼:");
		scanf("%s", password2);
		if (strcmp(C[Cnum].password, password2) != 0)/*判斷兩次密碼輸入是否相同*/
		{
			j++;
			printf("\n\t\t您的密碼輸入錯誤!您還有%d次機會輸入密碼!\n", 3 - j);
		}
		if (j == 3)/*密碼輸入錯誤不得超過三次*/
		{
			system("pause");
			return;
		}
	} while (strcmp(C[Cnum].password, password2) != 0);
	do
	{
		printf("\t\t請輸入身份證號:");
		scanf("%s", C[Cnum].IDnumber);
		len = strlen(C[Cnum].IDnumber);
		if (len != 18 && len != 15)/*判斷身份證號位數是否為15位或18 位*/
			printf("\t\t身份證號錯誤!請輸入15位或18位身份證號!\n");
	} while (len != 18 && len != 15);
	printf("\n\t\t請輸入存入金額:");
	scanf("%f", &C[Cnum].yue);
	if ((int)C[Cnum].yue % 50 != 0)/*存款金額必須為50的整數倍*/
	{
		printf("\t\t本機只接受50元或100元面值的存款!\n");
		system("pause");
		return;
	}
	strcpy(T[Tnum].account, C[Cnum].account);/**/
	strcpy(T[Tnum].type, "儲存");/*複製交易型別*/
	T[Tnum].Tmoney = C[Cnum].yue;/*第一次交易的賬戶餘額值賦給交易經額的值*/
	T[Tnum].Tyue = C[Dxiabiao].yue;/*第一次交易的賬戶餘額值賦給交易餘額的值*/
	printf("\n\t\t開戶成功!\n");
	system("pause");/*暫停功能*/
	printf("\n\n賬號  \t\t交易型別\t交易金額\t餘額\n");/*輸出賬戶第一次交易的資料清單*/
	printf("%s", C[Cnum].account);
	printf("  %s", T[Tnum].type);
	printf("\t\t%.2f", C[Cnum].yue);
	printf("   \t%.2f", C[Cnum].yue);
	printf("\n");
	Cnum++;/*賬戶序號加一*/
	Tnum++;/*交易序號加一*/
	Dxiabiao++;
	system("pause");/*暫停*/
}

定義登入函式

 { 
	char account[16], password[7];/*登入時輸入的賬號和密碼*/
	int i = 0, j = 0;
	system("cls");/*清屏*/
	printf("\n\n\n\t\t登入————DENGLU\n\n\n");/*進入登入得功能介面*/
	printf("\t\t輸入賬號:");
	scanf("%s", account);/*輸入賬號*/
	for (i = 0; i<Cnum; i++)/*在已註冊的賬號中依次尋找該賬號*/
		if (strcmp(account, C[i].account) == 0)
		{
			Dxiabiao = i;/*若找到,則跳出迴圈*/
			break;
		}
	if (i == Cnum)/*註冊的賬號中沒輸入的賬號*/
	{
		printf("\n\t\t當前賬號不存在!\n");
		system("pause");
		return;
	}
	do
	{
		printf("\n\t\t輸入密碼:");
		scanf("%s", password);
		if (strcmp(password, C[i].password) != 0)
		{
			j++;
			printf("\t\t您的密碼輸入錯誤!您還有%d次機會輸入密碼!\n\n", 3 - j);
		}
		if (j == 3)/*密碼輸入錯誤不得超過三次*/
		{
			printf("\n\t\t此卡已被鎖定,請到工作人員處解鎖。\n");
			system("pause");
			return;
		}		
	} while (strcmp(password, C[i].password) != 0);
	for (;;)/*空迴圈語句*/
	{
		switch (denglu_menu()) /***登陸介面選擇判斷***/
		{
		case 1:credit();break;/*呼叫存款函式*/			
		case 2:debit();break;/*呼叫取款函式*/		
		case 3:quary();break;/*呼叫查詢函式*/		
		case 4:updatepassword();break;/*呼叫修改密碼函式*/
		case 5:print(); break;  /*呼叫列印函式*/
		case 0:return;/*返回上一級選單介面*/	
		}
	}
}

定義載入資料函式

{
	FILE *fp;/*定義檔案指標*/
	int i;
	char Fname[20];/*定義輸入的檔名*/
	printf("\t\t請輸入開啟的檔名(檔名.txt):");
	scanf("%s", Fname);/*輸入要讀入資料的檔名*/
	if ((fp = fopen(Fname, "r")) == NULL)/*找不到輸入的檔名*/
	{
		printf("\t\t無法開啟該檔案!");
		system("pause");
		return;
	}
	fscanf(fp, "%d\n", &Cnum);
	fscanf(fp, "賬號  \t\t姓名\t密碼\t身份證號  \t\t餘額\n");
	for (i = 0; i<Cnum; i++)/*依次從檔案讀入註冊賬戶的資訊*/
	{
		fscanf(fp, "%16s %9s %7s %19s %12f", 
			C[i].account,	C[i].name, C[i].password,C[i].IDnumber, &C[i].yue);
		fscanf(fp, "\n");
	}
	fscanf(fp, "%d\n", &Tnum);
	fscanf(fp, "賬號  \t\t交易型別\t交易金額\t交易餘額\n");
	for (i = 0; i<Tnum; i++)/*依次從檔案讀入交易記錄的資訊*/
	{
		fscanf(fp, "%16s ", T[i].account);
		fscanf(fp, "%5s\t%12f\t%12f", 
			T[i].type,&T[i].Tmoney, &T[i].Tyue);
		fgets(T[i].account, 16, fp);
		fscanf(fp, "\n");
	}
	fclose(fp);/*關閉檔案*/
	printf("\t\t讀入成功!\n\n");
	system("pause");
}

定義儲存資料函式

void save()    
{
	FILE *fp;/*檔案指標*/
	int i;
	char Fname[13];
	printf("\t\t請輸入檔名(輸入格式為:檔名.txt):");
	scanf("%s", Fname);/*輸入要儲存的檔名*/
	if ((fp = fopen(Fname, "w")) == NULL)
	{
		printf("\n\t\t無法開啟檔案!\n");
		system("pause");
		return;
	}
	fprintf(fp, "%d\n", Cnum);
	fprintf(fp, "賬號  \t\t姓名\t密碼 \t身份證號  \t\t餘額\n");
	for (i = 0; i<Cnum; i++)/*把賬戶資訊依次輸出到指定檔案*/
		fprintf(fp, "%-16s%-9s%-7s%-19s%-12.2f\n", 
			C[i].account,C[i].name, C[i].password,C[i].IDnumber, C[i].yue);
	fprintf(fp, "%d\n", Tnum);
	fprintf(fp, "賬號  \t\t交易型別\t交易金額 \t\t交易餘額 \n");
	for (i = 0; i<Tnum; i++)/*把交易記錄的資訊依次輸出到指定檔案*/
		fprintf(fp, "%-16s  %-5s \t%-12.2f \t%-12.2f \n",
			T[i].account, T[i].type, T[i].Tmoney, T[i].Tyue);
	fclose(fp);/*關閉檔案*/
	printf("\n\t\t儲存成功!\n");
	system("pause");
}

定義登入選單函式

{
	char c;
	do
	{
		system("cls"); /*每次選擇執行前清屏*/
		printf("\n\n\n\t\t*********歡迎進入    登入介面!*********\n\n"); /*登入介面選單選擇*/
		printf("\t\t * 1. 存款 \n");
		printf("\t\t * 2. 取款 \n");
		printf("\t\t * 3. 查詢  \n");
		printf("\t\t * 4. 修改密碼  \n");
		printf("\t\t * 5. 列印票據  \n");
		printf("\t\t * 0. 返回 \n");
		printf("\t\t*****************************************\n");
		printf("\t\t請作出選擇(0-5):");
		c = getchar(); /*讀入選擇*/
	} while (c<'0' || c>'5');
	return(c - '0'); /*c變為空後返回重新選擇*/
}

定義列印函式

void print()
{
	FILE *file;
	int i;
	if ((file = fopen("票據.txt", "w")) == NULL)
	{
		printf("\t\t無法開啟該檔案!");
		system("pause");
		return;
	}
	fprintf(file, "**********************************\n");
	for (i = 0; i < Tnum; i++)
		if (strcmp(T[i].account, C[Dxiabiao].account) == 0)
		{
			fprintf(file, "** 交易型別:");
			fprintf(file, " %s \n", T[i].type);
			fprintf(file, "** 交易金額:");
			fprintf(file, " %.2f \n", T[i].Tmoney);
			fprintf(file, "** 交易餘額:");
			fprintf(file, " %.2f \n", T[i].Tyue);
			fprintf(file, "** 您的賬號:");
			fprintf(file, " %s \n", T[i].account);
		}
	fprintf(file, "**********************************\n");
	fclose(file);/*關閉檔案*/
	printf("\t\t列印成功!\n");
	system("pause");
}

定義存款函式

{
	float money;/*輸入的存款金額*/
	system("cls");/*清屏*/
	printf("\n\n\n\t\t存款————credit \n\n\n");/*進入存款功能介面*/
	printf("\t\t本機只接收50元或100元幣值人民幣!\n");/*提示資訊*/
	printf("\n\t\t請輸入存款金額:");
	scanf("%f", &money);/*輸入存款金額*/
	if ((int)money % 50 != 0 || money <= 0)/*存款金額必須為50的整數倍且為正數*/
	{
		printf("\n\t\t請輸入面值為50或100的存款金額!請勿輸入負數或0!\n");
		system("pause");
		return;
	}
	strcpy(T[Tnum].account, C[Dxiabiao].account);/*把當前登入賬號複製給交易記錄裡的賬號*/
	strcpy(T[Tnum].type, "存款");/*複製交易型別*/
	T[Tnum].Tmoney = money;/*把存款金額賦給交易金額*/
	C[Dxiabiao].yue += T[Tnum].Tmoney;/*計算存款後的賬戶餘額*/
	T[Tnum].Tyue = C[Dxiabiao].yue;/*交易後的餘額等於賬戶餘額*/
	printf("\n\t\t存款成功!");
	system("pause");
	printf("\n賬號  \t\t交易型別\t交易金額\t交易餘額\n");//輸出賬戶存款交易的資料清單
	printf("%s", T[Tnum].account);
	printf("   %s", T[Tnum].type);
	printf("\t\t%.2f", T[Tnum].Tmoney);
	printf("\t\t%.2f", T[Tnum].Tyue);
	printf("\n");
	Tnum++;/*交易序號加一*/
	system("pause");
}

定義取款函式

{
	float money;/*定義取款金額*/
	system("cls");/*清屏*/
	printf("\n\n\n\t\t取款————debit \n\n\n");/*進入取款功能介面*/
	printf("\t\t本機只可取50或100元幣值人民幣!\n");
	printf("\n\n\t\t請輸入取款金額:");
	scanf("%f", &money);	/*輸入取款金額*/
	if (money> C[Dxiabiao].yue)/*賬戶餘額是否足夠取款*/
	{
		printf("\n\t\t您的餘額不足!\n");
		system("pause");
		return;
	}
	if ((int)money % 50 != 0 || money <= 0)/*取款金額必須為50的整數倍且為正數*/
	{
		printf("\n\t\t請輸入面值為50或100的存款金額!請勿輸入負數或0!\n");
		system("pause");
		return;
	}
	strcpy(T[Tnum].account, C[Dxiabiao].account);/*把當前登入賬號複製給交易記錄裡的賬號*/
	strcpy(T[Tnum].type, "取款");/*複製交易型別*/
	T[Tnum].Tmoney = money;/*取款金額值賦給交易金額*/
	C[Dxiabiao].yue -= T[Tnum].Tmoney;/*計算取款後的賬戶餘額*/
	T[Tnum].Tyue = C[Dxiabiao].yue;/*取款後餘額等於賬戶餘額*/
	printf("\n\t\t取款成功!\n");
	system("pause");
	printf("\n賬號  \t\t交易型別\t交易金額\t交易餘額\n");//輸出賬戶和交易的資料清單
	printf("%s", T[Tnum].account);
	printf("   %s", T[Tnum].type);
	printf("\t\t%.2f", T[Tnum].Tmoney);
	printf("\t\t%.2f", T[Tnum].Tyue);
	printf("\n");
	Tnum++;/*交易序號加一*/
	system("pause");
}

定義修改密碼函式

{
	char password[7], newpassword1[7], newpassword2[7];
	int j = 0;
	printf("\n\n\t\t請輸入原來的密碼:");
	scanf("%s", password);/*輸入舊密碼*/
	if (strcmp(password, C[Dxiabiao].password) != 0)/*判斷舊密碼正確與否*/
	{
		printf("\n\t\t您的密碼輸入錯誤!\n");
		system("pause");
		return;
	}
	do
	{
		printf("\n\t\t請輸入新密碼:");
		scanf("%s", newpassword1);
		printf("\n\t\t請再一次輸入新密碼:");/*輸入兩次新密碼*/
		scanf("%s", newpassword2);
		if (strcmp(newpassword1, newpassword2) != 0)/*判斷輸入的兩次新密碼是否相等*/
		{
			j++;
			printf("\n\t\t您的密碼輸入錯誤!您還有%d次機會輸入密碼!\n", 3 - j);
		}
		if (j == 3)/*新密碼輸入錯誤不得超過三次*/
		{
			printf("密碼修改未成功!\n");
			system("pause");
			return;
		}
	} while (strcmp(newpassword1, newpassword2) != 0);
	strcpy(C[Dxiabiao].password, newpassword1);/*拷貝新密碼到賬戶資訊裡*/
	printf("\n\t\t您的密碼修改成功!\n");
	system("pause");
	return;
}

定義查詢函式

{
	for (;;)/*空迴圈語句*/
	{
		switch (quary_menu()) /*查詢介面選擇判斷*/
		{
		case 1:quary_yue();break;/*呼叫查詢餘額函式*/
		case 2:quary_mingxi();break; /*呼叫查詢明細函式*/	
		case 3:quary_credit();break; /*呼叫查詢存款函式*/
		case 4:quary_debit();break;/*呼叫查詢取款函式*/	
		case 0:return;		
		}
	}
}```
查詢選單
```int quary_menu()
{
	char c;
	do
	{
		system("cls"); /*每次選擇執行前清屏*/
		printf("\n\n\n\t\t *********歡迎進入    查詢介面!*********\n\n"); /*查詢介面選單選擇*/
		printf("\t\t *| 1. 查詢餘額 |\n");
		printf("\t\t *| 2. 查詢明細 |\n");
		printf("\t\t *| 3. 查詢存款 |\n");
		printf("\t\t *| 4. 查詢取款 |\n");
		printf("\t\t *| 0. 返回 |\n");
		printf("\t\t*****************************************\n");
		printf("\t\t請作出選擇(0-4):");
		c = getchar(); /*讀入選擇*/
	} while (c<'0' || c>'4');
	return(c - '0'); /*c變為空後返回重新選擇*/
}

查詢餘額

void quary_yue()    
{
	printf("\n\n\t\t這是查詢餘額功能\n\n");
	printf("\t\t您的賬戶餘額為:%.2f\n\n", C[Dxiabiao].yue);/*輸出賬戶餘額*/
	system("pause");
}```
查詢明細
```void quary_mingxi()  
{
	int i;
	system("cls");/*清屏*/
	printf("\n\n\n\t\t查詢明細————quary MINGXI\n\n");/*進入查詢明細介面*/
	printf("\n\t\t您的賬號:%s", C[Dxiabiao].account);
	printf("\n\n交易型別\t交易金額\t交易餘額\n");//輸出賬戶和交易的資料清單
	for (i = 0; i<Tnum; i++)
		if (strcmp(T[i].account, C[Dxiabiao].account) == 0)
		{
			printf("  %s", T[i].type);
			printf("\t\t%.2f", T[i].Tmoney);
			printf("\t\t%.2f", T[i].Tyue);
			printf("\n");
		}
	system("pause");
}

查詢存取款

{
	int i;
	system("cls");
	printf("\n\n\t\t查詢存款————quary credit\n\n");
	printf("\n\t\t您的賬號:%s", C[Dxiabiao].account);
	printf("\n\n交易型別\t交易金額\t交易餘額\n");//輸出賬戶和交易的資料清單
	for (i = 0; i<Tnum; i++)
		if (strcmp(T[i].account, C[Dxiabiao].account) == 0 && strcmp(T[i].type, "存款") == 0)
		{
			printf("  %s", T[i].type);
			printf("\t\t%.2f", T[i].Tmoney);
			printf("\t\t%.2f", T[i].Tyue);
			printf("\n");
		}
	system("pause");
}
void quary_debit()    
{
	int i;
	system("cls");
	printf("\n\n\n\t\t查詢取款————quary debit\n\n");
	printf("\n\t\t您的賬號:%s", C[Dxiabiao].account);
	printf("\n\n交易型別\t交易金額\t交易餘額\n");//輸出賬戶和交易的資料清單
	for (i = 0; i<Tnum; i++)/*輸出存款記錄*/
		if (strcmp(T[i].account, C[Dxiabiao].account) == 0 && strcmp(T[i].type, "取款") == 0)
		{
			printf("%s", T[i].type);
			printf("\t\t%.2f", T[i].Tmoney);
			printf("\t\t%.2f", T[i].Tyue);
		}
	printf("\n");
	system("pause");
}

四、執行截圖
主介面

註冊

五、作業小結
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.作業心得
通過本次綜合實驗,基本上能畫出各種圖形,對軟體建模有了進一步的瞭解。ATM看起來僅是一個簡單的程式,但是對於我這樣的初學者來說,打出這段程式碼也很費心思,經過這一個星期的課程設計,使我對於打程式碼這種勞動熟悉了不少。在這次作業中,ATM機的程式回顧了不少程式碼知識,在今後的程式設計裡也需要多思考,多總結,訓練記憶。