#include <stdlib.h>
#include "windows.h"
#include "string.h"
#define S_MAX 50
int user_count = 0 //用户信息的总数
int book_count = 0
char ini_path[100] = { "\0" } //数据文件的绝对路径
char user_path[100] = { "\0" } //用户数据文件的绝对路径
char book_path[100] = { "\0" }
int book_pos = 0 //book数组的计数
int user_pos = 0
struct user_data
{
char name[10]
char book_name[50]
}user[S_MAX]
struct book_data
{
char no[10]
char name[50]
char author[30]
char money[10]
char in_or_out[10]
char user_name[10]
}book[S_MAX]
void read_file() //从文件读取数据
{
user_pos = 0
int i
for (i = 0 i<S_MAX i++)
{
memset(user[i].name, '\0', 10)
memset(user[i].book_name, '\0', 50)
memset(book[i].no, '\0', 10)
memset(book[i].name, '\0', 50)
memset(book[i].author, '\0', 30)
memset(book[i].money, '\0', 10)
memset(book[i].in_or_out, '\0', 10)
memset(book[i].user_name, '\0', 10)
}
user_count = GetPrivateProfileInt("USER", "user_count", 0, user_path)
book_count = GetPrivateProfileInt("book", "book_count", 0, book_path)
for (i = 0 i<user_count i++)
{
char t[5] = { "\0" }
sprintf(t, "%d", i + 1)
GetPrivateProfileString(t, "name", "", user[i].name, 10, user_path)
GetPrivateProfileString(t, "book_name", "", user[i].book_name, 50, user_path)
user_pos++
}
for (i = 0 i<book_count i++)
{
char t[5] = { "\0" }
sprintf(t, "%d", i + 1)
GetPrivateProfileString(t, "no", "", book[i].no, 10, book_path)
GetPrivateProfileString(t, "name", "", book[i].name, 50, book_path)
GetPrivateProfileString(t, "author", "", book[i].author, 30, book_path)
GetPrivateProfileString(t, "money", "", book[i].money, 10, book_path)
GetPrivateProfileString(t, "in_or_out", "", book[i].in_or_out, 10, book_path)
GetPrivateProfileString(t, "user_name", "", book[i].user_name, 10, book_path)
book_pos++
}
}
void write_file()
{
int i
for (i = 0 i<user_count i++)
{
char t[5] = { "\0" }
sprintf(t, "%d", i + 1)
WritePrivateProfileString(t, "name", NULL, user_path)
WritePrivateProfileString(t, "book_name", NULL, user_path)
WritePrivateProfileString(t, "no", NULL, book_path)
WritePrivateProfileString(t, "name", NULL, book_path)
WritePrivateProfileString(t, "author", NULL, book_path)
WritePrivateProfileString(t, "money", NULL, book_path)
WritePrivateProfileString(t, "in_or_out", NULL, book_path)
WritePrivateProfileString(t, "user_name", NULL, book_path)
}
char temp[5] = { "\0" }
int temp_count = 0
for (i = 0 i<user_pos i++)
{
if (strcmp(user[i].name, "") == 0)
{
continue
}
char t[5] = { "\0" }
sprintf(t, "%d", i + 1)
WritePrivateProfileString(t, "name", user[i].name, user_path)
WritePrivateProfileString(t, "book_name", user[i].book_name, user_path)
temp_count++
}
sprintf(temp, "%d", temp_count)
WritePrivateProfileString("USER", "user_count", temp, user_path)
temp_count = 0
for (i = 0 i<book_pos i++)
{
if (strcmp(book[i].no, "") == 0)
{
continue
}
char t[5] = { "\0" }
sprintf(t, "%d", i + 1)
WritePrivateProfileString(t, "no", book[i].no, book_path)
WritePrivateProfileString(t, "name", book[i].name, book_path)
WritePrivateProfileString(t, "author", book[i].author, book_path)
WritePrivateProfileString(t, "money", book[i].money, book_path)
WritePrivateProfileString(t, "in_or_out", book[i].in_or_out, book_path)
WritePrivateProfileString(t, "user_name", book[i].user_name, book_path)
temp_count++
}
sprintf(temp, "%d", temp_count)
WritePrivateProfileString("BOOK", "book_count", temp, book_path)
}
void search_user_name() //按借书人姓名查询
{
system("cls")
char search_key[10] = { "\0" }
scanf("%s", search_key)
int i
int s[10] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }
int s_i = 0
int find = 0
for (i = 0 i<book_pos i++)
{
if (strcmp(book[i].user_name, search_key) == 0)
{
find = 1
s[s_i] = i
s_i++
printf("\n编 号: %s", book[i].no)
printf("\n名 称: %s", book[i].name)
printf("\n作 者: %s", book[i].author)
printf("\n金 额: %s", book[i].money)
printf("\n状 态: %s", book[i].in_or_out)
printf("\n借 书 人: %s\n", book[i].user_name)
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!")
}
else
{
for (i = 0 i<s_i i++)
{
printf("\n\n第%d本书: %s", i + 1, book[i].name)
}
printf("\n\n共%d本", i)
}
fflush(stdin)
getchar()
}
void search_book_author() //按图书作者查询
{
system("cls")
char search_key[50] = { "\0" }
printf("请输入要查询图书的作者:")
scanf("%s", search_key)
int i
int find = 0
for (i = 0 i<book_pos i++)
{
if (strcmp(book[i].author, search_key) == 0)
{
find = 1
printf("\n编 号: %s", book[i].no)
printf("\n名 称: %s", book[i].name)
printf("\n作 者: %s", book[i].author)
printf("\n金 额: %s", book[i].money)
printf("\n状 态: %s", book[i].in_or_out)
printf("\n借 书 人: %s\n", book[i].user_name)
break
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!")
}
fflush(stdin)
getchar()
}
void search_book_name() //按图书名称查询
{
system("cls")
char search_key[50] = { "\0" }
printf("请输入要查询图书的名称:")
scanf("%s", search_key)
int i
int find = 0
for (i = 0 i<book_pos i++)
{
if (strcmp(book[i].name, search_key) == 0)
{
find = 1
printf("\n编 号: %s", book[i].no)
printf("\n名 称: %s", book[i].name)
printf("\n作 者: %s", book[i].author)
printf("\n金 额: %s", book[i].money)
printf("\n状 态: %s", book[i].in_or_out)
printf("\n借 书 人: %s\n", book[i].user_name)
break
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!")
}
fflush(stdin)
getchar()
}
void search_book_no() //按图书编号查询
{
system("cls")
char search_key[10] = { "\0" }
printf("请输入要查询图书的编号:")
scanf("%s", search_key)
int i
int find = 0
for (i = 0 i<book_pos i++)
{
if (strcmp(book[i].no, search_key) == 0)
{
find = 1
printf("\n编 号: %s", book[i].no)
printf("\n名 称: %s", book[i].name)
printf("\n作 者: %s", book[i].author)
printf("\n金 额: %s", book[i].money)
printf("\n状 态: %s", book[i].in_or_out)
printf("\n借 书 人: %s\n", book[i].user_name)
break
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!")
}
fflush(stdin)
getchar()
}
void search_all_book() //查询所有图书
{
system("cls")
if (book_pos == 0)
{
printf("真TM穷,一本书都没有")
}
else
{
int i
printf("共有%d本书\n", book_pos)
for (i = 0 i<book_pos i++)
{
printf("\n编号:%s 名称:%s 作者:%s 金额:%s 状态:%s", book[i].no, book[i].name, book[i].author, book[i].money, book[i].in_or_out)
if (strcmp(book[i].in_or_out, "out") == 0)
{
printf(" 借书人:%s", book[i].user_name)
}
}
}
fflush(stdin)
getchar()
}
void search_all_user() //查询所有用户
{
system("cls")
if (user_pos == 0)
{
printf("要倒闭了?一个人都没有!")
}
else
{
int i
printf("共有%d个用户\n", user_pos)
for (i = 0 i<user_pos i++)
{
printf("\n用户名称: %s 借书名称: ", user[i].name)
if (strcmp(user[i].book_name, "") != 0)
{
printf("%s", user[i].book_name)
}
else
{
printf("未借书")
}
}
}
fflush(stdin)
getchar()
}
void No7() //查询
{
int f = 1
int sel
while (f)
{
system("cls")
printf(" *********************************\n")
printf(" * *\n")
printf(" * 图书管理系统--查询 *\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(" * 0.返回主菜单 *\n")
printf(" * *\n")
printf(" *********************************\n")
printf("请选择:(1,2,3,4,5,6,0) ")
fflush(stdin)
scanf("%d", &sel)
getchar()
switch (sel)
{
case 1:
search_book_no()
break
case 2:
search_book_name()
break
case 3:
search_book_author()
break
case 4:
search_user_name()
break
case 5:
search_all_book()
break
case 6:
search_all_user()
break
case 0:
f = 0
break
default:
break
}
}
}
void No6() //用户信息删除
{
system("cls")
char del_key[10] = { "\0" }
printf("请输入要删除的用户名称:")
scanf("%s", del_key)
int i, del_pos
int find = 0
for (i = 0 i<user_pos i++)
{
if (strcmp(user[i].name, del_key) == 0)
{
find = 1
printf("\n姓 名: %s", user[i].name)
if (strlen(user[i].book_name)>0)
{
printf("\n所借书籍: %s", user[i].book_name)
}
del_pos = i
break
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!")
fflush(stdin)
getchar()
return
}
while (1)
{
fflush(stdin)
printf("\n\n确认要删除该记录吗?(y/n):")
char t
scanf("%c", &t)
if (t == 'y' || t == 'Y')
{
if (strlen(user[del_pos].book_name)>0)
{
printf("\n\n该用户尚有书籍未归还,不能删除!")
fflush(stdin)
getchar()
return
}
strcpy(user[del_pos].name, "")
strcpy(user[del_pos].book_name, "")
write_file()
printf("\n\n删除成功!")
read_file()
fflush(stdin)
getchar()
break
}
else if (t == 'N' || t == 'n')
{
printf("\n\n你选择了不删除,按任意键返回!")
fflush(stdin)
getchar()
break
}
else
{
continue
}
}
}
//请在回复后发余下部分
通过测试!#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#define MAX 100
struct Student
{
int num/*登录号*/
char name[100]/*书名*/
char author[100]/*作者名*/
char fn[100]/*分类号*/
char place[100]/*出版单位*/
char day[100]/*出版时间*/
float money/*价格*/
}stu[MAX]
main()/*主函数*/
{
void Input()/*输入*/
void Display()/*输出*/
void Find()/*查找*/
void Modify()/*删除*/
void Change()/*修改*/
int n
for()
{
printf("\n")
printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n")
printf("※ ※\n")
printf("※ 欢迎来到图书信息管理系统 ※\n")
printf("※ ※\n")
printf("※ ※\n")
printf("※ 主菜单 ※\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("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n")
printf("请输入选择项(1-6):")
scanf("%d",&n)
printf("\n\n\n\n")
if(n>0&&n<7)
{
switch(n)
{
case 1:Input()break
case 2:Display()break
case 3:Find()break
case 4:Modify()break
case 5:Change()break
case 6:printf("※※※※※※※※※※※※※※※※※※※※※※※※\n")
printf("※※\n")
printf("※ 谢谢使用! ※\n")
printf("※再见! ※\n")
printf("※※\n")
printf("※※※※※※※※※※※※※※※※※※※※※※※※\n")
exit(0)
}
}
else
{
printf("※※※※※※※※※※※※※※※※※※※※※※※※\n")
printf("※※\n")
printf("※ 输入错误! ※\n")
printf("※ 请退出! ※\n")
printf("※※\n")
printf("※※※※※※※※※※※※※※※※※※※※※※※※\n")
break
}
}
}
void Find()/*查找*/
{
FILE *fp
int i
int choose,t
char ans[100]
do
{
printf("1.按书名查找\n")
printf("2.按作者名查找\n")
printf("返回主菜单(其他数字)\n")
scanf("%d",&choose)
if(choose==1)
{
printf("输入所查书名:\n")
scanf("%s",ans)
t=-1
if(choose==1)
{
for(i=0i<MAXi++) if(strcmp(ans,stu[i].name)==0)
{
t=i
fp=fopen("student","rb")
for(i=0fread(&stu[i],sizeof(struct Student),1,fp)==1i++)
printf("%d %s %s %s %s %s %f\n",stu[t].num,stu[t].name,stu[t].author,stu[t].fn,stu[t].place,stu[t].day,stu[t].money)
}
}
if(t==-1) printf("不存在该信息\n")
}
else if(choose==2)
{
printf("输入所查作者名:\n")
scanf("%s",ans)
t=-1
if(choose==2)
{
for(i=0i<MAXi++)
if(strcmp(ans,stu[i].author)==0)
{ t=i
fp=fopen("student","rb")
for(i=0fread(&stu[i],sizeof(struct Student),1,fp)==1i++)
printf("%d %s %s %s %s %s %f\n",stu[t].num,stu[t].name,stu[t].author,stu[t].fn,stu[t].place,stu[t].day,stu[t].money)
}
}
if(t==-1) printf("不存在该信息\n")
}
else return
}while(1)
}
void Display()/*输出*/
{
FILE *fp
int i
fp=fopen("student","rb")
printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n")
printf(" 图书列表\n")
printf("-----------------------------------------------------------\n")
printf("登录号书名作者名 分类号 出版单位 出版时间 价格\n")
printf("-----------------------------------------------------------\n")
for(i=0fread(&stu[i],sizeof(struct Student),1,fp)==1i++)
{
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money)
}
fclose(fp)
}
void Input()/*输入*/
{
FILE *fp
int n
fp=fopen("student","wb")
for(n=0n<MAXn++)
{
printf("n=%d 输入序号n(当输入n=-1时,返回),n=",n++)
scanf("%d",&n)
if(n==-1)
{
fclose(fp)
return
}
else
{
printf("请输入登录号 书名 作者名 分类号 出版单位 出版时间 价格\n")
scanf("%d%s%s%s%s%s%f",&stu[n].num,stu[n].name,stu[n].author,stu[n].fn,stu[n].place,stu[n].day,&stu[n].money)
fwrite(&stu[n],sizeof(struct Student),1,fp)
}
}
fclose(fp)
}
void Modify()/*删除*/
{
FILE *fp
int i,flag,n,s,j
fp=fopen("student","rb+")
rewind(fp)
printf(" 图书列表\n")
printf("-----------------------------------------------------------\n")
printf("登录号书名作者名 分类号 出版单位 出版时间 价格\n")
printf("-----------------------------------------------------------\n")
for(i=0fread(&stu[i],sizeof(struct Student),1,fp)==1i++)
{
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money)
printf("\n")
}
n=i
printf("输入待删除图书号:\n")
scanf("%d",&s)
for(i=0,flag=1flag&&i<ni++)
{
if(s==stu[i].num)
{
for(j=ij<n-1j++)
{
stu[j].num=stu[j+1].num
strcpy(stu[j].name,stu[j+1].name)
strcpy(stu[j].author,stu[j+1].author)
strcpy(stu[j].fn,stu[j+1].fn)
strcpy(stu[j].place,stu[j+1].place)
strcpy(stu[j].day,stu[j+1].day)
stu[j].money=stu[j+1].money
}
flag=0
}
}
if(!flag)
n=n-1
else
printf("没有此号\n")
fp=fopen("student","wb")
for(i=0i<ni++)
fwrite(&stu[i],sizeof(struct Student),1,fp)
fclose(fp)
fp=fopen("student","r")
printf(" 图书列表\n")
printf("-----------------------------------------------------------\n")
printf("登录号书名作者名 分类号 出版单位 出版时间 价格\n")
printf("-----------------------------------------------------------\n")
for(i=0i<ni++)
{
fread(&stu[i],sizeof(struct Student),1,fp)
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money)
printf("\n")
}
fclose(fp)
}
void Change()/*修改*/
{
FILE *fp
int i,num,n
int flag=0
printf("请输入要修改的图书号:")
scanf("%d",&num)
for(i=0i<=MAXi++)
if(stu[i].num==num)
{
printf(" 图书列表\n")
printf("-----------------------------------------------------------\n")
printf("登录号书名作者名 分类号 出版单位 出版时间 价格\n")
printf("-----------------------------------------------------------\n")
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money)
printf("-----------------------------------------------------------\n\n")
n=i
flag=1
break
}
if(flag==0)
{
printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n")
printf("输入错误!\n")
printf(" 请返回!\n")
printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n")
return
}
printf("\n\n\n")
fp=fopen("student","rb+")
fseek(fp,n*sizeof(struct Student),0)
printf("登录号书名作者名 分类号 出版单位 出版时间 价格\n")
scanf("%d%s%s%s%s%s%f",&stu[n].num,stu[n].name,stu[n].author,stu[n].fn,stu[n].place,stu[n].day,&stu[n].money)
fwrite(&stu[i],sizeof(struct Student),1,fp)
fclose(fp)
fp=fopen("student","rb")
printf(" 图书列表\n")
printf("-----------------------------------------------------------\n")
printf("登录号书名作者名 分类号 出版单位 出版时间 价格\n")
printf("-----------------------------------------------------------\n")
for(i=0fread(&stu[i],sizeof(struct Student),1,fp)==1i++)
{
printf("%6d %8s %8s %8s %8s %8s %8.2f\n",stu[i].num,stu[i].name,stu[i].author,stu[i].fn,stu[i].place,stu[i].day,stu[i].money)
}
printf("-----------------------------------------------------------\n\n")
fclose(fp)
}
没有分啊给个思路
你需要一个小型的数据库来支撑你的需求,access就可以了。你用VC++或者C++
Builder来开发界面,建立一个小数据库,里面放一张图书的数据表就可以了,字段包括图书的编号(这对每一本图书来说都是唯一的),图书名称,图书的作者啊等等其他信息。添加图书其实就是对数据库的insert操作,只是在insert之前你要先查询下图书名称是否已经包含在数据库里。查询图书就是简单的对数据库select操作。修改图书就是对数据库进行Update操作,删除就是Delete了,只要你熟悉SQL,理解这些就很简单。最后的access文件就是你的图书信息表,你可以将它拷贝到任何支持office的电脑上打开查看。