图书管理系统概述
一、数据需求
(1)出版社:出版社编号、出版社名称、出版社负责人、出版社简介,出版社下设出片分社,出版分社专注于某一个技术领域出版图书。
(2)图书:书名、书号、作者编号、出版日期、出版社编号、图书内容简介、图书价格。
(3)作者:作者编号、作者姓名、出生日期、性别、作者单位、作者简介。
1.2功能需求
1.2.1出版社管理
增加出版社信息
修改出版社信息
删除出版社信息
浏览出版社信息
1.2.2图书管理
增加图书信息
修改图书信息
浏览图书信息
删除图书信息
查询图书信息
1.2.3作者信息管理
增加作者信息
修改作者信息
删除作者信息
浏览作者信息
#include
#include
#include
using namespace std;
class press {
public:
int num;
char name[100];
char principal[100];//负责人
char introduce[100];
public:
void setValue(int n, char *na, char *pri, char *intr)
{
num = n;
strcpy(name, na);
strcpy(principal, pri);
strcpy(introduce, intr);
}
void setNum(int n)
{
num = n;
}
void setName(char *na)
{
strcpy(name, na);
}
void setPrincipal(char *pri)
{
strcpy(principal, pri);
}
void setIntroduce(char *intr)
{
strcpy(introduce, intr);
}
int getNum()
{
return num;
}
char *getName()
{
return name;
}
char *getPrincipal()
{
return principal;
}
char *getIntroduce()
{
return introduce;
}
};
class pressList {
private:
press preData[100];
int Num;
public:
pressList()
{
Num = 0;
}
void savePressDataToFile()
{
ofstream f2;
fstream file("PressData.dat", ios::in);
f2.open("PressData.dat", ios::binary);
if (!f2)
{
cout << "Save Data Error!" << endl;
return;
}
for (int i = 0; i < Num; i++)
{
f2.write((char*)&preData[i], sizeof(press));
}
f2.close();
}
void LoadPressDataFromFile()
{
ifstream f2;
f2.open("PressData.dat", ios::binary);
Num = 0;
if (!f2)
{
return;
}
while (1)
{
f2.read((char*)&preData[Num], sizeof(press));
if (f2.eof())
break;
Num++;
}
f2.close();
}
void addPress()
{
int num;//出版社编号
char name[100];//出版社名称
char principal[100];//出版社负责人
char introduce[100];//出版社简介
cout << "出版社编号:";
cin >> num;
cout << "出版社名称:";
cin >> name;
cout << "出版社负责人:";
cin >> principal;
cout << "出版社简介:";
cin >> introduce;
preData[Num].setValue(num, name, principal, introduce);
Num++;
}
void print()
{
for (int i = 0; i < Num; i++)
{
cout << "出版社编号:" << preData[i].getNum() << endl;
cout << "出版社名称:" << preData[i].getName() << endl;
cout << "出版社负责人:" << preData[i].getPrincipal() << endl;
cout << "出版社简介:" << preData[i].getIntroduce() << endl;
cout << "-----------------------------"<<endl;
}
}
char *getName(int num)
{
for (int i = 0; i < Num; i++)
if (preData[i].getNum() == num)
return preData[i].getName();
}
int findpresses() //查找出版社,这个函数用于出版社维护
{
int num;
cout << "请输入您要查找的出版社编号: ";
cin >> num;
for (int i = 0; i <= Num; i++)
{
if (preData[i].num == num )
{
cout << "出版社编号: " << preData[i].num << " 出版社名称: " << preData[i].name << " 出版社负责人: " << preData[i].principal << " 出版社简介: " << preData[i].introduce << endl;
return i;
}
}
return 1000;
}
int cz(int num) //查找
{
for (int i = 0; i < Num; i++)
{
if (preData[i].num == num )
{
cout << "出版社编号: " << preData[i].num << " 出版社名称: " << preData[i].name << " 出版社负责人: " << preData[i].principal << " 出版社简介: " << preData[i].introduce << endl;
return i;
}
}
return 1000;
}
void editpresses(int cur) //编辑出版社
{
if (cur == 1000)
{
cout << "没有这个出版社" << endl;
return;
}
cout << "1.出版社编号: " << preData[cur].num << endl;
cout << " 2.出版社名称: " << preData[cur].name << endl;
cout << " 3.出版社负责人: " << preData[cur].principal << endl;
cout << " 4.出版社简介: " << preData[cur].introduce << endl;
cout << "-----------------------------"<<endl;
cout << "请修改数据选项:";
int sel;
cin >> sel;
char a[15],b[100],c[100];
if (sel == 2)
{
cout<<"出版社名称:"<<endl;
cin >> a;
preData[cur].setName(a);
}
else if(sel == 3)
{
cout<<"出版社负责人:"<<endl;
cin >> b;
preData[cur].setPrincipal(b);
}
else if (sel == 4)
{
cout<<"出版社简介:"<<endl;
cin >> c;
preData[cur].setIntroduce(c);
}
return;
}
int delpresses(int cur) //删除图书
{
if (cur == 1000)
{
cout << "没有这个出版社,请重新输入" << endl;
return 0;
}
else if (cur != 1000)
{
for (int i = cur; i < Num; i++)
{
preData[i] = preData[i + 1];
}
Num--;
cout << "删除成功" << endl;
}
return 0;
}
};
class book {
public:
char bookname[100];
int booknum;//书号
int authornum;
char date[100];
int pressnum;//图书编号
char bookjianjie[100];//图书简介
float price;
int num;
void setValue( int num,char *nam, int au, char *da, int pre, char *ji, float pri)
{
strcpy(bookname, nam);
booknum = num;
authornum = au;
strcpy(date, da);
pressnum = pre;
strcpy(bookjianjie, ji);
price = pri;
}
void setBookname(char *nam)
{
strcpy(bookname, nam);
}
void setBooknum(int num)
{
booknum = num;
}
void setAuthornum(double au)
{
authornum = au;
}
void setDate(char *da)
{
strcpy(date, da);
}
void setPressnum(int pre)
{
pressnum = pre;
}
void setBookjianjie(char *ji)
{
strcpy(bookjianjie, ji);
}
void setPrice(float pri)
{
price = pri;
}
char *getBookname()
{
return bookname;
}
int getBooknum()
{
return booknum;
}
int getAuthornum()
{
return authornum;
}
char *getDate()
{
return date;
}
int getPressnum()
{
return pressnum;
}
char *getBookjianjie()
{
return bookjianjie;
}
float getPrice()
{
return price;
}
};
class bookList {
private:
book boData[100];
int Num;
public:
bookList()
{
Num = 0;
}
void saveBookDataToFile()
{
ofstream f2;
f2.open("bookData.dat", ios::binary);
if (!f2)
{
cout << "Save Date Error!" << endl;
return;
}
for (int i = 0; i < Num; i++)
{
f2.write((char*)&boData[i], sizeof(book));
}
f2.close();
}
void LoadBookDataFromFile()
{
ifstream f2;
f2.open("bookData.dat", ios::binary);
Num = 0;
if (!f2)
{
return;
}
while (1)
{
f2.read((char*)&boData[Num], sizeof(book));
if (f2.eof())
break;
Num++;
}
f2.close();
}
int judge(int n) //通过编号判断图书
{
for(int i=0;i<Num;i++)
if(n==boData[i].getBooknum())
return 1;
return 0;
}
void addBook()
{
char bookname[100];
int booknum;//书号
int authornum;
char date[100];
int pressnum;//图书编号
char bookjianjie[100];//图书简介
int price;
cout << "图书编号:";
cin >> booknum;
cout << "图书名称:";
cin >> bookname;
cout << "作者编号:";
cin >> authornum;
cout << "出版日期:";
cin >> date;
cout << "出版社编号:";
cin >> pressnum;
cout << "图书内容简介:";
cin >> bookjianjie;
cout << "图书价格:";
cin >> price;
boData[Num].setValue(booknum,bookname, authornum, date, pressnum, bookjianjie, price);
Num++;
}
void print()
{
for (int i = 0; i < Num; i++)
{
cout << "图书编号:" << boData[i].getBooknum() << endl;
cout << "图书名称:" << boData[i].getBookname() << endl;
cout << "作者编号:" << boData[i].getAuthornum() << endl;
cout << "出版日期:" << boData[i].getDate() << endl;
cout << "出版社编号:" << boData[i].getPressnum() << endl;
cout << "图书内容简介:" << boData[i].getBookjianjie() << endl;
cout << "图书价格:" << boData[i].getPrice() << endl;
cout << "-----------------------------"<<endl;
}
}
char *getBookname(int booknum)
{
for (int i = 0; i < Num; i++)
if (boData[i].getBooknum() == booknum)
return boData[i].getBookname();
}
int querybooks() //查询图书
{
int no;
cout<<"请输入查询的编号: ";
cin>>no;
for (int i = 0; i < Num; i++)
{
if (boData[i].pressnum == no)
{
cout<<"出版社编号: " << boData[i].pressnum << "图书编号: " << boData[i].booknum << "图书名称: " << boData[i].bookname << "作者编号: " << boData[i].authornum << "出版日期: " << boData[i].date<< "图书内容简介: " << boData[i].bookjianjie<< "图书价格: " << boData[i].price<< endl;
return i;
}
else if(boData[i].authornum == no )
{
cout<<"作者编号: " << boData[i].authornum << "图书编号: " << boData[i].booknum << "图书名称: " << boData[i].bookname << "出版日期: " << boData[i].date<<"出版社编号: " << boData[i].pressnum << "图书内容简介: " << boData[i].bookjianjie<< "图书价格: " << boData[i].price<< endl;
return i;
}
}
return 1000;
}
int findbooks() //查找图书,这个函数用于图书维护
{
int num;
cout << "请输入您要查找的图书编号: ";
cin >> num;
for (int i = 0; i < Num; i++)
{
if (boData[i].booknum == num )
{
cout << "图书编号: " << boData[i].booknum << " 图书名称: " << boData[i].bookname << " 作者编号: " << boData[i].authornum << " 出版日期: " << boData[i].date<< " 出版社编号: " << boData[i].pressnum << " 图书内容简介: " << boData[i].bookjianjie<< " 图书价格: " << boData[i].price<< endl;
return i;
}
}
return 1000;
}
void editbooks(int cur) //编辑图书
{
if (cur == 1000)
{
cout << "没有这本图书" << endl;
return;
}
cout << "1.图书编号: " << boData[cur].booknum << endl;
cout << " 2.图书名称: " << boData[cur].bookname << endl;
cout << " 3.作者编号: " << boData[cur].authornum << endl;
cout << " 4.出版日期: " << boData[cur].date << endl;
cout << " 5.出版社编号: " << boData[cur].pressnum << endl;
cout << " 6.图书内容简介: " << boData[cur].bookjianjie << endl;
cout << " 7.图书价格: " << boData[cur].price << endl;
cout << "请修改数据选项:";
cout << "-----------------------------"<<endl;
int sel;
cin >> sel;
char a[15],c[100],e[100];
int g,b,d;
float f;
if (sel == 2)
{
cout<<"图书名称:"<<endl;
cin >> a;
boData[cur].setBookname(a);
}
else if(sel == 3)
{
cout<<"作者编号:"<<endl;
cin >> b;
boData[cur].setAuthornum(b);
}
else if (sel == 4)
{
cout<<"出版日期:"<<endl;
cin >> c;
boData[cur].setDate(c);
}
else if(sel == 5)
{
cout<<"出版社编号:"<<endl;
cin >> d;
boData[cur].setPressnum(d);
}
else if(sel == 6)
{
cout<<"图书内容简介:"<<endl;
cin >> e;
boData[cur].setBookjianjie(e);
}
else if(sel == 7)
{
cout<<"图书价格:"<<endl;
cin >> f;
boData[cur].setPrice(f);
}
else if(sel == 1)
{
cout<<"图书编号:"<<endl;
cin >> g;
boData[cur].setBooknum(g);
}
return;
}
int delbooks() //删除图书
{
int cur;
cur = findbooks();
if (cur == 1000)
{
cout << "没有这本书,请重新输入" << endl;
return 0;
}
else if (cur != 1000)
{
for (int i = cur; i < Num; i++)
{
boData[i] = boData[i + 1];
}
Num--;
cout << "删除成功" << endl;
}
return 0;
}
//friend void panduan(book1 &);
};
class author {
public:
int num;
double aunum;
char auname[100];
char bridate[100];
char sex[100];
char danwei[100];
char jianjie[100];
public:
void setValue(double aun, char *name, char *bri, char *se, char *dan, char *jian)
{
aunum = aun;
strcpy(auname, name);
strcpy(bridate, bri);
strcpy(sex, se);
strcpy(danwei, dan);
strcpy(jianjie, jian);
}
void setAunum(double aun)
{
aunum=aun;
}
void setAuname(char *name)
{
strcpy(auname, name);
}
void setBridate(char *bri)
{
strcpy(bridate, bri);
}
void setSex(char *se)
{
strcpy(sex,se);
}
void setDanwei(char *dan)
{
strcpy(danwei, dan);
}
void setJianjie(char *jian)
{
strcpy(jianjie, jian);
}
double getAunum()
{
return aunum;
}
char *getAuname()
{
return auname;
}
char *getBridate()
{
return bridate;
}
char *getSex()
{
return sex;
}
char *getDanwei()
{
return danwei;
}
char *getJianjie()
{
return jianjie;
}
};
class authorList {
private:
author auData[100];
int Num;
public:
authorList()
{
Num = 0;
}
void saveAuthorDataToFile()
{
ofstream f2;
f2.open("authorData.dat", ios::binary);
if (!f2)
{
cout << "Save Date Error!" << endl;
return;
}
for (int i = 0; i < Num; i++)
{
f2.write((char*)&auData[i], sizeof(author));
}
f2.close();
}
void LoadAuthorDataFromFile()
{
ifstream f2;
f2.open("authorData.dat", ios::binary);
Num = 0;
if (!f2)
{
return;
}
while (1)
{
f2.read((char*)&auData[Num], sizeof(author));
if (f2.eof())
break;
Num++;
}
f2.close();
}
void addAuthor()
{
double aunum;
char auname[100];
char bridate[100];
char sex[100];
char danwei[100];
char jianjie[100];
cout << "作者编号:";
cin >> aunum;
cout << "作者姓名:";
cin >> auname;
cout << "出生日期:";
cin >> bridate;
cout << "性别:";
cin >> sex;
cout << "作者单位:";
cin >> danwei;
cout << "作者简介:";
cin >> jianjie;
auData[Num].setValue(aunum, auname, bridate, sex, danwei, jianjie);
Num++;
}
char *getAuname(int aunum)
{
for (int i = 0; i < Num; i++)
if (auData[i].getAunum() == aunum)
return auData[i].getAuname();
}
int findauthors() //查找作者,这个函数用于作者维护
{
int num;
cout << "请输入您要查找的作者编号: ";
cin >> num;
for (int i = 0; i <= Num; i++)
{
if (auData[i].aunum == num )
{
cout << "作者编号: " << auData[i].aunum << " 作者姓名: " <<auData[i].auname << " 出生日期: " << auData[i].bridate<< " 性别: " << auData[i].sex<< " 作者单位: " << auData[i].danwei<< " 作者简介: " << auData[i].jianjie << endl;
return i;
}
}
return 1000;
}
int cz(int num)
{
for (int i = 0; i <= Num; i++)
{
if (auData[i].aunum == num )
{
cout << "作者编号: " << auData[i].aunum << " 作者姓名: " <<auData[i].auname << " 出生日期: " << auData[i].bridate<< " 性别: " << auData[i].sex<< " 作者单位: " << auData[i].danwei<< " 作者简介: " << auData[i].jianjie << endl;
return i;
}
}
return 1000;
}
void editauthors(int cur) //编辑作者
{
if (cur == 1000)
{
cout << "没有这个作者" << endl;
return;
}
cout << " 1.作者编号: " << auData[cur].aunum << endl;
cout << " 2.作者姓名: " << auData[cur].auname << endl;
cout << " 3.出生日期: " << auData[cur].bridate << endl;
cout << " 4.性别: " << auData[cur].sex << endl;
cout << " 5.作者单位: " << auData[cur].danwei << endl;
cout << " 6.作者简介: " << auData[cur].jianjie << endl;
cout << "--------------------------"<<endl;
cout << "请修改数据选项:";
int sel;
cin >> sel;
char a[15],b[100],c[100],d[100],e[100];
if (sel == 2)
{
cout<<"作者姓名:"<<endl;
cin >> a;
auData[cur].setAuname(a);
}
else if(sel == 3)
{
cout<<"出生日期:"<<endl;
cin >> b;
auData[cur].setBridate(b);
}
else if (sel == 4)
{
cout<<"性别:"<<endl;
cin >> c;
auData[cur].setSex(c);
}
else if (sel == 5)
{
cout<<"作者单位:"<<endl;
cin >> d;
auData[cur].setDanwei(d);
}
else if (sel == 6)
{
cout<<"作者简介:"<<endl;
cin >> e;
auData[cur].setJianjie(e);
}
return;
}
int delauthors( int cur) //删除作者
{
cur = findauthors();
if (cur == 1000)
{
cout << "没有这个作者,请重新输入" << endl;
return 0;
}
else if (cur != 1000)
{
for (int i = cur; i < Num; i++)
{
auData[i] = auData[i + 1];
}
Num--;
cout << "删除成功" << endl;
}
return 0;
}
};
class process {
private:
pressList x1;
bookList y1;
authorList z1;
public:
void dispmenu1()
{
cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆" << endl;
cout << "☆ 图书管理系统 ☆" << endl;
cout << "☆ 1.出版社管理 ☆" << endl;
cout << "☆ 2.图书管理 ☆" << endl;
cout << "☆ 3.作者信息管理 ☆" << endl;
cout << "☆ 4.退出系统 ☆" << endl;
cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆" << endl;
}
void dispmenu2()
{
cout << "△☆☆☆☆☆☆☆☆☆☆△" << endl;
cout << " 出版社管理 " << endl;
cout << " 1.增加出版社 " << endl;
cout << " 2.修改出版社 " << endl;
cout << " 3.删除出版社 " << endl;
cout << " 4.浏览出版社 " << endl;
cout << " 5.返回 " << endl;
cout << "△☆☆☆☆☆☆☆☆☆☆△" << endl;
}
void dispmenu3()
{
cout << "△☆☆☆☆☆☆☆☆☆☆△" << endl;
cout << " 图书管理" << endl;
cout << " 1.增加图书" << endl;
cout << " 2.修改图书" << endl;
cout << " 3.浏览图书" << endl;
cout << " 4.删除图书" << endl;
cout << " 5.查询图书" << endl;
cout << " 6.返回" << endl;
cout << "△☆☆☆☆☆☆☆☆☆☆△" << endl;
}
void dispmenu4()
{
cout << "△☆☆☆☆☆☆☆☆☆☆△" << endl;
cout << " 作者管理 " << endl;
cout << " 1.增加作者 " << endl;
cout << " 2.修改作者 " << endl;
cout << " 3.删除作者 " << endl;
cout << " 4.返回 " << endl;
cout << "△☆☆☆☆☆☆☆☆☆☆△" << endl;
}
void maimenu()
{
int sel, sel1, sel2, sel3;
z1.LoadAuthorDataFromFile();
y1.LoadBookDataFromFile();
x1.LoadPressDataFromFile();
while (1)
{
dispmenu1();
cout << "请选择:";
cin >> sel;
if (sel == 1)
{
while (1)
{
dispmenu2();
cout << "请选择:";
cin >> sel1;
if (sel1 == 1) //增加
x1.addPress();
else if (sel1 == 4)//浏览
x1.print();
else if (sel1 == 2)//修改
{
int a;
a=x1.findpresses();
x1.editpresses(a);
}
else if (sel1 == 3)//删除
{
int i,a,b;
cout<<"请输入要删除的出版社编号:";cin>>i;
a=y1.judge(i);
if(a==0)
{
b=x1.cz(i);
x1.delpresses(b);
}
else if(a==1){cout<<"该出版社有图书,不能删除"<<endl;}
}
else if (sel1 >= 6 || sel1 == 0) cout << "输入有误,请重新输入!" << endl;
else if (sel1 == 5) break;
}
}
else if (sel == 2)
{
while (1)
{
dispmenu3();
cout << "请选择:";
cin >> sel2;
if (sel2 == 1)//增加
y1.addBook();
else if (sel2 == 3)//浏览
y1.print();
else if(sel2 == 2)//编辑
{
int c;
c=y1.findbooks();
y1.editbooks(c);
}
else if( sel2 == 4)//删除
y1.delbooks();
else if( sel2 == 5 )//查询
y1.querybooks();
else if (sel2 > 6 || sel2 == 0) cout << "输入有误,请重新输入!" << endl;
else if (sel2 == 6) break;
}
}
else if (sel == 3)
{
while (1)
{
dispmenu4();
cout << "请选择:";
cin >> sel3;
if (sel3 == 1)//增加
z1.addAuthor();
else if (sel3==2) //修改
{
int b;
b=z1.findauthors();
z1.editauthors(b);
}
else if (sel3==3)//删除
{
int i,a,b;
cout<<"请输入要删除的作者编号:";cin>>i;
a=y1.judge(i);
if(a==0)
{
b=z1.cz(i);
z1.delauthors(b);
}
else if(a==1){cout<<"该出版社有图书,不能删除"<<endl;}
}
else if (sel3 >= 5 || sel3 == 0) cout << "输入有误,请重新输入!" << endl;
else if (sel3 == 4) break;
}
}
else if (sel == 4)
{
cout<<"感谢使用!!!";break;}
else if (sel>= 5 || sel == 0) cout << "输入有误,请重新输入!" << endl;
}
x1.savePressDataToFile();
y1.saveBookDataToFile();
z1.saveAuthorDataToFile();
}
};
void main()
{
process p;
p.maimenu();
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)