图书管理系统(C++实践)


#include <iostream>
using namespace std;

class Addbook{
public:
 int add();
private:
 char a[2000];       //存放文件读进的东西
 int i;              //中间变量
 char bookname[100]; //书名
 char author[100];   //作者
 char stock[2];      //库存
 char num[3];        //编号
};
---------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;

class Check{
public:
 int check();
private:
 int i;         //中间变量
 char a[2000];  //存放文件读进的东西 
};
---------------------------------------------------------------------------------------------------------------------------------------
#ifndef _BOOK_H_
#define _BOOK_H_
#include <iostream>
using namespace std;
class Book{
public:
 void book();  
private:
 int i;         //中间变量
 char j[3];     //编号输入
 char *p;       //操作指针
 char a[2000];  //存放文件读进的东西
};
#endif
---------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
class Delbook{
public:
 int Del();
private:
 char a[2000];  //存放文件读进的东西
 int i;         //中间变量
 char *pa,*pb;       //操作指针
 char num[3];   //编号
 char b1[2000]; //中间变量
 char b2[2000]; //中间变量
};
---------------------------------------------------------------------------------------------------------------------------------------
#ifndef __DISPLAY_H_
#define __DISPLAY_H_
#include <iostream>
using namespace std;
class Display{
public:
 void DisplayZ();    //显示界面
private:
 int i;              //中间变量
};
#endif
---------------------------------------------------------------------------------------------------------------------------------------
#include "Addbook.h"
#include <fstream>
#include <string.h>
#include <windows.h>
int Addbook::add()
{
 system("CLS");
 fstream file4;
 file4.open("图书信息.txt",ios::in);
 for(i=0;!file4.eof();i++){
  a[i]=file4.get();
 }
 a[i-1]='\0';
 file4.close();
 cout<<a;
 printf("请输入编号(接着上面的编号排):");
 cin>>num;
 printf("请输入书名:");
 cin>>bookname;
 printf("请输入作者名:");
 cin>>author;
 printf("请输入库存数(个位数):");
 cin>>stock;
 strcat(a,num);
 strcat(a,"   ");
 strcat(a,bookname);
 strcat(a,"               ");
 strcat(a,author);
 strcat(a,"         ");
 strcat(a,stock);
 fstream file5;
 file5.open("图书信息.txt",ios::out);
 file5<<a<<endl;
 file5.close();
 printf("\n增加成功\n");
 getchar();
 getchar();
 return 0;
}
==================================================================================
#include "Book.h"
#include <fstream>
#include <windows.h>
#include <stdio.h>
#include <string.h>
void Book::book()
{
 system("CLS");
 fstream file2;
 file2.open("图书信息.txt",ios::in);
 for(i=0;!file2.eof();i++){
  a[i]=file2.get();
 }
 a[i-1]='\0';
 file2.close();
 cout<<a;
 while(1){
  printf("请输入你要借的书籍(编号,两位数):");
  cin>>j;
  p=strstr(a,j);
  if(p==NULL){
   printf("查找不到\n");
   continue;
  }
  else break;
 }
 p+=2;  //指到空格位
 while(1){
  if(*p>='0'&&*p<='9'){
   (*p)--;
   break;
  }
  p++;
 }
 printf("\n\n借书成功\n");
 fstream file3;
 file3.open("图书信息.txt",ios::out);
 file3<<a;
 file3.close();
 getchar();
 getchar();
}
==================================================================================
#include "Check.h"
#include <stdio.h>
#include <fstream>
#include <windows.h>
using namespace std;

int Check::check(){
 system("CLS");
 fstream file1;
 file1.open("图书信息.txt",ios::in);
 for(i=0;!file1.eof();i++){
  a[i]=file1.get();
 }
 a[i-1]='\0';
 file1.close();
 cout<<a;
 printf("\n\n按任意键返回");
 getchar();
 getchar();
 return 0;
}
==================================================================================
#include "Delbook.h"
#include <fstream>
#include <windows.h>
#include <stdio.h>
#include <string.h>
int Delbook::Del()
{
 system("CLS");
 fstream file6;
 file6.open("图书信息.txt",ios::in);
 for(i=0;!file6.eof();i++){
  a[i]=file6.get();
 }
 a[i-1]='\0';
 file6.close();
 cout<<a;
 printf("请输入你要删除的书籍(编号):");
 cin>>num;
 pb=strstr(a,num);
 for(pa=a,i=0;(pa+1)!=pb;pa++,i++){
  b1[i]=*pa;
 }
 b1[i]='\0';
 while(*pb!='\n'){
  pb++;
 }
 for(i=0;*pb!='\0';pb++,i++){
  b2[i]=*pb;
 }
 b2[i]='\0';
 strcpy(a,b1);
 strcat(a,b2);
 fstream file7;
 file7.open("图书信息.txt",ios::out);
 file7<<a;
 file7.close();
 printf("\n删除成功\n");
 getchar();
 getchar();
 return 0;
}
==================================================================================
#include "Display.h"
#include <stdio.h>

void Display::DisplayZ()
{
 printf("\n                            图书管理系统\n");
 printf("\n");
 printf("         -------------------- 1.查看 --------------------\n\n");
 printf("         -------------------- 2.订阅 --------------------\n\n");
 printf("         -------------------- 3.增加 --------------------\n\n");
 printf("         -------------------- 4.删除 --------------------\n\n\n\n");
 printf("按0退出");
}
==================================================================================
#include "Display.h"
#include "Book.h"
#include "Addbook.h"
#include "Check.h"
#include "Delbook.h"
#include <iostream>
#include <windows.h>
#include <stdio.h>
using namespace std;
Display a;
Check b;
Book c;
Addbook d;
Delbook e;
int main()
{
 while(1){
  system("CLS");
  a.DisplayZ();
  printf("请输入你要选择的功能:");
  int j;
  cin>>j;
  switch(j){
  case 1:b.check();break;
  case 2:c.book();break;
  case 3:d.add();break;
  case 4:e.Del();break;
  default:
   printf("输入有误");
   system("CLS");
   break;
  }
 }
 return 0;
}
==================================================================================


  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
/*****************************************************************************************/#include #include #include #include //输入/输出文件流类using namespace std;const int Maxr=100;//最多的读者const int Maxb=100;//最多的图书const int Maxbor=5;//每位读者最多借五本书//读者类,实现对读者的信息的描述class Reader { private: int tag; //删除标记 1:已删 0:未删 int no; //读者编号 char name[10]; //读者姓名 int borbook[Maxbor];//所借图书 public: Reader() {} char *getname() {return name;} //获取姓名 int gettag() {return tag;} //获取删除标记 int getno() {return no;} //获取读者编号 void setname(char na[]) //设置姓名 { strcpy(name,na); } void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删 void addreader(int n,char *na)//增加读者 { tag=0; no=n; strcpy(name,na); for(int i=0;i<Maxbor;i++) borbook[i]=0; } void borrowbook(int bookid)//借书操作 { for(int i=0;i<Maxbor;i++) { if (borbook[i]==0) { borbook[i]=bookid; return; } } } int retbook(int bookid)//还书操作 { for(int i=0;i<Maxbor;i++) { if(borbook[i]==bookid) { borbook[i]=0; return 1; } } return 0; } void disp()//读出读者信息 { cout << setw(5) << no <<setw(10) << name<<"借书编号:["; for(int i=0;i<Maxbor;i++) if(borbook[i]!=0) cout << borbook[i] << "|"; cout << "]"<<endl; }};//读者类库,实现建立读者的个人资料 class RDatabase{ private: int top; //读者记录指针 Reader read[Maxr];//读者记录public: RDatabase() //构造函数,将reader.txt读到read[]中 { Reader s; top=-1; fstream file("reader.txt",ios::in);//打开一个输入文件 while (1) { file.read((char *)&s,sizeof(s)); if (!file)break; top++; read[top]=s; } file.close(); //关闭 reader.txt } void clear()//删除所有读者信息 { top=-1; } int addreader(int n,char *na)//添加读者时先查找是否存在 { Reader *p=query(n); if (p==NULL) { top++; read[top].addreader(n,na); return 1; } return 0; } Reader *query(int readerid)//按编号查找 { for (int i=0;i<=top;i++) if (read[i].getno()==readerid && read[i].gettag()==0) { return &read[i]; } return NULL; } void disp() //输出所有读者信息 { for (int i=0;i<=top;i++) read[i].disp(); } void readerdata();//读者库维护 ~RDatabase() //析构函数,将read[]写到reader.txt文件中 { fstream file("reader.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值