❶ 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语言编程:图书管理信息系统的设计与实现
这个工作本不难,自己编程工作量太大,且输入基本数据也占时,最好将扫描一起纳入。建议采购现有程序。