图书管理系统

这是一个使用C++编写的图书管理系统,包括创建图书信息、保存到文件、打印、搜索、插入、删除和修改图书信息的功能。系统能读取并显示“library.txt”和“librarynew.txt”文件的内容。
摘要由CSDN通过智能技术生成
 
#include "iostream.h"
#include "string.h"
#include "stdlib.h"
#include "iomanip.h"
#include  "stdio.h"
#include "process.h"


typedef struct library
{
 int num;
 char name[20];
 char author[10];
 char kind[10];
 char pubunit[30];
 char pubtime[20];
 int price;
 struct library *next;
}LRY;


LRY *createlib()
{
 LRY *p,*headlib,*tail;
 int num,price;
 char name[20],kind[10],author[10];
 char pubunit[30],pubtime[20];
 int size=sizeof(LRY);
 
 headlib=tail=NULL;
 cout<<"输入图书信息:"<
 cin>>num>>name>>author>>kind>>pubunit>>pubtime>>price;
 while(num)
 {
  p=(LRY *)malloc(size);
  p->num=num;
  strcpy(p->name,name);
  strcpy(p->author,author);
  strcpy(p->kind,kind);
  strcpy(p->pubunit,pubunit);
  strcpy(p->pubtime,pubtime);
  p->price=price;
  if(headlib==NULL)
   headlib=p;
  else
   tail->next=p;
  tail=p;
  cin>>num>>name>>author>>kind>>pubunit>>pubtime>>price;
 }
 tail->next=NULL;
 return headlib;
}


void savefilelib(LRY *headlib)
{
 LRY *p;
 FILE *fp;
 if((fp=fopen("e:\\library.txt","w"))==NULL){
  cout<<"open fail!"<
  exit(0);
 }
 fprintf(fp,"登陆号     图书名     图书作者    图书分类号     出版单位     出版日期   价格\n");
 for(p=headlib;p;p=p->next)
  fprintf(fp,"%4d%15s%10s%11s%18s%12s%6d\n",p->num,p->name,p->author,p->kind,p->pubunit,p->pubtime,p->price);
 if(fclose(fp)){
  cout<<"close fail!"<
   exit(0);
 }
 cout<<"创建后的信息已放入E盘根目录的“library.txt”文件中"<
}


void savefilelibnew(LRY *headlib)
{
 LRY *p;
 FILE *fp;
 if((fp=fopen("e:\\librarynew.txt","w"))==NULL){
  cout<<"open fail!"<
  exit(0);
 }
 fprintf(fp,"登陆号     图书名     图书作者    图书分类号     出版单位     出版日期   价格\n");
 for(p=headlib;p;p=p->next)
  fprintf(fp,"%4d%15s%10s%11s%18s%12s%6d\n",p->num,p->name,p->author,p->kind,p->pubunit,p-
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值