此为C语言简单图书管理系统,实现增加图书、显示所有图书信息功能。问题所在请看最后详细描述。

此为C语言简单图书管理系统,实现增加图书、显示所有图书信息功能。问题所在请看最后详细描述。,第1张

new是关键字唉,怎么能当变量名,编译能过?我的不能.因为你那个new传的是止,第一次就把head指向了new,以后每次增加时修改了p2就修改了head,所以只是显示最后一个记录。TS *new1=(TS *)malloc(LEN)这句加在TS *Add(TS *head)函数第一句就OK了

#include <cstring>

#include <vector>

#include <fstream>

#include <map>

#include <iostream>

#include <algorithm>

using namespace std

class Library{

map<string,string>book_num

vector<string>people_num

map<string,string>::iterator ib

vector<string>::iterator ip

public:

Library(){

ib=book_num.begin()

ip=people_num.begin()

}

void set_book_num(string,string)

void delete_book_num(string)

void find_book_num(string)

void change_booke_num(string,string)

void add_people_num(string)

void lend_num(string,string)

void return_num(string,string)

void file_book(vector<string>::iterator)

void file_people(vector<string>::iterator)

}

void Library::set_book_num(string A,string B){

book_num.insert(A,B)

}

void Library::add_people_num(string A){

people_num.push_back(A)

}

void Library::find_book_num(string A){

map<string,string>::iterator result =find(book_num.begin(), book_num.end(), A)

if(result==book_num.end())

cout<<"图书馆中查无此书!"<<endl

else

cout<<"图书馆中此书信息如下:"<<endl

cout<<result->first<<":"<<result->second<<endl

}

void Library::delete_book_num(string A){

map<string,string>::iterator result =find(book_num.begin(), book_num.end(), A)

if(result==book_num.end())

cout<<"图书馆中查无此书!"<<endl

else

book_num.erase(result)

cout<<"已成功删除该书在图书馆中的记录"<<endl

}

void Library::change_booke_num(string A,string B){

map<string,string>::iterator result =find(book_num.begin(), book_num.end(), A)

if(result==book_num.end())

cout<<"图书馆中查无此书!"<<endl

else

result->second=B

}

void Library::file_people(vector<string>::iterator ifp){

ofstream file_p

file_p.open("/Users/apple/Documents/Library_p.txt",ios::out)

if(!file_p.is_open())

{

cerr<<"open file_people fail"<<endl

exit(-1)

}

file_p<<*ifp<<endl

file_p.close()

}

void Library::file_book(vector<string>::iterator ibp){

ofstream file_b

file_b.open("/Users/apple/Documents/Library_b.txt",ios::out)

if(!file_b.is_open())

{

cerr<<"open file_people fail"<<endl

exit(-1)

}

file_b<<*ibp<<endl

file_b.close()

}

#include#includeclassBook{//书籍基类protected:charTitle[40]//书名longCode//条码intType//0表示书,1表示杂志public:Book()Book(char*title,longcode)voidSetCode(longcode){Code=code}voidSetTitle(char*tl){strcpy(Title,tl)}voidSetType(booltype){Type=type}intGetType(){returnType}longGetCode(){returnCode}virtualvoidShow()//显示书的信息friendostream&operator>(istream&is,Book&)//重载提取运算符Book*Next//为创建每个读者所借书链表而定义指针}classItem:publicBook{//书的款目//charTitle[40]//书名charAuthor[20]//著者名charIndexCode[10]//分类号//longCode//条码public:Item()Item(char*author,char*title,char*index,intcode)Item(Item&)voidSetAuthor(char*)voidSetIndexCode(char*)virtualvoidShow()//显示书的信息friendostream&operator>(istream&is,Item&)//重载提取运算符public:}classMagazine:publicBook{//杂志类intVolumeenumLANG{CHINESE=1,ENGLISH}Lang//枚举变量,确定语言类别public:Magazine():Book(){Volume=0Lang=CHINESEType=1}Magazine(char*title,intvol,LANGlang,intcode)Magazine(Magazine&)voidSetVolume(intvol){Volume=vol}voidSetLang(intlang){Lang=(LANG)lang}virtualvoidShow()//显示杂志的信息friendostream&operator>(istream&is,Magazine&)//重载提取运算符}classReader{//读者信息类charName[20]//姓名charPosition[20]//职务intAge//年龄longCode//借书证号Book*items//所借书链表public:Reader()Reader(char*name,char*posi,intage,intcode)//Reader(Reader&)~Reader()longGetCode(){returnCode}voidSetName(char*)voidSetPosition(char*)voidSetAge(int)voidSetCode(long)voidAddBook(Item)//添加所借书voidAddBook(Magazine)//添加所借杂志voidDelBook(Bookit)//还书后减少所借书voidShowBooks()//显示所借书voidShow()//显示读者信息friendostream&operator>(istream&is,Reader&)//重载提取运算符public:intCounter//计数器,统计所借书数目}classManager{//管理员类charName[20]//姓名intAge//年龄intCode//工号friendclassLibrary//将图书馆类声明为友元public:Manager(){}Manager(char*,int,int)longGetCode(){returnCode}voidShow()friendostream&operator>(istream&is,Manager&)//重载提取运算符}classLoan{//借阅信息类intType//0表示书,1表示杂志Itemitem//借阅书Magazinemag//借阅杂志Readerreader//借阅者Managermanager//借书 *** 作员intCodefriendclassLibrary//将图书馆类声明为友元public:Loan(){}Loan(Loan&l)intGetCode(){returnCode}voidShow()friendostream&operator>(istream&is,Loan&)//重载提取运算符}、、、、、、、、、、、、、、、、、、、、、、、#include#includeclassReadertemplateclassDblListtemplateclassDblNode{public:TInfo//数据域DblNode*llink,*rlink//前驱(左链)、后继(右链)指针public:DblNode(Tdata)//一般结点DblNode()//头结点TGetInfo(){returnInfo}friendclassDblListfriendclassLibrary}templateclassDblList{DblNode*head,*currentpublic:DblList()~DblList()voidInsert(constT&data)DblNode*Remove(DblNode*p)voidPrint()intLength()//计算链表长度DblNode*Find(Tdata)//搜索数据与定值相同的结点DblNode*Find(intdata)//按某个关键字查找voidMakeEmpty()//清空链表voidShowList()//显示链表各结点friendistream&operator>>(istream&,DblList&)//重载输入流运算符friendostream&operator&dlist)//重载输出流运算符friendclassLibrary//其它 *** 作}templateDblNode::DblNode(){llink=rlink=NULL}templateDblNode::DblNode(Tdata){info=datallink=NULLrlink=NULL}templateDblList::DblList(){//建立表头结点head=newDblNode()head->rlink=head->llink=headcurrent=NULL}templateDblList::~DblList(){MakeEmpty()//清空链表deletehead}templatevoidDblList::MakeEmpty(){DblNode*tempPwhile(head->rlink!=head){tempP=head->rlinkhead->rlink=tempP->rlink//把头结点后的第一个节点从链中脱离tempP->rlink->llink=head//处理左指针deletetempP//删除(释放)脱离下来的结点}current=NULL//current指针恢复}templatevoidDblList::Insert(constT&data){//新节点在链尾current=newDblNodecurrent->Info=datacurrent->rlink=head//注意次序current->llink=head->llinkhead->llink->rlink=currenthead->llink=current//最后做}templateDblNode*DblList::Remove(DblNode*p){//删除结点current=head->rlinkwhile(current!=head&¤t!=p)current=current->rlinkif(current==head)current=NULLelse{//结点摘下p->llink->rlink=p->rlinkp->rlink->llink=p->llinkp->rlink=p->llink=NULL}returncurrent}templateDblNode*DblList::Find(Tdata){//按结点查找current=head->rlinkwhile(current!=head&¤t->Info!=data)current=current->rlinkif(current==head)current=NULLreturncurrent}templateDblNode*DblList::Find(intdata){//按数据值查找结点current=head->rlinkinttemp=current->Info.GetCode()while(current!=head&&temp!=data){current=current->rlinktemp=current->Info.GetCode()}if(current==head)current=NULLreturncurrent}templatevoidDblList::Print(){//输出链表current=head->rlinkwhile(current!=head){coutInforlink}coutintDblList::Length(){//取得链表长度intcount=0current=head->rlinkwhile(current!=head){count++current=current->rlink}returncount}templatevoidDblList::ShowList(){//输出链表各结点intcount=0current=head->rlinkwhile(current!=head){current->GetInfo().Show()current=current->rlink}return}templateistream&operator>>(istream&is,DblList&dlist){intlenTtt//定义局部变量读入一个结点is>>lenfor(inti=0i>ttdlist.Insert(tt)}returnis}templateostream&operator&dlist){DblNode*tempPintlen=dlist.Length()osrlinkwhile(tempP!=dlist.head){//循环输出链表各结点osInfotempP=tempP->rlink}returnos}#include"class.h"#include"dblist.h"#includeclassLibrary{//封装图书馆流通业务的类DblListitem//在馆图书链表DblListmag//在馆杂志链表DblListreader//读者链表DblListloan//借阅信息链表DblListmanager//管理员信息链表intitemNum//记录在馆图书数目intmagNum//记录在馆杂志数目intreaderNum//记录读者数目intloanNum//记录借阅信息数目intmanagerNum//记录管理员数目ofstreamitemFileOut//文件流对象,保存图书馆书籍数据ifstreamitemFileIn//文件流对象,读入图书馆书籍数据ofstreammagFileOut//文件流对象,保存图书馆杂志数据ifstreammagFileIn//文件流对象,读入图书馆杂志数据ofstreamreaderFileOut//文件流对象,保存图书馆读者数据ifstreamreaderFileIn//文件流对象,读入图书馆读者数据ofstreamloanFileOut//文件流对象,保存图书馆借阅信息数据ifstreamloanFileIn//文件流对象,读入图书馆借阅信息ofstreammanagerFileOut//文件流对象,保存图书馆管理员数据ifstreammanagerFileIn//文件流对象,读入图书馆管理员数据public:Library()//构造函数~Library()//析构函数voidRun()//图书馆类的运行函数voidCreateBibliotheca()//创建书目voidCreateReader()//创建读者库voidCreateManager()//创建管理员信息intShowMainMenu()//显示主菜单函数voidBorrow()//借书 *** 作voidReturn()//还书 *** 作voidRequire()//查询 *** 作voidSaveInfo()//保存图书馆信息voidOpenInfo()//读入图书馆信息}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11383291.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存