我的學生資訊管理系統總結
我的學生管理系統總結
花了一天時間用C語言做了一個學生資訊管理系統,有一些想要總結的地方,在此記錄一下。
雖然是一個簡單的系統,簡單到只有增刪改查功能,而且,儲存資料的地方不是資料庫,而是檔案,但是,我還是按照了做大型專案時採用的“三層架構”的思路來寫:大體上就是:底層,和資料庫打交道;中間層,處理使用者輸入的業務邏輯,並將錯誤資訊反饋給使用者;表面層,就是和將介面展現給使用者,接受使用者的輸入。
下面是,總結的一些好的程式碼:
1、判斷鍵盤連續兩次輸入回車(也可以用來判斷連續兩次輸入某字元)。
void back_button()/*在子選單下,使用者按兩下Enter鍵,返回主選單*/
{
printf("Please press \"Enter button\" two times to back previous menu.\n");
char ch;
do
{
while (fflush(stdin), ch = getch(), ch != '\r');
if ((ch = getch()) == '\r'){
break;
}
} while (1);
system("cls");
}
2、用fgets()接受螢幕輸入資訊,一方面可以限制輸入長度,一方面也能判斷使用者是直接按下Enter鍵,還是直接按下Ctrl+Z.
void sub_choose_1()/*子選單1:根據學生姓名搜尋學生資訊*/
{
system("cls");
char stu_name[STU_NAME_SIZE];
memset(stu_name,0,STU_NAME_SIZE);/*將字串初始化為0*/
loops_search_stu_name:printf("Please input a name for search: \n");
fflush(stdin);
fgets(stu_name, STU_NAME_SIZE, stdin);
if (stu_name[0] == 0){
return;
}
strProcess(stu_name);/*將fgets()新增的'\n'去掉*/
if (strlen(stu_name) == 0){
printf("Student's name cannot empty!Please input again.\n");
goto loops_search_stu_name;
}
stu_pNode stu;
stu = searchStuInfoByName(stuList,stu_name);
showAllStuInfo(stu);
back_button();
}
3、上一個函式是對輸入字串時的錯誤資訊進行判斷,這個函式是對輸入數時的錯誤資訊進行判斷。
(總結一下,由於fgets()的返回值是輸入字串的指標或者NULL,所以沒法用返回值進行判斷,也就沒法用while迴圈。而scanf()函式的返回值是:正確接受時,返回接受的個數,沒正確接受時,返回0,遇到Ctrl+Z時,返回EOF(即-1),所以,可以用迴圈進行處理)
void sub_choose_2()/*子選單2:根據學生學號搜尋學生資訊*/
{
system("cls");
int stu_id, input_info;
printf("Please input a sno for search: \n");
printf("Sno: ");
while (fflush(stdin), input_info = scanf("%d", &stu_id), input_info == EOF || input_info != 1){
if (input_info == EOF){
return;
}
printf("Sno is a number,please input again.\n");
printf("Sno: ");
}
stu_pNode stu;
stu = searchStuInfoById(stuList,stu_id);
showOneStuInfo(stu);
back_button();
}
4、這段程式碼,對fgets()的返回值進行了非常細的劃分。
loop_modify_name:printf("Name: ");
if (fflush(stdin), fgets(new_stu.stu_name, STU_NAME_SIZE, stdin)){/*使用者敲回車,此條件成立*/
strProcess(new_stu.stu_name);
}
else{/*使用者輸入Ctrl+Z,此條件成立*/
strcpy(new_stu.stu_name, stu_info->stu_name);
}
if (strlen(new_stu.stu_name) == 0){
printf("Name must be not empty.If don't want to modify,press Ctrl+Z.\n");
goto loop_modify_name;
}
5、這一大段程式碼,非常完美的模擬了使用者輸入使用者名稱密碼進行登入時的情景。其中包括了,允許使用者有三次輸錯的機會、模擬將使用者的輸入資訊轉換成‘*’在螢幕上顯示(包括按退格鍵時,‘*’跟著減少,密碼輸入過長,停止輸入,並且有提示音等細節功能)。
void userNameprocess(char *str)
{
while (*str != 10){
++str;
}
*str = 0;
}
void backspace(int *length,char **ch)
{
--(*ch);
--(*length);
putchar(8);
putchar(32);
putchar(8);
}
void passwordGets(char *psw)
{
char ch;
int psw_length = 0, sign = 0;
while ((ch = getch()) != '\r'){/*使用者沒有輸入Enter鍵時,繼續監測鍵盤*/
if (psw_length < USER_PASSWORD_LEN - 1){/*允許輸入的最大長度限制*/
if (ch == 8){/*如果是退格鍵*/
if (psw_length >0){
sign = 1;
backspace(&psw_length, &psw);
}
else{/*長度小於0,即退格到開頭了,響鈴警報*/
putchar(7);
}
}
else{/*不是退格鍵,繼續前進*/
sign = 0;
*(psw++) = ch;
++psw_length;
}
if (!sign){/*退格鍵標記,當使用者按下退格鍵時,不再列印'*'.*/
putchar('*');
}
}
else if (ch == 8){/*長度超過限制,為能重新輸入,即滿足輸入條件(lentgh<psw_length < USER_PASSWORD_LEN - 1),在按退格鍵時,退一格*/
backspace(&psw_length, &psw);
}
else{/*長度已經超過最大限制了,如繼續輸入非回車非退格鍵,則響鈴警報*/
putchar(7);
}
}
*psw = '\0';
}
int login()
{
char user_name[USER_NAME_SIZE];
char user_password[USER_PASSWORD_LEN];
user_pNode user;
int count = 3;
do{
--count;
system("cls");
printf("enter user_name: ");
fgets(user_name, USER_NAME_SIZE + 1, stdin);/*獲取使用者名稱*/
userNameprocess(user_name);
system("cls");
printf("enter usr_password: ");
passwordGets(user_password);/*獲取使用者密碼*/
user = searchUserAccountInfoByName(userList, user_name);
if (user){
if (strcmp(user->user_password, user_password) != 0){
if (count == 0){
system("cls");
printf("You have already input Wrong 3 times,system will be exit.\n");
}
else{
printf("\nPassword wrong,please try again!you have %d times.\n", count);
system("pause");
}
}
else{
return user->role_type;
}
}
else{
if (count == 0){
system("cls");
printf("You have already input Wrong 3 times,system will be exit.\n");
}
else{
printf("\nUser name is not exist,please try again!you have %d times.\n", count);
system("pause");
}
}
} while (count);
exit(-1);
}
相關文章
- 學生選題資訊管理系統
- 學生資訊管理系統用例
- 某學校的學生資訊管理系統網站網站
- 基於php學生資訊管理系統PHP
- Java簡單學生資訊管理系統Java
- 管理資訊系統川大972 | 管理資訊系統全書知識點總結
- Python編寫簡單的學生資訊管理系統Python
- java+SQL做學生資訊管理系統(增刪改查)學生新作JavaSQL
- 學生管理系統
- python實現學生資訊管理系統(從淺到深)Python
- Python專案開發案例(一)————學生資訊管理系統Python
- 教你如何運用python實現學生資訊管理系統Python
- Python學生資訊管理系統-簡易版(Python基礎)Python
- Linux 系統管理總結Linux
- 學生管理系統(springMVC)SpringMVC
- Java入門專案:學生資訊管理系統V1Java
- 學生資訊管理系統 (第二天 )技術彙總及問題解決
- 基於java的大學生健康資訊管理系統的設計與實現Java
- 【C++】學生管理系統C++
- JAVA學生宿舍管理系統Java
- Java之學生資訊管理系統升級版(資料庫程式設計)Java資料庫程式設計
- 基於jsp學生資訊管理系統的設計與實現(含原始檔)JS
- 基於ThinkPHP框架開發的響應式學生資訊後臺管理系統PHP框架
- C# 簡單的學生資訊管理系統,好看的UI介面,與資料庫互動C#UI資料庫
- 流行的後臺管理系統模板總結
- (十)ArrayList&&學生管理系統
- Python簡易學生管理系統Python
- 教你如何用python實現學生通訊錄管理系統Python
- python基礎(16):學生資訊管理系統——Python編寫(附全部程式碼)Python
- Django練習-學生管理系統案例Django
- 9、ArrayList集合完成學生管理系統
- 基於python的學生資訊管理系統!聽說好多人的作業都是這個Python
- Java Swing+Mysql+beautyEye(介面優美)學校成績管理系統(管理員/學生/教師,資訊管理/選課管理/成績管理)JavaMySql
- 20145317 《資訊保安系統設計基礎》第七週學習總結2
- 4-資訊系統管理
- 醫學實驗室資訊管理系統原始碼原始碼
- [Python急救站]簡單的學生管理系統Python
- 日誌管理系統,多種方式總結
- 基於“結構體”實現簡易版學生管理系統(Golang)結構體Golang