實現的是乙個小型圖書館的程式,功能包括增加新書,以及讀者借書和還書等。
**如下:
#include
#include
#include
#include
#include
using
namespace
std;
class patron;
class book
bool
operator==(const book &bk) const
private:
char *title;
patron *patron;
ostream &printbook(ostream &) const;
friend ostream &operator
<<(ostream &out, const book &bk)
friend
class checkoutbook;
friend
class patron;
friend
void includebook(); //友元函式
friend
void checkoutbook();
friend
void returnbook();
};class author
bool
operator==(const author & ar) const
private:
char *name;
list
books;
ostream &printauthor(ostream &) const;
friend ostream &operator
<<(ostream &out, const author &ar)
friend
void includebook();
friend
void checkoutbook();
friend
void returnbook();
friend
class checkoutbook;
friend
class patron;
};class checkoutbook
bool
operator==(const checkoutbook &bk) const
private:
list
::iterator author;
list
::iterator book;
friend
void checkoutbook();
friend
void returnbook();
friend
class patron;
};class patron
bool
operator==(const patron &pn) const
private:
char *name;
list
books;
ostream &printpatron(ostream &) const;
friend ostream &operator
<<(ostream &out, const patron &pn)
friend
void checkoutbook();
friend
void returnbook();
friend
class book;
};list
catalog['z' + 1]; //作家陣列
list
people['z' + 1]; //顧客陣列
//三個成員函式
ostream &author::printauthor(ostream &out) const
return out;
}ostream &book::printbook(ostream &out) const
ostream &patron::printpatron(ostream &out) const
else
out << "has no books.\n";
return out;
}//三個被呼叫的函式
template
//過載《的模板函式
ostream &operator
<<(ostream &out, const
list
&lst)
char *getstring(char *msg)
void status()
//友元函式
void includebook()
else
(*oldauthor).books.push_front(newbook); //查到了
}void checkoutbook()
while(true)
list
::iterator patronref;
patronref = find(people[patron.name[0]].begin(), people[patron.name[0]].end(), patron);
checkoutbook checkedoutbook(authorref, bookref);
if(patronref == people[patron.name[0]].end())
else
}void returnbook()
while(true)
while(true)
checkoutbook checkoutbook(authorref, bookref);
(*bookref).patron = 0;
(*patronref).books.remove(checkoutbook);
}int menu()
int main()
}return
0;}
有時間進行分析 c 鍊錶簡單實現
鍊錶 include using namespace std template struct node template class linklist public linklist node p new node head p p next null node push front const t...
c 簡單鍊錶實現
以下為linklist.件 ifndef linklist h included define linklist h included typedef structlnode lnode,plinklist classlinklist endif linklist h included 以下為lin...
C 實現鍊錶基礎功能
include include include include define ok 1 define error 0 define true 1 define false 0 using namespace std typedef int elmetype typedef int status 鍊錶...