#include<stdioh>
#include<stringh>
#include<conioh>
#include<stdlibh>
#include<windowsh>
#define LL sizeof(BOOK_TYPE)
int maininterface();
void infor_input();
void refer();
void refer_1();
void refer_2();
void modify();
void delete();
void findbook();
void findbook1();
void findbook2();
void devise();
void main()
{
int a=0;
do
{
a=maininterface();
switch(a)
{
case 1:system("CLS");infor_input();break;
case 2:system("CLS");refer();break;
case 3:system("CLS");modify();break;
case 4:system("CLS");delete();break;
case 5:exit(0);
default:system("CLS");printf("\n\n\n\n\t\t\t无此 *** 作,请按任意键返回:\n");getch();system("CLS");
}
}while(a!=6);
}
int maininterface()
{
int n;
printf("\n\n\n\t\t------------欢迎进入图书登记管理系统!-----------\n");
printf("\n\t\t\t\t1:<录入图书信息>\n");
printf("\n\t\t\t\t2:<查询信息>\n");
printf("\n\t\t\t\t3:<修改图书信息>\n");
printf("\n\t\t\t\t4:<删除图书信息>\n");
printf("\n\t\t\t\t5:<退出系统>\n");
printf("\n\t\t\t请输入1--5,其他输入非法!\n");
scanf("%d",&n);
return n;
}
typedef struct
{
int month;
int day;
int year;
}DATES;
DATES day;
typedef struct books
{
char bookname[50];
char ISBN[50];
char author[50];
char publisher[50];
float money;
DATES day;
int count;
struct books next;
}BOOK_TYPE;
BOOK_TYPE ts;
struct books head = NULL;
void infor_input()
{
FILE fp;
int n=0;
BOOK_TYPE ts;
printf("---------------图书资料基本信息录入--------------\n");
do
{
printf("请输入书名\n");
scanf("%s",tsbookname);
printf("请输入ISBN\n");
scanf("%s",tsISBN);
printf("请输入作者\n");
scanf("%s",tsauthor);
printf("请输入出版社\n");
scanf("%s",tspublisher);
printf("请输入定价\n");
scanf("%f",&tsmoney);
printf("请输入出版日期\n");
scanf("%d/%d/%d",&tsdaymonth,&tsdayday,&tsdayyear);
printf("请输入数量\n");
scanf("%d",&tscount);
printf("\n\t\t\t请选择(1:确定\t2:取消\t0:重新输入):");
scanf("%d",&n);
}while(n==0);
if(n==1)
{
if((fp=fopen("booktxt","a"))==NULL) / 若"booktxt"文件不存在,则以创建方式打开文件 /
{
fp=fopen("booktxt","w+");
}
fwrite(&ts,LL,1,fp); / 将输入的图书信息写入磁盘文件"booktxt" /
fclose(fp);
}
system("CLS");
printf("输入成功!\n");
printf("请选择(1:返回主界面\t2:输入另一本图书信息\t0:退出系统):\n");
scanf("%d",&n);
switch(n)
{
case 1:system("CLS");break;
case 2:system("CLS");infor_input();break;
case 0:break;
default:printf("无此 *** 作,按任意键返回\n");getch();system("CLS");break;
}
}
void refer()
{
int n;
printf("1:<根据ISBN号,找出图书信息>\n");
printf("2:<根据出版社名称,找出所有图书信息>\n");
printf("3:<根据书名,找出图书信息>\n");
printf("4:<统计书籍总数>\n");
printf("5:<统计书籍总金额和平均价格>\n");
printf("0:<返回>\n");
printf("请输入0--5,其他输入非法!\n");
scanf("%d",&n);
switch(n)
{
case 1:system("CLS");findbook();break;
case 2:system("CLS");findbook1();break;
case 3:system("CLS");findbook2();break;
case 4:system("CLS");refer_1();break;
case 5:system("CLS");refer_2();break;
case 0:system("CLS");break;
default:printf("无此 *** 作\n");break;
}
}
struct books read_1()
{
FILE fp;
struct books p1,p2,head;
fp=fopen("booktxt","r");
head=p1=(BOOK_TYPE )malloc(LL);
fread(p1,LL,1,fp);
while(feof(fp)==0)
{
p2=(BOOK_TYPE )malloc(LL);
fread(p2,LL,1,fp);
p1->next=p2;
p1=p2;
}
p1->next=NULL;
fclose(fp);
return head;
}
void refer_1()
{
struct books head,p,d;
struct books read_1();
int total=0;
head=read_1();
for(p=head;p->next!=NULL;d=p,p=p->next,free(d))
{
total=total+p->count;
}
printf("书籍总数:%d\n",total);
printf("按任意键返回");getch();system("CLS");
}
void refer_2()
{
int num=0;
struct books head,p1,p2;
struct books read_1();
float total=0,average=0;
head=read_1();
for(p1=head;p1->next!=NULL;p2=p1,p1=p1->next,free(p2))
{
num=num+p1->count;
total=total+p1->moneyp1->count;
}
average=total/num;
printf("书籍总金额:%2f\n",total);
printf("书籍平均价格:%2f\n",average);
printf("按任意键返回");getch();system("CLS");
}
void findbook()
{
FILE fp;
char ISBN[50];
int i;
fp=fopen("booktxt","r");
printf("请输入书的ISBN号\n");
scanf("%s",ISBN);
for(i=0;fread(&ts,LL,1,fp)!=0;i++)
{
if(strcmp(ISBN,tsISBN)==0)
printf("这本书的详细资料为:%s %s %s %s %f %d/%d/%d %d\n按任意键返回\n",tsbookname,tsISBN,tsauthor,tspublisher,tsmoney,tsdaymonth,tsdayday,tsdayyear,tscount);
}
printf("没有你所需要的书籍");
fclose(fp);
}
void findbook1()
{
FILE fp;
char publisher[50];
int i;
fp=fopen("booktxt","r");
printf("请输入书的publisher\n");
scanf("%s",publisher);
for(i=0;fread(&ts,LL,1,fp)!=0;i++)
{
if(strcmp(publisher,tspublisher)==0)
printf("这本书的详细资料为:%s %s %s %s %f %d/%d/%d %d\n按任意键返回\n",tsbookname,tsISBN,tsauthor,tspublisher,tsmoney,tsdaymonth,tsdayday,tsdayyear,tscount);
}
printf("没有你所需要的书籍");
fclose(fp);
}
void findbook2()
{
FILE fp;
char bookname[50];
int i;
fp=fopen("booktxt","r");
printf("请输入书的bookname\n");
scanf("%s",bookname);
for(i=0;fread(&ts,LL,1,fp)!=0;i++)
{
if(strcmp(bookname,tsbookname)==0)
printf("这本书的详细资料为:%s %s %s %s %f %d/%d/%d %d\n按任意键返回\n",tsbookname,tsISBN,tsauthor,tspublisher,tsmoney,tsdaymonth,tsdayday,tsdayyear,tscount);
}
printf("没有你所需要的书籍");
fclose(fp);
}
void delete()
{
struct books p1, p2;
char ISBN[50];
int e=0;
if(head == NULL)
{
printf("无书籍记录");
return;
}
printf("请输入您要删除的书籍的ISBN:\n");
scanf("%s",ISBN);
p1 = head;
while(ISBN != p1->ISBN && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(ISBN == p1->ISBN)
{
if(p1 == head)
head = p1->next;
else p2->next = p1->next;
free(p1);
e--;
}
else
printf("没有该书籍记录,请核对!\n");
}
void modify()
{
struct books p1, p2;
char ISBN[50];
if(head == NULL)
{
printf("无书籍记录!\n");
return;
}
printf("请输入您要修改的书籍的ISBN\n:");
scanf("%s",ISBN);
p1 = head;
while(ISBN != p1->ISBN && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if(ISBN == p1->ISBN)
devise(p1);
else
printf("没有该学生记录,请核对!\n");
}
void devise(struct books p)
{
int choice;
choice = -1;
do
{
printf("请选择您要修改的书籍的信息内容:\n");
printf("+----------------------+\n");
printf("| 书名 请按 1 |\n");
printf("| ISBN 请按 2 |\n");
printf("| 作者 请按 3 |\n");
printf("|出版社请按 4 |\n");
printf("| 定价 请按 5 |\n");
printf("| 出版日期 请按 6 |\n");
printf("| 数量 请按 7 |\n");
printf("| 取消 请按 0 |\n");
printf("+----------------------+\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch(choice)
{
case 0:
return;
case 1:
printf("请输入新书名 :");
scanf("%s", p->bookname);
break;
case 2:
printf("请输入新ISBN:");
scanf("%s", &p->ISBN);
break;
case 3:
printf("请输入新作者:");
scanf("%s", p->author);
break;
case 4:
printf("请输入新出版社:");
scanf("%s", p->publisher);
break;
case 5:
printf("请输入新定价:");
scanf("%d", p->money);
break;
case 6:
printf("请输入新出版日期 :");
scanf("%ld", &p->daymonth,dayday,dayyear);
break;
case 7:
printf("请输入新数量:");
scanf("%s", p->count);
break;
default:
printf("\n无效选项!");
break;
}
}
while(choice != 0);
}
///////////////////////////////////////////////////////////////////
// File :
// Author :
// Date :
// Modifier :
// Modify Date :
// Description :
///////////////////////////////////////////////////////////////////
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
using namespace std;
struct Book
{
int Number;// 书号
string Name;// 书名
int Price;// 价格
int Deal_Num;// 交易流水号
};
void Data_Input( vector< Book > &book )
{
int Num;
Book Temp;
string s;
stringstream sstr;
char File_Name[10]="Datatxt";
ifstream fp(File_Name);
if(!fp)
{
cerr<<" Can not Open"<<File_Name<<endl;
}
getline(fp,s);
sstr << s;
sstr >> s >> Num;
sclear();
for(unsigned i=0; i<Num; i++ )
{
sstrclear();
sclear();
getline(fp,s);
sstr << s;
sstr >> TempNumber >> TempName>>TempPrice>>TempDeal_Num;
bookpush_back( Temp );
}
fpclose();
cout<<"完成系统录入"<<endl;
}
void Data_Insert( vector< Book > &book )
{
Book Temp;
int Num;
cout<<"请输入您需要录入的信息总数:\n";
cin>>Num;
for(unsigned i=0; i<Num ;i++ )
{
cout<<"正在录入第"<<i+1<<"本书目的信息:"<<endl;
cout<<"请键入书号: ";
cin>>TempNumber;
cout<<"请键入书名: ";
cin>>TempName;
cout<<"请键入价格: ";
cin>>TempPrice;
cout<<"请键入交易流水号: ";
cin>>TempDeal_Num;
bookpush_back(Temp);
}
cout<<"共计"<<Num<<"本书的信息已经被录入"<<endl;
}
void Data_Delete( vector< Book > &book )
{
int Num;
vector< Book >::iterator Sear;
cout<<"请输入您要删除的书号: ";
cin>>Num;
for(Sear=bookbegin(); Sear!=bookend(); Sear++ )
{
if( (Sear)Number==Num )
{
bookerase( Sear );
cout<<"该书号被删除"<<endl;
Num=-1;
break;
}
}
if( Num!=-1 )
{
cout<<"输入书号有误!\n";
}
}
void Data_Display( vector< Book > &book )
{
cout<<"LIST\n";
for(unsigned i=0; i<booksize() ;i++ )
{
cout<<"书号: "<<book[i]Number<<endl;
cout<<"书名: "<<book[i]Name<<endl;
cout<<"价格: "<<book[i]Price<<endl;
cout<<"交易流水号: "<<book[i]Deal_Num<<endl;
cout<<endl;
}
cout<<"END\n";
}
void Data_Output( vector< Book > &book )
{
char File_Name[10]="Datatxt";
ofstream fp(File_Name);
if(!fp)
{
cerr<<" Can not Open "<< File_Name<< endl;
}
fp<<"图书总计(本): "<<booksize()<<endl;
for(unsigned i=0; i<booksize() ;i++ )
{
fp<<book[i]Number<<book[i]Name<<book[i]Price<<book[i]Deal_Num<<endl;
}
fpclose();
cout<<"书目已被保存到本地"<<endl;
}
int main()
{
int choice;
vector< Book > book;
while( choice!=5 )
{
cout<<""<<endl;
cout<<" 0--------------->读取数据 "<<endl;
cout<<" 1--------------->增加数据 "<<endl;
cout<<" 2--------------->删除数据 "<<endl;
cout<<" 3--------------->查看数据 "<<endl;
cout<<" 4--------------->保存记录 "<<endl;
cout<<" 5--------------->退出程序 "<<endl;
cout<<""<<endl;
cout<<"请键入您的选择:\t";
cin>>choice;
switch(choice)
{
case 0:Data_Input( book );break;
case 1:Data_Insert( book );break;
case 2:Data_Delete( book );break;
case 3:Data_Display( book );break;
case 4:Data_Output( book );break;
case 5:break;
default:break;
}
}
return 0;
}
以上就是关于图书馆管理系统全部的内容,包括:图书馆管理系统、编制程序,实现一个图书信息管理系统,功能包括录入、查询等。(c语言)、C语言图书管理系统等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)