一、JS代碼怎么編寫?
前端代碼可以被修改,也就是 js 這一層限制沒有任何意義。
一般應該在 nginx 、linux iptables、后端服務 進行限制。
然后你的用途是什么?
是為了抗CC攻擊?
如果是這個目的話,JS 限制訪問這樣的攻擊沒有任何意義,對方是消耗帶寬和服務器資源。
最好的方式是在 iptables 層面就進行限制,效率也最高。
但是如你要求有較高的要求,比如需要更為精準的識別,那么可以在nginx 這一層配合一些抗CC 軟件來進行識別。
二、如何編寫代碼?
具體就上機編寫代碼來講,首先需要打開 c++的開發環境,然 后新建一個工程; 然后新建一個文件(如果是 vc6.0 就可以繼續寫了,
三、怎樣編寫代碼?
編寫代碼需要遵循一定的步驟。首先,明確需求并分析問題,然后設計算法和數據結構。
接下來,選擇適當的編程語言,并使用編輯器或集成開發環境編寫代碼。
在編寫過程中,注重代碼的可讀性和可維護性,使用合適的命名和注釋。
完成代碼后,進行測試和調試,確保代碼的正確性。
最后,進行代碼的優化和重構,提高代碼的效率和可擴展性。編寫代碼需要不斷學習和實踐,掌握編程技巧和設計原則,不斷改進自己的編碼能力。
四、代碼怎么編寫?
零基礎的人想要寫代碼首先需要進行一定的學習,了解一些基礎的編程知識,選擇適合自己的程序語言,之后通過不斷的學習就可以寫代碼。
從簡單的、直接的伯幾行十幾行程序開始,比如計算器;到復雜的小工具,比如大數計算器。這個過程中逐漸明白數組、指針、內存布局、函數,了解遞歸、棧、鏈表,然后學度基本的數據結構。
C語言也好,python也好,得學會把自己的思考用程序實現。舉個例子,想制定計劃表,安排自己的時間,那這個問題就可以寫個程序來實現;想做知筆記、管理自己的文件,這也是一個程序。從簡單的、直接的幾行十幾行程序開始,比如計算器;到復雜的小工具,比如大數計算器。
五、代碼是怎么編寫的?
代碼怎么寫?首先,在精神上或書面上,分解你的代碼并以簡單的方式構建它。第二,寫代碼。第三,研究代碼,看看是否能比你的初始版本進一步提高效率。
編寫程序的步驟
首先明確要解決的問題;
其次分析問題并選擇想要利用的算法,或者自己想一個的算法; 畫流程圖,明確解決問題過程中的邏輯關系和時序關系;
然后才是上機編寫代碼; 之后是debug調試,基本就可以執行了。
六、編寫vbs基本的代碼?
初學者從 基本輸入 輸出開始。然后學分支循環。
msgbox "OK"
name=inputbox("Prompt","Title")
……
七、EXCEL的VBA代碼編寫?
1、在excel中可以添加VBA代碼,通過打開“開發工具”,點擊打開VB編輯器,進入VBA編寫代碼。1開發工具2VB編輯器3選擇工作,雙擊4在代碼窗中輸入代碼2、VBA,Visual Basic for Applications(VBA)是Visual Basic的一種宏語言,是微軟開發出來在其桌面應用程序中執行通用的自動化(OLE)任務的編程語言。主要能用來擴展Windows的應用程式功能,特別是Microsoft Office軟件。也可說是一種應用程式視覺化的Basic 腳本。該語言于1993年由微軟公司開發的的應用程序共享一種通用的自動化語言--------Visual Basic For Application(VBA),實際上VBA是寄生于VB應用程序的版本。微軟在1994年發行的Excel5.0版本中,即具備了VBA的宏功能。
八、C語言編寫圖書管理系統的代碼怎么編寫?
序
時間在流去,我們在長大。
嗨,這里是狐貍~~
今天是2022年的一月四日了,元旦小長假也過去了,新年新氣象,新年新目標,我們要向前看,不要執意過去了,感謝過去,把握現在,展望未來,這是我們現在應該做的。好了,廢話不多說,今天我們分享一個系統,確實也有許久沒有分享過系統了,今天就給大家詳細講一下這個圖書管理系統吧。
主要內容
開發一個圖書信息管理系統,圖書信息包括:圖書編號、書名、作者、出版社、類別、出版時間、價格等基本信息(也可以根據自己情況進行擴充,比如是否借出、庫存量等)。使之能提供以下基本功能:
(1)圖書信息錄入功能(圖書信息用文件保存)--輸入
(2)圖書信息瀏覽功能--輸出
(3)查詢功能(至少一種查詢方式)、排序功能(至少一種排序方式):
①按書名查詢
②按作者名查詢 按照價錢排序 按出版時間排序等等
(4)圖書信息的刪除與修改
擴展功能:可以按照自己的程度進行擴展。比如
(1)簡單的權限處理
(2)報表打印功能
(3)甚至根據自己情況,可以加上學生信息,并擴充為圖書借閱系統。
(4)模糊查詢
(5)綜合查詢
(6)統計功能 比如統計處某一類別的圖書信息 或 篩選出小于指定數量庫存的圖
書信息等等。
概要設計
1 圖書錄入可以錄入圖書名,作者,出版社,出版日期,價格!錄入圖書編號時函數就會判斷此編號是否存在,若
存在不能成功錄入!
2 圖書瀏覽可以瀏覽全部圖書!
3 圖書查詢提供按圖書編號模糊查詢,按圖書名關鍵字查詢,按圖書編號精確查詢,按圖書名精確查詢!模糊查詢
和關鍵字查詢事通過比價字符串的相似度而實現的!
4 修改刪除圖書可以通過圖書查詢來查詢操作的圖書編號,通過編號操作!函數會提示用戶是否調用圖書查詢來找
到自己想要操作的圖書的編號。如果某一本圖書已經被借閱那么用戶就不能刪除該圖書!
5 借閱圖書通過學號和圖書編號進行借閱!如果該學號是第一次借閱那么會提示用戶輸入自己的姓名,并存入
student.txt,方便以后借閱與歸還!
6 歸還圖書先提供學號,然后程序會輸出該學號借閱的所有圖書,然后再通過編號歸還!
7 借閱查詢可查詢某個學生已借但未歸還的圖書!
項目源碼
結構體
先建立結構體,定義結構體成員
typedef struct book/*圖書結構體*/
{
char num[10]; /*書號*/
char name[10]; /*書名*/
char auth[10]; /*作者*/
int count;
int sum;
}Book;
typedef struct borrow/*借書結構體*/
{
char id[20];
char user[20];
char book[20];
char bookid[20];
struct borrow *next;
}BBnode,*BBlink;
struct user
{
char num[10];/* 學號 */
char pass[15];
char name[15];
char sex[10];
};
typedef struct unode
{
struct user data;
struct unode *next;
}Unode,*Ulink;
Unode *os;
登錄界面函數
int login(Ulink l)
{
/*****************登陸窗口初始化****************************/
while(!flag)
{
char User_id[10],password[10],tmp;
int i=0;
User_id[0]='\0';
password[0]='\0';
textbackground(179);
clrscr();
gotoxy(33,23);
textcolor(YELLOW);
cputs("ESC = EXIT");
textcolor(WHITE);
textbackground(179);
box(1,1,80,24);
h_line(2,3,78);
gotoxy(15,2);
cputs("Login now please input the User__ID and Password");
bar_(30,10,23,5,5);
/******************賬號過濾*********************/
while(User_id[0]=='\0')
{
gotoxy(31,11);
textcolor(YELLOW);
textbackground(5);
cputs("User__ID:");
gotoxy(31,13);
cputs("Password:");
textbackground(179);
textcolor(WHITE);
gotoxy(28,7);
cputs("please input the User__ID!");
textbackground(179);
textcolor(YELLOW);
gotoxy(27,11);
putch(272);
gotoxy(27,13);
putch(' ');
gotoxy(40,11);
tmp=getch();
if(tmp==27)
{
flg=27;
return 0;
}
while(tmp!='\r'&&i<=9&&(tmp>=64&&tmp<=90)||(tmp>=97&&tmp<=122||(tmp>=48&&tmp<=57)))
{
textcolor(YELLOW);
textbackground(5);
putch(tmp);
User_id[i]=tmp;
i++;
tmp=getch();
if(tmp==27)
{
flg=27;
return 0;
}
}
User_id[i]='\0';
}
/**********************密碼過濾****************************/
while(password[0]=='\0')
{
gotoxy(28,7);
textbackground(179);
textcolor(WHITE);
cputs(" input the password now ");
textbackground(179);
textcolor(YELLOW);
gotoxy(27,13);
putch(272);
gotoxy(27,11);
putch(' ');
gotoxy(40,13);
i=0;
tmp=getch();
if(tmp==27)
{
flg=27;
return 0;
}
while(tmp!='\r'&&i<=10&&(tmp>=64&&tmp<=90)||(tmp>=97&&tmp<=122||(tmp>=48&&tmp<=57)))
{
textbackground(5);
putch('*');
password[i]=tmp;
i++;
tmp=getch();
if(tmp==27)
{
flg=27;
return 0;
}
}
password[i]='\0';
}
/*************把賬號和密碼進行對比驗證**************/
if(!strcmp(User_id,"admin")&&!strcmp(password,"admin"))
{
return 2;
}
if(cmps(l,User_id,password))
{
return 1;
}
}
}
選擇界面函數
void choose()
{
while(1)
{
textbackground(179);
clrscr();
gotoxy(33,2);
textcolor(WHITE);
cputs("Administrastor");
textcolor(YELLOW);
box(1,1,80,24);
h_line(2,3,78);
gotoxy(3,6);
cputs(">>>-------------------------1.User Management----------------------------<<<");
gotoxy(3,10);
cputs(">>>-------------------------2.Book Management----------------------------<<<");
gotoxy(3,14);
cputs(">>>-------------------------3.Borrow Books-------------------------------<<<");
gotoxy(30,22);
textcolor(RED);
cputs("Please Select!!!");
flg=getch();
if(flg=='2')
bookss();
if(flg=='1')
users();
if(flg=='3')
borrow();
if(flg==27)
{
flg=-1;
return;
}
}
}
void admin()
{
while(1)
{
choose();
if(flg=='1')
bookss();
if(flg=='2')
users();
if(flg=='3')
borrow();
if(flg==27)
{
return;
}
}
}
操作界面函數
void user(Ulink h)
{
int flag;
BBlink l,p,r;/* 連表 */
FILE *fp; /* 文件指針 */
int count=0;
l=(BBnode*)malloc(sizeof(BBnode));
l->next=NULL;
r=l;
fp=fopen(bfile,"rb");
if(fp==NULL)
{
fp=fopen(bfile,"wb");
}
while(!feof(fp))
{
p=(BBnode*)malloc(sizeof(BBnode));
if(fread(p,sizeof(BBnode),1,fp)) /* 將文件的內容放入接點中 */
{
p->next=NULL;
r->next=p;
r=p; /* 將該接點掛入連中 */
count++;
}
}
while(1)
{
textbackground(179);
clrscr();
textcolor(YELLOW);
box(1,1,80,24);
h_line(2,3,78);
gotoxy(3,2);
textcolor(RED);
cputs("A.");
textcolor(BLUE);
cputs("my message ");
textcolor(RED);
cputs("B.");
textcolor(BLUE);
cputs("modyfy my message ");
textcolor(RED);
cputs("C.");
textcolor(BLUE);
cputs("my borrow ");
textcolor(RED);
cputs("D.");
textcolor(BLUE);
cputs("search book");
textcolor(YELLOW);
gotoxy(50,50);
flag=getch();
switch(flag)
{
case 'a':
show(os);
break; /*************添加用戶**********/
case 'b':
Modify_user(h);
Save(h);
break;/*************刪除用戶**********/
case 'c':
Myborrow();
break;
case 'd':
usersearch();
break;
case 27:
return;
}
}
}
添加函數
圖書的添加,包括用戶添加以及管理員添加
void add(blink l)
{
Bnode *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next;
textcolor(RED);
gotoxy(25,4);
cputs("INPUT THE MESSAGE ABOUT BOOK");
gotoxy(31,10);
textcolor(YELLOW);
cputs("Book ID:");
scanf("%s",num);
p=(Bnode *)malloc(sizeof(Bnode));
while(s)
{
if(strcmp(s->data.num,num)==0)
{
textcolor(WHITE);
gotoxy(25,15);
cputs("This ID:");
printf("'%s'",num);
cputs("is exist!");
gotoxy(25,22);
cputs("please Press any key to continue...");
gotoxy(255,252);
getch();
return;
}
s=s->next;
}
strcpy(p->data.num,num);
gotoxy(31,12);
textcolor(YELLOW);
cputs("Input Book name:");
scanf("%s",p->data.name);
gotoxy(31,14);
cputs("input your Book auth:");
scanf("%s",p->data.auth);
gotoxy(31,16);
cputs("input your Book count:");
scanf("%d",&p->data.count);
bookcount=p->data.count+bookcount;
p->data.sum=0;
p->next=NULL;
r->next=p;
r=p;
gotoxy(30,22);
textcolor(RED);
cputs("Add Book Success !!!");
getch();
textcolor(YELLOW);
}
/*******管理員添加用戶*******/
void Add(Ulink l)
{
Unode *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next;
textcolor(RED);
gotoxy(25,4);
cputs("INPUT THE MESSAGE ABOUT BOOK");
gotoxy(31,10);
textcolor(YELLOW);
cputs("User ID:");
scanf("%s",num);
p=(Unode *)malloc(sizeof(Unode));
while(s)
{
if(strcmp(s->data.num,num)==0)
{
gotoxy(25,15);
cputs("This ID:");
printf("'%s'",num);
cputs("is exist!");
gotoxy(25,22);
textcolor(RED);
cputs("please Press any key to continue...");
gotoxy(255,252);
getch();
return;
}
s=s->next;
}
strcpy(p->data.num,num);
gotoxy(31,12);
textcolor(YELLOW);
cputs("Input Password:");
scanf("%s",p->data.pass);
gotoxy(31,14);
cputs("input your name:");
scanf("%s",p->data.name);
gotoxy(31,16);
cputs("input the sex:");
scanf("%s",p->data.sex);
p->next=NULL;
r->next=p;
r=p;
gotoxy(30,22);
cputs("Add User Success !!!");
usercount++;
getch();
textcolor(YELLOW);
}
查找函數
用戶查找以及管理員查找
/*******管理員查找圖書*******/
void qur(blink l)
{
int sel;
char findmess[20];
Bnode *p;
if(!l->next)
{
gotoxy(30,4);
textcolor(WHITE);
cputs("Not Find Bookdata!!!");
getch();
return;
}
textcolor(RED);
gotoxy(25,4);
cputs("Please Select Search Type !");
gotoxy(10,8);
textcolor(WHITE);
cputs("1.Search by ID");
gotoxy(10,10);
cputs("2.Search by Name");
gotoxy(10,12);
cputs("Please Select 1 or 2:");
scanf("%d",&sel);
if(sel==1)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the search ID:");
scanf("%s",findmess);
p=locate(l,findmess,"num");
if(p)
{
gotoxy(36,12);
textcolor(WHITE);
cputs("Book ID:");
printf("%s",p->data.num);
gotoxy(36,14);
textcolor(WHITE);
cputs("Book Name:");
printf("%s",p->data.name);
gotoxy(36,16);
textcolor(WHITE);
cputs("Book author:");
printf("%s",p->data.auth);
gotoxy(36,18);
textcolor(WHITE);
cputs("Book count:");
printf("%d",p->data.count);
getch();
textcolor(YELLOW);
gotoxy(30,21);
cputs("Search Success !!");
}
else
{
gotoxy(30,22);
textcolor(RED);
cputs("Not finde !!!");
getch();
}
}
else if(sel==2) /* 姓名 */
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the search name:");
scanf("%s",findmess);
p=locate(l,findmess,"name");
if(p)
{
gotoxy(36,12);
textcolor(WHITE);
cputs("Book ID:");
printf("%s",p->data.num);
gotoxy(36,14);
textcolor(WHITE);
cputs("Book Name:");
printf("%s",p->data.name);
gotoxy(36,16);
textcolor(WHITE);
cputs("Book author:");
printf("%s",p->data.auth);
gotoxy(36,18);
textcolor(WHITE);
cputs("Book count:");
printf("%d",p->data.count);
getch();
textcolor(YELLOW);
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Not finde !!!");
}
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Error !!");
getch();
}
}
/*******用戶查找圖書*******/
void usersearch()
{
int sel;
char findmess[20];
Bnode *p;
blink l;/* 連表 */
FILE *fp; /* 文件指針 */
int count=0;
Bnode *P,*r;
l=(Bnode*)malloc(sizeof(Bnode));
l->next=NULL;
r=l;
fp=fopen(file,"rb");
if(fp==NULL)
{
fp=fopen(file,"wb");
}
while(!feof(fp))
{
P=(Bnode*)malloc(sizeof(Bnode));
if(fread(P,sizeof(Bnode),1,fp)) /* 將文件的內容放入接點中 */
{
P->next=NULL;
bookcount=bookcount+P->data.count;
booksum=booksum+P->data.sum;
r->next=P;
r=P; /* 將該接點掛入連中 */
count++;
}
}
fclose(fp); /* 關閉文件 */
if(!l->next)
{
gotoxy(30,4);
textcolor(WHITE);
cputs("Not Find Bookdata!!!");
getch();
return;
}
textcolor(RED);
gotoxy(25,4);
cputs("Please Select Delete Type !");
gotoxy(10,8);
textcolor(WHITE);
cputs("1.Search by ID");
gotoxy(10,10);
cputs("2.Search by Name");
gotoxy(10,12);
cputs("Please Select 1 or 2:");
scanf("%d",&sel);
if(sel==1)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the search ID:");
scanf("%s",findmess);
p=locate(l,findmess,"num");
if(p)
{
gotoxy(36,12);
textcolor(WHITE);
cputs("Book ID:");
printf("%s",p->data.num);
gotoxy(36,14);
textcolor(WHITE);
cputs("Book Name:");
printf("%s",p->data.name);
gotoxy(36,16);
textcolor(WHITE);
cputs("Book author:");
printf("%s",p->data.auth);
gotoxy(36,18);
textcolor(WHITE);
cputs("Book count:");
printf("%d",p->data.count-p->data.sum);
getch();
textcolor(YELLOW);
}
else
{
gotoxy(30,22);
textcolor(RED);
cputs("Not finde !!!");
getch();
}
}
else if(sel==2)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the search name:");
scanf("%s",findmess);
p=locate(l,findmess,"name");
if(p)
{
gotoxy(36,12);
textcolor(WHITE);
cputs("Book ID:");
printf("%s",p->data.num);
gotoxy(36,14);
textcolor(WHITE);
cputs("Book Name:");
printf("%s",p->data.name);
gotoxy(36,16);
textcolor(WHITE);
cputs("Book author:");
printf("%s",p->data.auth);
gotoxy(36,18);
textcolor(WHITE);
cputs("Book count:");
printf("%d",(p->data.count-p->data.sum));
getch();
textcolor(YELLOW);
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Not finde !!!");
}
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Error !!");
getch();
}
}
/*******圖書查找*******/
int cmpbook(blink l,char id[],char na[])
{
char findm[20];
Bnode *p;
if(!l->next)
{
gotoxy(25,4);
textcolor(RED);
cputs("Not Find Book!!!");
getch();
return 0;
}
strcpy(findm,id);
p=locate(l,findm,"num");
if(p)
{
strcpy(findm,na);
p=locate(l,findm,"name");
if(p)
{
return 1;
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Book name is NULL !!!");
getch();
return 0;
}
}
else
{
gotoxy(30,22);
textcolor(RED);
cputs("Book id is NULL !!!");
getch();
return 0;
}
}
刪除函數
圖書的刪除
void del(blink l)
{
int sel;
Bnode *p,*r;
char findmess[20];
if(!l->next)
{
gotoxy(25,4);
textcolor(RED);
cputs("=====>not thing could delete!\n");
getch();
return;
}
textcolor(RED);
gotoxy(25,4);
puts("Please Select Delete Type !");
gotoxy(10,8);
textcolor(WHITE);
cputs("1.Delete by Book ID");
gotoxy(10,10);
cputs("2.Delete by Book Name");
gotoxy(10,12);
cputs("Please Select 1 or 2:");
scanf("%d",&sel);
if(sel==1)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the delete ID:");
scanf("%s",findmess);
p=locate(l,findmess,"num");
if(p)
{
bookcount=bookcount-p->data.count;
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
gotoxy(30,22);
textcolor(RED);
cputs("Delete success!\n");
textcolor(YELLOW);
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Error !!");
}
}
else if(sel==2)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the delete name:");
scanf("%s",findmess);
p=locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
gotoxy(30,22);
textcolor(RED);
cputs("Delete success!\n");
bookcount--;
textcolor(YELLOW);
}
else
{
gotoxy(25,18);
cputs("Not find!!");
}
}
else
{
textcolor(RED);
gotoxy(30,22);
cputs("Error !!");
}
getch();
textcolor(YELLOW);
}
借書管理函數
void borrow()
{
while(1)
{
int flag;
BBlink l,p,r;/* 連表 */
FILE *fp; /* 文件指針 */
int count=0;
l=(BBnode*)malloc(sizeof(BBnode));
l->next=NULL;
r=l;
fp=fopen(bfile,"rb");
if(fp==NULL)
{
fp=fopen(bfile,"wb");
}
while(!feof(fp))
{
p=(BBnode*)malloc(sizeof(BBnode));
if(fread(p,sizeof(BBnode),1,fp)) /* 將文件的內容放入接點中 */
{
p->next=NULL;
r->next=p;
r=p; /* 將該接點掛入連中 */
count++;
}
borrowcount=count;
}
while(1)
{
textbackground(179);
clrscr();
textcolor(YELLOW);
box(1,1,80,24);
h_line(2,3,78);
gotoxy(3,2);
textcolor(RED);
cputs("B");
textcolor(BLUE);
cputs("orrow book ");
textcolor(RED);
cputs("R");
textcolor(BLUE);
cputs("eturn book ");
textcolor(RED);
cputs("S");
textcolor(BLUE);
cputs("earch borrow ");
textcolor(YELLOW);
printf("count: (borrow=%d)",borrowcount);
textcolor(RED);
gotoxy(50,50);
flag=getch();
switch(flag)
{
case 'b':
Add_borrow(l);
break; /*************添加用戶**********/
case 'r':
Del_borrow(l);
Save_borrow(l);
break;
case 's':
Qur_borrow(l);
break;
case 27:
return;
}
}
}
}
信息儲存函數
圖書信息的儲存
*******借書信息保存*******/
void Save_borrow(BBlink l)
{
FILE* fp;
BBnode *p;
int flag=1,count=0;
fp=fopen(bfile,"wb");
if(fp==NULL)
{
gotoxy(35,12);
textcolor(RED);
cputs("open error!");
exit(1);
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(BBnode),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
textcolor(RED);
gotoxy(30,24);
/*** printf("save success.(saved%d.)",count);**調試的時候用的*/
}
fclose(fp);
}
還書函數
/* 還書的操作 */
void Del_borrow(BBlink l)
{
int sel;
BBnode *p,*r;
Bnode *L;
char findmess[20];
FILE *fp; /* 文件指針 */
Bnode *P,*R,*Q;
L=(Bnode*)malloc(sizeof(Bnode));
L->next=NULL;
R=L;
fp=fopen(file,"rb");
if(fp==NULL)
{
fp=fopen(file,"wb");
}
while(!feof(fp))
{
P=(Bnode*)malloc(sizeof(Bnode));
if(fread(P,sizeof(Bnode),1,fp)) /* 將文件的內容放入接點中 */
{
P->next=NULL;
R->next=P;
R=P; /* 將該接點掛入連中 */
}
}
fclose(fp); /* 關閉文件 */
if(!l->next)
{
gotoxy(30,4);
textcolor(RED);
cputs("not Book could Return!\n");
getch();
return;
}
textcolor(RED);
gotoxy(25,4);
puts("Please Select Return Type !");
gotoxy(10,8);
textcolor(WHITE);
cputs("1.Return by Borrow ID");
gotoxy(10,10);
cputs("2.Return by book name");
gotoxy(10,12);
cputs("Please Select 1 or 2:");
scanf("%d",&sel);
if(sel==1)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the Borrow ID:");
scanf("%s",findmess);
p=Locate_borrow(l,findmess,"num");
if(p)
{
Q=locate(L,findmess,"num");
if(Q)
{
Q->data.sum=Q->data.sum-1;
save(L);
}
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
gotoxy(30,22);
textcolor(RED);
cputs("Return success!\n");
borrowcount--;
getch();
textcolor(YELLOW);
}
else
{
gotoxy(30,22);
textcolor(RED);
cputs("Note find !!");
getch();
}
}
else if(sel==2)
{
gotoxy(36,8);
textcolor(YELLOW);
cputs("Input the Book name:");
scanf("%s",findmess);
p=Locate_borrow(l,findmess,"book");
if(p)
{
Q=locate(L,findmess,"name");
if(Q)
{
Q->data.sum=Q->data.sum-1;
save(L);
}
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
gotoxy(30,22);
textcolor(RED);
cputs("Borrow success!\n");
borrowcount--;
getch();
textcolor(YELLOW);
}
else
{
gotoxy(30,18);
textcolor(RED);
cputs("Not find!!");
getch();
}
}
else
{
gotoxy(30,22);
textcolor(RED);
cputs("Not finde !!");
getch();
}
textcolor(YELLOW);
}
修改函數
也分為用戶和管理員兩種情況
/* ****用于管理員修改用戶資料 ***/
void Modify(Ulink l)
{
Unode *p;
char findmess[20];
if(!l->next)
{
gotoxy(30,4);
textcolor(RED);
cputs("not thing could modify!");
getch();
return;
}
gotoxy(30,4);
textcolor(RED);
cputs("Modify User Message");
gotoxy(25,8);
textcolor(YELLOW);
cputs("input the User Id:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
textcolor(YELLOW);
gotoxy(25,10);
printf("Inpute The New ID(old:%s):",p->data.num);
scanf("%s",p->data.num);
gotoxy(25,12);
printf("Input The New Password(old:%s):",p->data.pass);
scanf("%s",p->data.pass);
gotoxy(25,14);
printf("Input The New Name(old:%s):",p->data.name);
scanf("%s",p->data.name);
gotoxy(25,16);
printf("Input The New Sex(old:%s):",p->data.sex);
scanf("%s",p->data.sex);
gotoxy(30,20);
textcolor(RED);
cputs("Modify Success !!!");
getch();
textcolor(YELLOW);
}
else
{
gotoxy(30,16);
textcolor(RED);
cputs("Not Finde !!!");
getch();
}
}
/****供用戶修改用戶自己資料 */
void Modify_user(Ulink l)
{
Unode *p;
char findmess[20];
if(!l->next)
{
gotoxy(30,4);
textcolor(RED);
cputs("not thing could modify!");
getch();
return;
}
gotoxy(30,4);
textcolor(RED);
cputs("Modify User Message");
gotoxy(33,8);
textcolor(YELLOW);
strcpy(findmess,os->data.num);
printf("your id:%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
textcolor(YELLOW);
gotoxy(24,10);
printf("Input The New Password(old:%s):",p->data.pass);
scanf("%s",p->data.pass);
gotoxy(24,12);
printf("Input The New Name(old:%s):",p->data.name);
scanf("%s",p->data.name);
gotoxy(24,14);
printf("Input The New Sex(old:%s):",p->data.sex);
scanf("%s",p->data.sex);
gotoxy(31,18);
textcolor(RED);
cputs("Modify Success !!!");
getch();
textcolor(YELLOW);
}
else
{
gotoxy(30,16);
textcolor(RED);
cputs("Not Finde !!!");
getch();
}
}
添加借書函數
/*******添加借書*******/
void Add_borrow(BBlink l)
{
Ulink H;/* 連表 */
FILE *Fp; /* 文件指針 */
Unode *Q,*T;
blink L;/* 連表 */
FILE *FP; /* 文件指針 */
int ttl;
Bnode *P,*R;
char bookid[20];
char bookname[20];
char userid[20];
BBnode *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next;
L=(Bnode*)malloc(sizeof(Bnode));
L->next=NULL;
R=L;
FP=fopen(file,"rb");
if(FP==NULL)
{
FP=fopen(file,"wb");
}
while(!feof(FP))
{
P=(Bnode*)malloc(sizeof(Bnode));
if(fread(P,sizeof(Bnode),1,FP)) /* 將文件的內容放入接點中 */
{
P->next=NULL;
bookcount=bookcount+P->data.count;
R->next=P;
R=P; /* 將該接點掛入連中 */
}
}
fclose(FP); /* 關閉文件 */
H=(Unode*)malloc(sizeof(Unode));
H->next=NULL;
T=H;
Fp=fopen(ufile,"rb");
if(Fp==NULL)
{
Fp=fopen(ufile,"wb");
}
while(!feof(Fp))
{
Q=(Unode*)malloc(sizeof(Unode));
if(fread(Q,sizeof(Unode),1,Fp)) /* 將文件的內容放入接點中 */
{
Q->next=NULL;
T->next=Q;
T=Q; /* 將該接點掛入連中 */
}
}
fclose(Fp);
textcolor(RED);
gotoxy(25,4);
cputs("Please input thease message");
gotoxy(30,10);
textcolor(YELLOW);
cputs("Input Borrow ID:");
scanf("%d",&ttl);
itoa(ttl,num,10) ;
p=(BBnode *)malloc(sizeof(BBnode));
while(s)
{
if(strcmp(s->id,num)==0)
{
gotoxy(30,15);
cputs("Borrow ID:");
printf("'%s'",num);
cputs("is exist!");
gotoxy(26,22);
textcolor(RED);
cputs("please Press any key to continue...");
gotoxy(255,252);
getch();
return;
}
s=s->next;
}
strcpy(p->id,num);
gotoxy(31,12);
textcolor(YELLOW);
cputs("Input book id:");
scanf("%s",bookid);
gotoxy(31,14);
textcolor(YELLOW);
cputs("Input book name:");
scanf("%s",bookname);/***************************************圖書判斷在否***************************************/
if(cmpbook(L,bookid,bookname))
{
strcpy(p->bookid,bookid);
strcpy(p->book,bookname);
gotoxy(31,16);
cputs("input your ID:");
scanf("%s",userid); /**************************************用戶判斷在否********************************/
if(cmpuser(H,userid))
{
strcpy(p->user,userid);
p->next=NULL;
r->next=p;
r=p;
if(changeb(L,bookid))
{
gotoxy(30,22);
cputs("Borrow Success !!!");
Save_borrow(l);
borrowcount++;
getch();
}
}
}
textcolor(YELLOW);
}
查找借書函數
查找自己借了哪些書
void Myborrow()
{
int i;
BBlink l,p,r;/* 連表 */
FILE *fp; /* 文件指針 */
int count=0;
l=(BBnode*)malloc(sizeof(BBnode));
l->next=NULL;
r=l;
fp=fopen(bfile,"rb");
if(fp==NULL)
{
fp=fopen(bfile,"wb");
}
i=6;
while(!feof(fp))
{
p=(BBnode*)malloc(sizeof(BBnode));
if(fread(p,sizeof(BBnode),1,fp)) /* 將文件的內容放入接點中 */
{
textcolor(WHITE);
gotoxy(30,4);
cputs("Your borrow book");
if(strcmp(p->user,os->data.num)==0)
{
textcolor(YELLOW);
gotoxy(20,i);
printf("Borrow ID:%s\tBook id:%s\tBook name:%s",p->id,p->bookid,p->book);
i++;
p->next=NULL;
r->next=p;
r=p; /* 將該接點掛入連中 */
count++;
}
}
myborrow=count;
if(myborrow==0)
{
textcolor(YELLOW);
gotoxy(30,13);
cputs("You no borrow !!");
}
}
fclose(fp);
textcolor(YELLOW);
gotoxy(65,2);
printf("(borrow=%d)",myborrow);
getch();
}
借書管理函數
void borrow()
{
while(1)
{
int flag;
BBlink l,p,r;/* 連表 */
FILE *fp; /* 文件指針 */
int count=0;
l=(BBnode*)malloc(sizeof(BBnode));
l->next=NULL;
r=l;
fp=fopen(bfile,"rb");
if(fp==NULL)
{
fp=fopen(bfile,"wb");
}
while(!feof(fp))
{
p=(BBnode*)malloc(sizeof(BBnode));
if(fread(p,sizeof(BBnode),1,fp)) /* 將文件的內容放入接點中 */
{
p->next=NULL;
r->next=p;
r=p; /* 將該接點掛入連中 */
count++;
}
borrowcount=count;
}
while(1)
{
textbackground(179);
clrscr();
textcolor(YELLOW);
box(1,1,80,24);
h_line(2,3,78);
gotoxy(3,2);
textcolor(RED);
cputs("B");
textcolor(BLUE);
cputs("orrow book ");
textcolor(RED);
cputs("R");
textcolor(BLUE);
cputs("eturn book ");
textcolor(RED);
cputs("S");
textcolor(BLUE);
cputs("earch borrow ");
textcolor(YELLOW);
printf("count: (borrow=%d)",borrowcount);
textcolor(RED);
gotoxy(50,50);
flag=getch();
switch(flag)
{
case 'b':
Add_borrow(l);
break; /*************添加用戶**********/
case 'r':
Del_borrow(l);
Save_borrow(l);
break;
case 's':
Qur_borrow(l);
break;
case 27:
return;
}
}
}
}
主函數
main()
{
Ulink h,os;/* 連表 */
FILE *fp; /* 文件指針 */
Unode *p,*r;
h=(Unode*)malloc(sizeof(Unode));
h->next=NULL;
r=h;
fp=fopen(ufile,"rb");
if(fp==NULL)
{
fp=fopen(ufile,"wb");
}
while(!feof(fp))
{
p=(Unode*)malloc(sizeof(Unode));
if(fread(p,sizeof(Unode),1,fp)) /* 將文件的內容放入接點中 */
{
p->next=NULL;
r->next=p;
r=p; /* 將該接點掛入連中 */
}
}
fclose(fp);
system("wellcome");
if(flg==27)
{
flg=-1;
return;
}
while(1)
{
flag=login(h);
if(flg==27)
{
flg=-1;
break;
}
if(flag==2)
{
choose();
flag=0;
}
if(flag==1)
{
user(h);
flag=0;
}
}
}
總結
今天的代碼量有點小多,難度也不小,用了大量的鏈表來儲存數據,還有一些功能因為篇幅的問題沒有放上來,總的來說,這個圖書管理系統的功能是很全面的,無論從哪個角度來看。當然啦。有興趣的同學可以進群領取完整的源碼看看,絕對是一個不錯的機會,可以說,你要是學會了這個系統,你的C語言在我看來就完全沒有問題了,而且在數據結構一塊,你也算是小成了,所以希望大家可以認真學習,爭取早日掌握。
這也是2022年的第一篇文章了,希望2022繼續加油,向大家分享更多有趣的、有用的知識,十分感謝大家的一路支持,后續我還會發布更多的項目源或者學習資料,希望大家可以持續關注,有什么問題可以回帖留言。想要提前掌握的可以加群領取C/C++學習資料以及其他項目的源碼的可以加群【1083227756】了解。想要對程序員的未來發展有興趣的可以關注微信公眾號:【狐貍的編碼時光】,希望和大家一起學習進步!
九、代碼雨怎么編寫?
1、首先找到開始菜單,一般找到附件,在里面打開記事本。
2、再里面編輯代碼內容
3、然后在保存時彈出保存界面。
4、點擊保存途徑桌面,之后在文件名里隨便編寫一個字然后后綴+ .bat
5、保存后,就在桌面啦
6、打開,效果就出來啦
擴展資料:
代碼就是程序員用開發工具所支持的語言寫出來的源文件,是一組由字符、符號或信號碼元以離散形式表示信息的明確的規則體系。代碼設計的原則包括唯一確定性、標準化和通用性、可擴充性與穩定性、便于識別與記憶、力求短小與格式統一以及容易修改等。 源代碼是代碼的分支,某種意義上來說,源代碼相當于代碼。現代程序語言中,源代碼可以書籍或磁帶形式出現,但最為常用格式是文本文件,這種典型格式的目的是為了編譯出計算機程序。計算機源代碼最終目的是將人類可讀文本翻譯成為計算機可執行的二進制指令,這種過程叫編譯,它由通過編譯器完成。
十、代碼怎么編寫方法?
編寫代碼的方法通常包括以下幾個步驟:明確需求:在開始編寫代碼之前,首先要明確你要解決的問題或實現的功能。理解需求是至關重要的,它能幫助你設計出正確的算法和數據結構。設計算法和數據結構:根據需求,你需要設計出相應的算法和數據結構。這可能涉及到一些邏輯思考和問題分解,以便找出解決問題的最佳方式。選擇編程語言:根據你的需求和設計的算法,選擇一種適合的編程語言。不同的編程語言有各自的優勢和適用場景,選擇合適的語言可以大大提高代碼的效率和可讀性。編寫代碼:使用編程語言的語法規則,將你的算法和數據結構轉化為代碼。這一步需要注重代碼的清晰度和可讀性,同時也要考慮代碼的健壯性和可維護性。測試和調試:在代碼編寫完成后,需要進行測試和調試。通過測試可以檢查代碼是否按照預期工作,而調試則是找出并修復代碼中的錯誤。優化和維護:在代碼穩定運行后,可能還需要進行優化以提高性能,同時也要進行必要的維護工作,以應對需求變化或修復潛在問題。以上是編寫代碼的基本方法,具體實施時可能還需要根據項目需求和團隊情況進行適當的調整。