資源簡介
C++實現圖書管理系統,可以實現查找書籍,編輯書籍,刪除書籍,顯示書籍,新建書籍等功能
代碼片段和文件信息
#include
#include
#include
using?namespace?std;
struct?book//定義結構體變量?
{
int?number;//?書籍編號?
string?name;//書籍名稱?
string?author;//作者姓名?
int?codenum;//分類編號?
string?publisher;//出版單位?
string?publishtime;//出版時間
double?price;//價格?
struct?book?*next;
};
typedef?struct?book?BOOK;//定義sruct?book類型的變量BOOK?
class?Book//聲明一個類?
{
?public://公用部分?
Book();//公用成員函數?
void?firstpage();//首頁
void?show();//顯示所有書籍?
void?add();//添加書籍信息?
void?del();//刪除書籍信息?
void?alter();//修改書籍信息?
void?search();//查找書籍?
void?infile();//錄入信息?
void?outfile();//輸出文件流?
void?close();//退出系統?
private://私有部分?
BOOK?*first*last;//頭尾指針?
int?t;//計數變量?
};
Book::Book()//在類外定義Book函數?
{????
first?=last=?NULL;//初始化鏈表?
t?=?0;//計數變量?
}
void?Book::firstpage()//實現首頁?
{
cout?<“*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*“?< <“*?????????????????????????????????????????????????????*“?< <“*?????????????????????書籍管理系統????????????????????*“?< <“*?????????????????????????????????????????????????????*“?< <“*????1.顯示書籍信息??2.查找書籍信息??3.新建書籍信息???*“?< <“*?????????????????????????????????????????????????????*“?< <“*????4.刪除書籍信息??5.編輯書籍信息??6.退出系統???????*“?< <“*?????????????????????????????????????????????????????*“?< <“*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*?*“?< cout?<}
void?Book::add()//實現新建書籍信息?
{
struct?book?*point;//定義指針?
point?=?new?BOOK;//開辟存儲空間?
cout?<“請輸入書籍信息:?“?< cout?<“書籍編號:“;
cin?>>?point->number;
cout?<“書籍名稱:“;
cin?>>?point->name;
cout?<“作者姓名:“;
cin?>>?point->author;
cout?<“分類編號:“;
cin?>>?point->codenum;
cout?<“出版單位:“;
cin?>>?point->publisher;
cout?<“出版時間:“;
cin?>>?point->publishtime;
cout?<“價格:“;
cin?>>?point->price;
point->next?=?NULL;
if?(first?==?NULL)//鏈表操作?
{???
first=last?=point;
}
else
{
last->next?=?point;
last?=?point;
}
t++;//計數?
}
void?Book::del()//實現刪除書籍信息?
{
struct?book?*point?=?first?*prepoint?=?NULL;
int?c;
cout<<“請輸入待刪除書籍編號:?“;?
cin>>c;
//查找圖書并刪除該圖書信息?
while?(point?!=?NULL&&point->number?!=c)
{
prepoint?=?point;
point?=?point->next;
}
if?(point)
{
if?(!prepoint)
{
first?=?point->next;
}
else
{
if?(point->next?==?NULL)
last?=?prepoint;
prepoint->next?=?point->next;
}
delete?point;//釋放結點?
t--;//計數減少一?
cout< cout<“該書籍信息已刪除“?< }
else
{
cout<“未查詢到該書籍“?<
}
}
void?Book::alter()//實現修改書籍信息?
{
struct?book?*point=first;
double?b;
int?choose;
int?c;
string?ch;
cout<<“請輸入待修改書籍編號:?“;
cin>>c;
for?(int?i?=?1;?i?<=?t&&point?!=?NULL;?i++)
{
if?(point->number?==?c)
{
????????cout<<“書籍編號:?“<number<name<author<codenum<publisher<
- 上一篇:302_規格劃分矩形.cpp
- 下一篇:小型公司工資管理系統課程設計報告c++版
評論
共有 條評論