资源简介
这个是C++之父的著作 The C++ PL的特别版的课后习题答案,希望对大家有用,

代码片段和文件信息
/* 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 “ << q.dequeue() << ‘\n‘;
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 “ << typeid(x).name()
<< “ (“ << x.what() << “)\n“;
}
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 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个文件信息
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
评论
共有 条评论