媒体库管理系统

//这个是main.cpp中的代码
#include 
#include //作用是调用setw()函数
#include 
#include //使用exit()函数
#include //使用文件输入输出流
#include "article.h"
//#include "article.cpp"
#include "book.h"
#include "picture.h"
#include "disk.h"
#include "add.h"
#include "del.h"
using namespace std;
int main()
{
 int i;//用于菜单功能
 int j;//存放物品的编号
 string str;//存放物品的标题
 //以下9行程序为建立链表做准备工作
 struct book * bhead,*bcurrent;
 struct disk * dhead,*dcurrent;
 struct picture *phead,*pcurrent;
 bhead=bcurrent=NULL;
 dhead=dcurrent=NULL;
 phead=pcurrent=NULL;
 bhead=initbook();
 dhead=initdisk();
 phead=initpicture();
 while(1)
 {
  cout<>i;
  switch(i)
  {
  case 1:
   cout<<"********************************************************************************";
   cout<>i;
   if(i==1)
    bhead=addbook(bhead);
   else if(i==2)
    dhead=adddisk(dhead);
   else if(i==3)
    phead=addpicture(phead);
   else 
   {
    cout<<"输入有误,返回主目录!"<>i;
   if(i==1)
   {
    if(bhead!=NULL)
    {
     bcurrent=bhead;
     while(bcurrent!=NULL)
     {
      bcurrent->bk->showbook();
      bcurrent=bcurrent->next;
     }
    }
    else cout<<"无图书信息!"<dk->showdisk();
      dcurrent=dcurrent->next;
     }
    }
    else cout<<"无光盘信息!"<pe->showpicture();
      pcurrent=pcurrent->next;
     }
    }
    else cout<<"无图画信息!"<>i;
   if(i==1)
   {
    cout<<"请输入物品的标题:"<>str;
    pcurrent=phead;
    while(pcurrent!=NULL)
    {
     if(pcurrent->pe->searchtitle(str))
     {
      cout<pe->showpicture();
      break;
     }
     else
      pcurrent=pcurrent->next;
    }
    if(pcurrent==NULL)
    {
     cout<dk->searchtitle(str))
     {
      cout<dk->showdisk();
      break;
     }
     else
      dcurrent=dcurrent->next;
    }
    if(dcurrent==NULL)
    {
     cout<bk->searchtitle(str))
     {
      cout<bk->showbook();
      break;
     }
     else
      bcurrent=bcurrent->next;
    }
    if(bcurrent==NULL)
    {
     cout<>j;
     for(i=0;ipe->searchnumber(j))
        {
         pcurrent->pe->showpicture();
         break;
        }
        else
         pcurrent=pcurrent->next;
       }
       dcurrent=dhead;
       while(dcurrent!=NULL)
       {
        if(dcurrent->dk->searchnumber(j))
        {
         dcurrent->dk->showdisk();
         break;
        }
        else
         dcurrent=dcurrent->next;
       }
       bcurrent=bhead;
       while(bcurrent!=NULL)
       {
        if(bcurrent->bk->searchnumber(j))
        {
         bcurrent->bk->showbook();
         break;
        }
        else
         bcurrent=bcurrent->next;
       }
       break;
      } 
     }
     if(i>=sumnumber)
     {
      cout<<"无此编号!"<>str;
    if(str=="book")
    {
     bcurrent=bhead;
     if(bcurrent==NULL)
     {
      cout<bk->showbook();
      bcurrent=bcurrent->next;
     }
    }
    else if(str=="disk")
    {
     dcurrent=dhead;
     if(dcurrent==NULL)
     {
      cout<dk->showdisk();
      dcurrent=dcurrent->next;
     }
    }
    else if(str=="picture")
    {
     pcurrent=phead;
     if(pcurrent==NULL)
     {
      cout<pe->showpicture();
      pcurrent=pcurrent->next;
     }
    }
    else
    {
     cout<<"输入错误,返回主目录!"<>i;
   cout<>j;
   while(1)
   {
    if(sumnumber==0)cout<<"物品库为空!"<//作用是调用setw()函数
#include 
Article :: Article(int number,string title,string author)
{
 this->number=number;
 this->title=title;
 this->author=author;
}
void Article :: show()
{
 cout<<"********************************************************************************";
 cout<number==number)
  return true;
 else 
  return false;
}
bool Article :: searchtitle(string str)
{
 if(this->title==str)
  return true;
 else 
  return false;
}
//这个是book.cpp中的文件
#include "article.h"
#include //作用是调用setw()函数
#include 
#include "book.h"
Book :: Book(int number,string title,string author,string press,int page) :Article(number,title,author)
{
 this->press=press;
 this->page=page;
}
void Book :: showbook()
{
 show();
 cout<//作用是调用setw()函数
#include 
#include "disk.h"
Disk :: Disk(int number,string title,string author,int time,string date) : Article(number,title,author)
{
 this->time=time;
 this->date=date;
}
void Disk :: showdisk()
{
 show();
 cout<//作用是调用setw()函数
#include 
#include "picture.h"
Picture :: Picture(int number,string title,string author,int width,int length,string nationality) : Article(number,title,author)
{
 this->width=width;
 this->length=length;
 this->nationality=nationality;
}
void Picture :: showpicture()
{
 show();
 cout<
struct article
{
 Article * ae;
 struct article * next;
};
struct book
{
 Book * bk;
 struct book * next;
};
struct disk
{
 Disk * dk;
 struct disk * next;
};
struct picture
{
 Picture * pe;
 struct picture * next;
};
struct book * initbook();//完成初始化功能
struct disk * initdisk();
struct picture * initpicture();
struct book * addbook(struct book * phead);//完成添加功能
struct disk * adddisk(struct disk * disk);
struct picture * addpicture(struct picture * picture);
bool count(char str,int num);//完成统计功能
struct book * initbook()
{
 struct book * phead;
 phead=NULL;
 ifstream infile("书籍档案.txt");      
 string str;
 getline(infile,str);
 while(!infile.eof())
 {
  getline(infile,str);
  if(str.empty())break;
  istringstream istring(str);
  int num,page;
  num=page=0;
  string title,author,press;
  istring>>bcount>>num>>title>>author>>press>>page;
  struct book * ptail=phead;
  if(ptail!=NULL)
  {
   while(ptail->next!=NULL)
   ptail=ptail->next;
  }
  struct book * d=new struct book;
  Book * d1=new Book(num,title,author,press,page);
  d->bk=d1;
  d->next=NULL;
  if(phead==NULL)phead=d;
  else ptail->next=d;
  ptail=d;
  sumnumber++;
  bk[dcount-1]=num;
  sum[dcount-1]=num;
 }
 infile.close();
 return phead;
}
struct book * addbook(struct book * phead)
{
 ofstream outfile("书籍档案.txt",ios::app);//定义一个文件输出流的对象,用于向文件中输出数据
 if(!outfile)
 {
 cout<<"打开书籍档案失败!"<next!=NULL)
  ptail=ptail->next;
 }
 int i;
 int num;
 string title;
 string author;
 string press;
 int page;
 while(1)
 {
  cout<<"按1输入图书信息,按0返回主目录:"<>i;
  if(i==0)break;
  if(i==1)
  {
   cout<<"输入图书编号(整数),题目,作者,出版社,页数(整数):"<>num>>title>>author>>press>>page;
   if(count('b',num))
   {
    struct book * b=new struct book;
    Book * b1=new Book(num,title,author,press,page);
    b->bk=b1;
    b->next=NULL;
    if(phead==NULL)phead=b;
    else ptail->next=b;
    ptail=b;
    //在链表末尾添加节点后,将数据添加到文件中
    outfile<>dcount>>num>>title>>author>>time>>date;
  struct disk * ptail=phead;
  if(ptail!=NULL)
  {
   while(ptail->next!=NULL)
   ptail=ptail->next;
  }
  struct disk * d=new struct disk;
  Disk * d1=new Disk(num,title,author,time,date);
  d->dk=d1;
  d->next=NULL;
  if(phead==NULL)phead=d;
  else ptail->next=d;
  ptail=d;
  sumnumber++;
  dk[dcount-1]=num;
  sum[dcount-1]=num;
 }
 infile.close();
 return phead;
}
struct disk * adddisk(struct disk * phead)
{
 ofstream outfile("光盘档案.txt",ios::app);//定义一个文件输出流的对象,用于向文件中输出数据
 if(!outfile)
 {
 cout<<"打开光盘档案失败!"<next!=NULL)
  ptail=ptail->next;
 }
 int i;
 int num;
 string title;
 string author;
 int time;
 string date;
 while(1)
 {
  cout<<"按1输入光盘信息,按0返回主目录:"<>i;
  if(i==0)break;
  if(i==1)
  {
   cout<<"输入光盘编号(整数),题目,作者,播放时长(整数),出品年份:"<>num>>title>>author>>time>>date;
   if(count('d',num))
   {
    struct disk * d=new struct disk;
    Disk * d1=new Disk(num,title,author,time,date);
    d->dk=d1;
    d->next=NULL;
    if(phead==NULL)phead=d;
    else ptail->next=d;
    ptail=d;
    //在链表末尾添加节点后,将数据添加到文件中
    outfile<>pcount>>num>>title>>author>>width>>length>>nationality;
  struct picture * ptail=phead;
  if(ptail!=NULL)
  {
   while(ptail->next!=NULL)
   ptail=ptail->next;
  }
  struct picture * d=new struct picture;
  Picture * d1=new Picture(num,title,author,width,length,nationality);
  d->pe=d1;
  d->next=NULL;
  if(phead==NULL)phead=d;
  else ptail->next=d;
  ptail=d;
  sumnumber++;
  pe[pcount-1]=num;
  sum[pcount-1]=num;
 }
 infile.close();
 return phead;
}
struct picture * addpicture(struct picture * phead)
{
 ofstream outfile("图画档案.txt",ios::app);//定义一个文件输出流的对象,用于向文件中输出数据
 if(!outfile)
 {
 cout<<"打开图画档案失败!"<next!=NULL)
  ptail=ptail->next;
 }
 //outfile<<"记录"<<"  "<<"编号"<<"  "<<"题目"<<"  "<<"作者"<<"  "<<"宽"<<"  "<<"长"<<"  "<<"出品国籍"<>i;
  if(i==0)break;
  if(i==1)
  {
   cout<<"输入图画编号(整数),题目,作者,宽(整数),长(整数),出品国籍:"<>num>>title>>author>>width>>length>>nationality;
   if(count('p',num))
   {
    struct picture * p=new struct picture;
    Picture * p1=new Picture(num,title,author,width,length,nationality);
    p->pe=p1;
    p->next=NULL;
    if(phead==NULL)phead=p;
    else ptail->next=p;
    ptail=p;
    //在链表末尾添加节点后,将数据添加到文件中
    outfile<
using namespace std;
class Article
{
protected :
 int number;//此处为物品的编号,是物品不同与其他物品的唯一标识,为书,光盘,图画的共有属性
 string title;//此处为物品的名称,为书,光盘,图画的共有属性
 string author;//此处为物品的作者,为书,光盘,图画的共有属性
public :
 Article(int number,string title,string author);//构造函数,为属性初始化
 void show();//此函数的功能为显示
 bool searchnumber(int number);
 bool searchtitle(string str);
};
//book.h
#include 
using namespace std;
class Article;
class Book : public Article
{
private :
 string press;//为出版社的名字
 int page;//为书的页数
public :
 Book(int number,string title,string author,string press,int page);//构造函数,为属性初始化
 void showbook();//完成显示功能
};

//count.h
#define MAX 100//可以存放的物品的最大值
int bk[MAX];
int dk[MAX];
int pe[MAX];
int sum[3*MAX];
//定义全局变量,对书,光盘,图画进行统计,初始值为0;
int bcount=0;
int dcount=0;
int pcount=0;
int sumnumber=0;
bool count(char str,int num)
{
 int i;
 switch(str)
 {
 case 'b':
  for(i=0;i=sumnumber)
  {
   bcount++;
   sumnumber++;
   bk[i]=num;
   sum[i]=num;
  }
  break;
 case 'd':
  for(i=0;i=sumnumber)
  {
   dcount++;
   sumnumber++;
   dk[i]=num;
   sum[i]=num;
  }
  break;
 case 'p':
  for(i=0;i=pcount)
  {
   pcount++;
   sumnumber++;
   pe[i]=num;
   sum[i]=num;
  }
 }
 return true;
}
//del.h
struct article * del(struct article * ahead,int j)//j存放物品的编号
{
 int i;
 struct article * acurrent,* afront;
 acurrent=afront=ahead;
  for(i=0;iae->searchnumber(j))
     {
      if(ahead->ae->searchnumber(j))
      {
       ahead=ahead->next;
       delete(acurrent->ae);
       sumnumber--;
       i--;
       cout<<"删除成功!"<next=acurrent->next;
       delete(acurrent->ae);
       sumnumber--;
       i--;
       cout<<"删除成功!"<next;
     } 
    }
    break;
   } 
  }
  return ahead;
}
//disk.h
class Disk : public Article
{
protected :
 int time;//为光盘的播放时间
 string date;//为光盘的出品年份
public :
 Disk(int number,string title,string author,int time,string date);//构造函数,为属性初始化
 void showdisk();//完成显示功能
};
//picture.h
class Picture : public Article
{
protected :
 int width;//画的宽
 int length;//画的长
 string nationality;//出品国籍
public :
 Picture(int number,string title,string author,int width,int length,string nationality);//构造函数,为属性初始化
 void showpicture();//完成显示功能
};

你可能感兴趣的:(项目,c++)