❶ c語言索引搜索如何建立索引表
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<direct.h>
#include<string.h>
#include<io.h>
#include<stdio.h>
#include<iostream>
#include<windows.h>
#include<time.h>
usingnamespacestd;
FILE*p;
voidmd(longlongintm)
{
longlongintshi,fen,miao,hmiao;
hmiao=m%3600000;
m=m/1000;
if(m/3600<24)
{
shi=m/3600;
fen=m/60%60;
miao=m%60;
cout<<endl<<"換算等於"<<shi<<"時:"<<fen<<"分:"<<miao<<"秒:"<<(hmiao-miao*1000)<<"毫秒"<<endl;
}
elseprintf("輸入數值太大");
}
classCBrowseDir
{
protected:
charm_szInitDir[_MAX_PATH];
public:
CBrowseDir();
boolSetInitDir(constchar*dir);
boolBeginBrowse(constchar*filespec);
protected:
boolBrowseDir(constchar*dir,constchar*filespec);
virtualboolProcessFile(constchar*filename);
virtualvoidProcessDir(constchar*currentdir,constchar*parentdir);
};
CBrowseDir::CBrowseDir()
{
getcwd(m_szInitDir,_MAX_PATH);
intlen=strlen(m_szInitDir);
if(m_szInitDir[len-1]!='\')
strcat(m_szInitDir,"\");
}
boolCBrowseDir::SetInitDir(constchar*dir)
{
if(_fullpath(m_szInitDir,dir,_MAX_PATH)==NULL)
returnfalse;
if(_chdir(m_szInitDir)!=0)
returnfalse;
intlen=strlen(m_szInitDir);
if(m_szInitDir[len-1]!='\')
strcat(m_szInitDir,"\");
returntrue;
}
boolCBrowseDir::BeginBrowse(constchar*filespec)
{
ProcessDir(m_szInitDir,NULL);
returnBrowseDir(m_szInitDir,filespec);
}
boolCBrowseDir::BrowseDir(constchar*dir,constchar*filespec)
{
_chdir(dir);
longhFile;
_finddata_tfileinfo;
if((hFile=_findfirst(filespec,&fileinfo))!=-1)
{
do
{
if(!(fileinfo.attrib&_A_SUBDIR))
{
charfilename[_MAX_PATH];
strcpy(filename,dir);
strcat(filename,fileinfo.name);
puts(filename);
fputs(filename,p);
fprintf(p," ");
if(!ProcessFile(filename))
returnfalse;
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
_chdir(dir);
if((hFile=_findfirst("*.*",&fileinfo))!=-1)
{
do
{
if((fileinfo.attrib&_A_SUBDIR))
{
if(strcmp(fileinfo.name,".")!=0&&strcmp
(fileinfo.name,"..")!=0)
{
charsubdir[_MAX_PATH];
strcpy(subdir,dir);
strcat(subdir,fileinfo.name);
strcat(subdir,"\");
ProcessDir(subdir,dir);
if(!BrowseDir(subdir,filespec))
returnfalse;
}
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
returntrue;
}
boolCBrowseDir::ProcessFile(constchar*filename)
{
returntrue;
}
voidCBrowseDir::ProcessDir(constchar
*currentdir,constchar*parentdir)
{
}
classCStatDir:publicCBrowseDir
{
protected:
longlongintm_nFileCount;
longlongintm_nSubdirCount;
public:
CStatDir()
{
m_nFileCount=m_nSubdirCount=0;
}
intGetFileCount()
{
returnm_nFileCount;
}
intGetSubdirCount()
{
returnm_nSubdirCount-1;
}
protected:
virtualboolProcessFile(constchar*filename)
{
m_nFileCount++;
returnCBrowseDir::ProcessFile(filename);
}
virtualvoidProcessDir
(constchar*currentdir,constchar*parentdir)
{
m_nSubdirCount++;
CBrowseDir::ProcessDir(currentdir,parentdir);
}
};
intmain()
{
intDiskCount=0;
DWORDDiskInfo=GetLogicalDrives();
while(DiskInfo)
{
if(DiskInfo&1)
{
++DiskCount;
}
DiskInfo=DiskInfo>>1;
}
cout<<"邏輯磁碟數量:"<<DiskCount<<endl;
intDSLength=GetLogicalDriveStrings(0,NULL);
char*DStr=newchar[DSLength];
GetLogicalDriveStrings(DSLength,(LPTSTR)DStr);
intDType;
intsi=0;
BOOLfResult;
;
unsignedlonglongintTotalBytes;
;
;
intg=0,k=0;
charname[100];
for(inti=0;i<DSLength/4;++i)
{
chardir[5]={DStr[si],':','\'};
cout<<dir;
DType=GetDriveType(DStr+i*4);
if(DType==DRIVE_FIXED)
{
cout<<"硬碟";
name[k]=DStr[si];
k++;
g++;
}
elseif(DType==DRIVE_CDROM)
{
cout<<"光碟機";
}
elseif(DType==DRIVE_REMOVABLE)
{
cout<<"可移動式磁碟";
}
elseif(DType==DRIVE_REMOTE)
{
cout<<"網路磁碟";
}
elseif(DType==DRIVE_RAMDISK)
{
cout<<"虛擬RAM磁碟";
}
elseif(DType==DRIVE_UNKNOWN)
{
cout<<"未知設備";
}
fResult=GetDiskFreeSpaceEx(dir,(PULARGE_INTEGER)&i64FreeBytesToCaller,(PULARGE_INTEGER)&i64TotalBytes,(PULARGE_INTEGER)&i64FreeBytes);
if(fResult)
{
if((i64TotalBytes/1024/1024)>1024)
cout<<"磁碟大小:"<<(float)i64TotalBytes/1024/1024/1024<<"GB";
else
cout<<"磁碟大小:"<<(float)i64TotalBytes/1024/1024<<"MB";
if((i64FreeBytesToCaller/1024/1024)>1024)
cout<<"剩餘空間:"<<(float)i64FreeBytesToCaller/1024/1024/1024<<"GB";
else
cout<<"剩餘空間:"<<(float)i64FreeBytesToCaller/1024/1024<<"MB";
}
else
{
cout<<"設備未准備好或啟用了系統加密!";
}
if(!fResult)
{
k--;
}
cout<<endl;
si+=4;
}
cout<<"共有硬碟"<<g<<"塊"<<endl;
g=k+1;
cout<<"共有未加密的硬碟"<<g<<"塊"<<endl;
cout<<"正在啟動索引程序"<<endl;
inti;
p=fopen("list.txt","a+");
if(g==1)
{
cout<<"您只有一個c盤"<<endl;
cout<<"檢測C盤可能會讓程序崩潰"<<endl;
}
clock_tstart,finish;
start=clock();
for(i=1;i<g;i++)
{
fprintf(p,"%c盤內的文件如下 ",name[i]);
charbuf[6]={name[i],':','\'};
CStatDirstatdir;
statdir.SetInitDir(buf);
statdir.BeginBrowse("*.*");
fprintf(p,"文件總數:%d 子目錄總數:%d ",statdir.GetFileCount(),statdir.GetSubdirCount());
printf("文件總數:%d 子目錄總數:%d ",statdir.GetFileCount(),statdir.GetSubdirCount());
}
cout<<"全部完成"<<endl;
finish=clock();
cout<<"用時"<<(finish-start)<<"毫秒";
md(finish-start);
return0;
}
❷ 看不太明白 怎麼用C語言編寫圖書館管理系統呢
通過c語言中的鏈表記錄圖書的信息、修改圖書的信息、刪除圖書的信息、保存圖書的信息、輸出圖書的信息啊、載入圖書信息,記錄,修改,刪除很簡單解決,保存的話,就用文件的輸入輸出就行了,同理就是載入信息,也是用文件的輸入輸出就行了。然後這些各個功能就單獨作為一個函數,然後通過主函數去調用,就行了。
❸ 怎樣用C語言製作圖書館管理系統
這個是自己寫的
注釋很清楚地
有什麼不清楚的問我
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct books_list
{
char author[20]; /*作者名*/
char bookname[20]; /*書名*/
char publisher[20]; /*出版單位*/
char pbtime[15]; /*出版時間*/
char loginnum[10]; /*登陸號*/
float price; /*價格*/
char classfy[10]; /*分類號*/
struct books_list * next; /*鏈表的指針域*/
};
struct books_list * Create_Books_Doc(); /*新建鏈表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*刪除*/
void Print_Book_Doc(struct books_list * head);/*瀏覽*/
void search_book(struct books_list * head); /*查詢*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存數據至文件*/
/*新建鏈表頭節點*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配頭節點空間*/
head->next=NULL; /*頭節點指針域初始化,定為空*/
return head;
}
/*保存數據至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen("data.txt","w+"); /*以寫方式新建並打開 data.txt文件*/
fprintf(fp,"┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n"); /*向文件輸出表格*/
fprintf(fp,"┃登錄號┃ 書 名 ┃ 作 者┃ 出版單位 ┃ 出版時間 ┃分類號┃ 價格 ┃\n");
fprintf(fp,"┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指針從頭節點開始移動,遍歷至尾結點,依次輸出圖書信息*/
while(p->next!= NULL)
{
p=p->next;
fprintf(fp,"┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
}
fprintf(fp,"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
fclose(fp);
printf(" 已將圖書數據保存到 data.txt 文件\n");
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定義結構體指針變數 s指向開辟的新結點首地址 p為中間變數*/
struct books_list *s, *p;
char flag='Y'; /*定義flag,方便用戶選擇重復輸入*/
p=head;
/*遍歷到尾結點,p指向尾結點*/
while(p->next!= NULL)
{
p=p->next;
}
/*開辟新空間,存入數據,添加進鏈表*/
while(flag=='Y'||flag=='y')
{
s=(struct books_list *)malloc(sizeof(struct books_list));
printf("\n 請輸入圖書登陸號:");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n 請輸入圖書書名:");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n 請輸入圖書作者名:");
fflush(stdin);
scanf("%s",s->author);
printf("\n 請輸入圖書出版社:");
fflush(stdin);
scanf("%s",s->publisher);
printf("\n 請輸入圖書出版時間:");
fflush(stdin);
scanf("%s",s->pbtime);
printf("\n 請輸入圖書分類號:");
fflush(stdin);
scanf("%s",s->classfy);
printf("\n 請輸入圖書價格:");
fflush(stdin);
scanf("%f",&s->price);
printf("\n");
p->next=s; /*將新增加的節點添加進鏈表*/
p=s; /*p指向尾節點,向後移*/
s->next=NULL;
printf(" ━━━━ 添加成功!━━━━");
printf("\n 繼續添加?(Y/N):");
fflush(stdin);
scanf("%c",&flag);
printf("\n");
if(flag=='N'||flag=='n')
{break;}
else if(flag=='Y'||flag=='y')
{continue;}
}
save(head); /*保存數據至文件*/
return;
}
/*查詢操作*/
void search_book(struct books_list *head)
{
struct books_list * p;
char temp[20];
p=head;
if(head==NULL || head->next==NULL) /*判斷資料庫是否為空*/
{
printf(" ━━━━ 圖書庫為空!━━━━\n");
}
else
{
printf("請輸入您要查找的書名: ");
fflush(stdin);
scanf("%s",temp);
/*指針從頭節點開始移動,遍歷至尾結點,查找書目信息*/
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n圖書已找到!\n");
printf("\n");
printf("登錄號: %s\t\n",p->loginnum);
printf("書名: %s\t\n",p->bookname);
printf("作者名: %s\t\n",p->author);
printf("出版單位: %s\t\n",p->publisher);
printf("出版時間: %s\t\n",p->pbtime);
printf("分類號: %s\t\n",p->classfy);
printf("價格: %.2f\t\n",p->price);
}
if(p->next==NULL)
{
printf("\n查詢完畢!\n");
}
}
}
return;
}
/*瀏覽操作*/
void Print_Book_Doc(struct books_list * head)
{
struct books_list * p;
if(head==NULL || head->next==NULL) /*判斷資料庫是否為空*/
{
printf("\n ━━━━ 沒有圖書記錄! ━━━━\n\n");
return;
}
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n");
printf("┃登錄號┃ 書 名 ┃ 作 者┃ 出版單位 ┃ 出版時間 ┃分類號┃ 價格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指針從頭節點開始移動,遍歷至尾結點,依次輸出圖書信息*/
while(p->next!= NULL)
{
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price); /*循環輸出表格*/
}
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
printf("\n");
}
/*修改操作*/
void info_change(struct books_list * head)
{
struct books_list * p;
int panan=0; /*此變數用於判斷是否找到書目*/
char temp[20];
p=head;
printf("請輸入要修改的書名:");
scanf("%s",temp);
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n 請輸入圖書登陸卡號:");
fflush(stdin);
scanf("%s",p->loginnum);
printf("\n 請輸入圖書書名:");
fflush(stdin);
scanf("%s",p->bookname);
printf("\n 請輸入圖書作者名:");
fflush(stdin);
scanf("%s",p->author);
printf("\n 請輸入圖書出版社:");
fflush(stdin);
scanf("%s",p->publisher);
printf("\n 請輸入圖書出版時間:");
fflush(stdin);
scanf("%s",p->pbtime);
printf("\n 請輸入圖書分類號:");
fflush(stdin);
scanf("%s",p->classfy);
printf("\n 請輸入圖書價格:");
fflush(stdin);
scanf("%f",&p->price);
printf("\n");
panan=1;
}
}
if(panan==0)
{
printf("\n ━━━━ 沒有圖書記錄! ━━━━\n\n");
}
return;
}
/*刪除操作*/
void DeleteDoc(struct books_list * head)
{
struct books_list *s,*p; /*s為中間變數,p為遍歷時使用的指針*/
char temp[20];
int panan; /*此變數用於判斷是否找到了書目*/
panan=0;
p=s=head;
printf(" [請輸入您要刪除的書名]:");
scanf("%s",temp);
/*遍歷到尾結點*/
while(p!= NULL)
{
if(strcmp(p->bookname,temp)==0)
{
panan++;
break;
}
p=p->next;
}
if(panan==1)
{
for(;s->next!=p;) /*找到所需刪除卡號結點的上一個結點*/
{
s=s->next;
}
s->next=p->next; /*將後一節點地址賦值給前一節點的指針域*/
free(p);
printf("\n ━━━━ 刪除成功! ━━━━\n");
}
else /*未找到相應書目*/
{
printf(" 您輸入的書目不存在,請確認後輸入!\n");
}
return;
}
int main(void)
{
struct books_list * head;
char choice;
head=NULL;
for(;;) /*實現反復輸入選擇*/
{
printf(" ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");
printf(" ┃ ┃ socat 圖書管理系統 ┃ ┃\n");
printf(" ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃\n");
printf(" ┃ ●[1]圖書信息錄入 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[2]圖書信息瀏覽 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[3]圖書信息查詢 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[4]圖書信息修改 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[5]圖書信息刪除 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[6]退出系統 ┃\n");
printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");
printf(" 請選擇:");
fflush(stdin);
scanf("%c",&choice);
if(choice=='1')
{
if(head==NULL)
{
head=Create_Books_Doc();
}
InsertDoc(head);
}
else if(choice=='2')
{
Print_Book_Doc(head);
}
else if(choice=='3')
{
search_book(head);
}
else if(choice=='4')
{
info_change(head);
}
else if(choice=='5')
{
DeleteDoc(head);
}
else if(choice=='6')
{
printf("\n");
printf(" ━━━━━━━━ 感謝使用圖書管理系統 ━━━━━━━━\n");
break;
}
else
{
printf(" ━━━━ 輸入錯誤,請重新輸入!━━━━");
break;
}
}
return 0;
}
❹ 如果用C語言編寫一個圖書館管理系統,大概需要什麼樣的主函數求大體的編寫步驟
建議採用模塊化,自頂向低的編程思路
主函數只負責繪制菜單,根據用戶的選擇跳入對應功能。
然後各個功能有一個函數單獨編寫實現,調試,最後組裝完成。
如果你的系統需要實現添加、保存、修改、刪除、排序等功能,建議採用文件讀寫
可能會用到如下函數
strcmp(字元串比較函數,用於查找)
fprintf/fscanf/fopen/fclose(文件讀寫函數)
並且可能會用到結構體數組
如果您有需要,可以私信我,我可以幫您代寫。
謝謝
❺ 用c語言創建一個圖書管理信息
雖然沒有時間給你編寫具體程序,但是我可以告訴你演算法和數據結構:
定義一個如下的結構體:
struct book_manager
{
char num[30], bookname[100], author[30], classnum[40] ;
......
} ;
演算法:鏈表的查找、刪除、排序。
演算法必須採用動態的才行,因為你的圖書數目不是固定的,可能隨時需要刪除、還有增加、排序。
現在不是補分的問題,而是實際上從編寫到調試通過一個程序是需要花費非常多的時間的,調試程序比編寫程序更為復雜。
❻ 如何使用C語言編寫圖書管理系統
圖書管理系統是運行於Windows系統下的應用軟體,主要用於對圖書館中的圖書信息進行增、刪、改、查等操作,並且還可對使用該系統的用戶進行登錄名和密碼的管理等。系統給用戶提供了一個簡單的人機界面,使用戶可以根據提示輸入操作項,調用系統提供的管理功能。
所需功能類似於學生成績管理系統,界面可參考附錄C。用戶分為管理員和一般人員兩大類。
功能需求描述如下。
①用戶登錄:根據用戶輸入的用戶名和密碼判斷是否允許該用戶使用本系統,並且當用戶登錄後根據用戶許可權判斷用戶可以使用哪些功能。學生只有瀏覽等許可權而不能進行實質性改動。
②提供系統主控平台:系統主控平台也應根據用戶許可權不同而有所區別,只列出在用戶許可權范圍內的功能供用戶選擇。系統主控平台包括輸入功能選項、調用相應程序兩大需求。教師和學生對應的系統主控平台是不同的。所能進行的操作也不相同。
③創建圖書信息文件:用戶根據提示輸入圖書編號、圖書分類號、書名、作者姓名、出版社名、出版年月、定價、存庫數量和借閱和上架情況等等信息存儲在系統磁碟的文件中。以便進行管理、查找和備份。
④增加圖書信息:可在原有圖書信息文件的基礎上增加新的圖書信息記錄並繼續保存至磁碟,並且將增加後的文件存儲狀況顯示給用戶。
⑤刪除圖書信息:提示用戶輸入要進行刪除操作的圖書編號,如果在文件中有該信息存在,則將該書號所對應的記錄刪除。並選擇是否繼續進行刪除操作。
⑥修改圖書信息:提示用戶輸入要進行修改操作的書號,如果在文件中有該息存在,則將提示用戶輸入該書號對應的要修改的選項,結果存儲於文件。該部分需求也需要提示用戶選擇是否繼續進行修改操作。
⑦查詢圖書信息:提供按書號或書名等查詢。在該功能中,也需提示用戶是否需要繼續查再繼續查找,則返回主界面。
⑧一般用戶查詢個人的借閱情況並按日期進行排序:。
⑨管理員和一般用戶管理:管理員對用戶的管理也需要進行用戶的創建、增加、刪除、瀏覽。管理員創建的用戶存儲在名為yonghu的磁碟文件中,每當有用戶登錄系統時,會根據該文件中的用戶名和密碼進行核實判斷,用戶才能夠順利登錄。管理員還具有用戶的功能。增加的用戶及密碼、許可權等也被繼續存儲在yonghu文件中。當某些用一用該系統時,還可以進行刪除操作,並且管理員具有修改用戶許可權的功能,一般用戶和管理員對於系統的許可權是不一樣的。
❼ 求大神指導!C語言編程題:請設計一個圖書館管理系統,要求:(1)圖書的信
我可以幫你寫一個如果需要的話!
❽ C語言文件中怎麼對存入文件的數據設置索引,在使用的時候可以按照索引的類別來調用它
你可在寫入主體文件數據時,順便建立索引表寫入本文件或另一個文件,可以在讀主體數據的文件前,先讀取索性表的文件,然後根據索引表指向的位置定位文件流指針讀取主體數據文件。
❾ 求好心高手指導如何用c語言設計一個簡單的圖書館圖書管理系統
功能簡單啊。。就是排序。。添加。。
用一個結構體包含id(就是索引),名字。。然後設計他的添加功能,添加就是把結構體的信息存到文件中。。索引就是排序就完了
❿ C語言編程:圖書管理信息系統的設計與實現
這個工作本不難,自己編程工作量太大,且輸入基本數據也占時,最好將掃描一起納入。建議采購現有程序。