資源簡(jiǎn)介
這個(gè)是C++之父的著作 The C++ PL的特別版的課后習(xí)題答案,希望對(duì)大家有用,

代碼片段和文件信息
/*?Code?for?exercise?10.12.
?|?
?|?“C++?Solutions--Companion?to?The?C++?Programming?Language?Third?Edition“
?|?by?David?Vandevoorde;?Addison-Wesley?1998;?ISBN?0-201-30965-3.
?|
?|?Permission?to?use?copy?modify?distribute?and?sell?this?software
?|?and?its?documentation?for?any?purpose?is?hereby?granted?without?fee.
?|?The?author?makes?no?representations?about?the?suitability?of?this
?|?software?for?any?purpose.??It?is?provided?“as?is“?without?express?or
?|?implied?warranty.
?‘----------------------------------------------------------------------*/
#include?
#include?
/*?The?following?can?go?in?a?header?file?*/
#include?
#include?
struct?Char_queue?{
???inline?Char_queue(unsigned?capacity?=?default_capacity);
???~Char_queue()?{?delete[]?queue_;?}
???bool?empty()?const?{?return?head_==tail_;?}
???inline?char?dequeue();
???inline?void?enqueue(char);
???bool?full()?const?{?return?head_==(tail_+1)%capacity_;?}
???static?bool?const?fixed_capacity?=?true;
private:
???static?unsigned?const?default_capacity?=?32;
???char?*queue_;
???unsigned?head_?tail_;
???unsigned?const?capacity_;
};
inline
Char_queue::Char_queue(unsigned?n)
???:?queue_(new?char[n+1])?head_(0)?tail_(0)?capacity_(n+1)?{
}
inline
char?Char_queue::dequeue()?{
???if?(!empty())?{
??????char?c?=?queue_[head_];
??????head_?=?(head_+1)%capacity_;
??????return?c;
???}?else
??????throw?std::underflow_error(std::string(“queue“));
}
inline
void?Char_queue::enqueue(char?c)?{
???if?(!full())?{
??????queue_[tail_]?=?c;
??????tail_?=?(tail_+1)%capacity_;
???}?else
??????throw?std::overflow_error(std::string(“queue“));
}
/*?Header?file?would?stop?here.?*/
/*?A?brief?test?of?the?above?implementation:?*/
int?main()?{
???Char_queue?q(4);
???while?(1)?{
??????if?(q.empty())?{?std::cout?<“Queue?is?empty.\n“;?}
??????else?if?(q.full())?{?std::cout?<“Queue?is?full.\n“;?}
??????char?cmd?ch;
??????std::cin?>>?cmd;
??????try?{
?????????switch?(cmd)?{
?????????case?‘e‘:?case?‘E‘:
????????????std::cin?>>?ch;
????????????q.enqueue(ch);
????????????break;
?????????case?‘d‘:?case?‘D‘:
????????????std::cout?<“Dequeued?“?<????????????break;
?????????case?‘q‘:?case?‘Q‘:
????????????std::cout?<“Quitting!\n“;
????????????return?0;
?????????default:
????????????std::cerr?<“Invalid?command!\n“;
?????????}
??????}?catch?(std::exception?&x)?{
?????????std::cerr?<“Caught?exception?“?<???????????????????<“?(“?<??????}
???}
???return?0;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2626??1998-09-06?19:29??課后題解答\Ch10\ex10_12a.cpp
?????文件???????2890??1998-09-06?19:29??課后題解答\Ch10\ex10_12b.cpp
?????文件????????807??1998-09-06?19:29??課后題解答\Ch10\ex10_15.cpp
?????文件???????2703??1998-09-06?19:30??課后題解答\Ch10\ex10_19.cpp
?????文件???????1970??1998-09-06?19:30??課后題解答\Ch10\ex10_5.cpp
?????文件???????2263??1998-09-06?19:30??課后題解答\Ch11\ex11_1.cpp
?????文件????????781??1998-09-06?19:31??課后題解答\Ch11\ex11_10.cpp
?????文件???????1014??1998-09-06?19:31??課后題解答\Ch11\ex11_21.cpp
?????文件???????1624??1998-09-06?19:31??課后題解答\Ch11\ex11_4.cpp
?????文件???????1195??1998-09-06?19:32??課后題解答\Ch11\ex11_8.cpp
?????文件???????5176??1998-09-06?19:43??課后題解答\Ch11\str.hpp
?????文件???????3139??1998-09-06?19:32??課后題解答\Ch12\ex12_10.cpp
?????文件???????1072??1998-09-06?19:32??課后題解答\Ch12\ex12_1a.cpp
?????文件???????1031??1998-09-06?19:32??課后題解答\Ch12\ex12_1b.cpp
?????文件???????1378??1998-09-06?19:32??課后題解答\Ch12\ex12_9.cpp
?????文件????????934??1998-09-06?19:33??課后題解答\Ch13\ex13_15.cpp
?????文件???????4753??1998-09-06?19:33??課后題解答\Ch13\ex13_2.cpp
?????文件???????2046??1998-09-06?19:33??課后題解答\Ch14\ex14_1.cpp
?????文件???????1627??1998-09-06?19:33??課后題解答\Ch14\ex14_10.cpp
?????文件???????3487??1998-09-06?19:33??課后題解答\Ch14\ex14_2.cpp
?????文件???????3041??1998-09-06?19:33??課后題解答\Ch15\ex15_2.cpp
?????文件???????2939??1998-09-06?19:44??課后題解答\Ch15\Ex15_3\Board.C
?????文件???????1365??1998-09-06?19:44??課后題解答\Ch15\Ex15_3\Board.H
?????文件???????1399??1998-09-06?19:45??課后題解答\Ch15\Ex15_3\BoardTextViewer.C
?????文件????????935??1998-09-06?19:45??課后題解答\Ch15\Ex15_3\BoardTextViewer.H
?????文件????????703??1998-09-06?19:45??課后題解答\Ch15\Ex15_3\BoardViewer.H
?????文件???????1529??1998-09-06?19:48??課后題解答\Ch15\Ex15_3\Game.C
?????文件????????946??1998-09-06?19:46??課后題解答\Ch15\Ex15_3\Game.H
?????文件???????2305??1998-09-06?19:46??課后題解答\Ch15\Ex15_3\HumanTextPla
?????文件???????1166??1998-09-06?19:46??課后題解答\Ch15\Ex15_3\HumanTextPla
............此處省略116個(gè)文件信息
評(píng)論
共有 條評(píng)論