From b25f01cd9dbd3dcb9b0c8d4e5fdb32d262e9b075 Mon Sep 17 00:00:00 2001 From: LvChong Date: Sun, 14 Sep 2014 17:21:47 +0800 Subject: [PATCH 01/20] static allocator declare alloc as a static data member --- ch13/ex13.43/strvec.cpp | 1 + ch13/ex13.43/strvec.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ch13/ex13.43/strvec.cpp b/ch13/ex13.43/strvec.cpp index 89262bda..64eafc8c 100644 --- a/ch13/ex13.43/strvec.cpp +++ b/ch13/ex13.43/strvec.cpp @@ -22,6 +22,7 @@ #include #include +allocator StrVec::alloc; //! copy constructor StrVec::StrVec(const StrVec &s) diff --git a/ch13/ex13.43/strvec.h b/ch13/ex13.43/strvec.h index 17ccdc02..66db89e4 100644 --- a/ch13/ex13.43/strvec.h +++ b/ch13/ex13.43/strvec.h @@ -53,7 +53,7 @@ class StrVec std::string* first_free; // pointer to the first free element std::string* cap; // pointer to one past the end - std::allocator alloc; + static std::allocator alloc; //! utilities for Big 3/5 void reallocate(); From df26d2b52df7b5f312b73561d5ad8a0433ae52b6 Mon Sep 17 00:00:00 2001 From: Queequeg92 Date: Sun, 14 Sep 2014 21:23:25 +0800 Subject: [PATCH 02/20] Update strvec.cpp --- ch13/ex13.43/strvec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch13/ex13.43/strvec.cpp b/ch13/ex13.43/strvec.cpp index 64eafc8c..76bfae8f 100644 --- a/ch13/ex13.43/strvec.cpp +++ b/ch13/ex13.43/strvec.cpp @@ -22,7 +22,7 @@ #include #include -allocator StrVec::alloc; +std::allocator StrVec::alloc; //! copy constructor StrVec::StrVec(const StrVec &s) From 7ec25272bcd71075f24536263ded1677dccf34a9 Mon Sep 17 00:00:00 2001 From: Queequeg Date: Sun, 14 Sep 2014 21:34:52 +0800 Subject: [PATCH 03/20] Revert "Update strvec.cpp" This reverts commit df26d2b52df7b5f312b73561d5ad8a0433ae52b6. --- ch13/ex13.43/strvec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch13/ex13.43/strvec.cpp b/ch13/ex13.43/strvec.cpp index 76bfae8f..64eafc8c 100644 --- a/ch13/ex13.43/strvec.cpp +++ b/ch13/ex13.43/strvec.cpp @@ -22,7 +22,7 @@ #include #include -std::allocator StrVec::alloc; +allocator StrVec::alloc; //! copy constructor StrVec::StrVec(const StrVec &s) From 01a99cd767f153fdbba0207566b1c61c280f4d63 Mon Sep 17 00:00:00 2001 From: Queequeg Date: Sun, 14 Sep 2014 21:44:17 +0800 Subject: [PATCH 04/20] recover wrong revert --- ch13/ex13.43/strvec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch13/ex13.43/strvec.cpp b/ch13/ex13.43/strvec.cpp index 64eafc8c..76bfae8f 100644 --- a/ch13/ex13.43/strvec.cpp +++ b/ch13/ex13.43/strvec.cpp @@ -22,7 +22,7 @@ #include #include -allocator StrVec::alloc; +std::allocator StrVec::alloc; //! copy constructor StrVec::StrVec(const StrVec &s) From f858dcecfb8d78c405bbd13b79d2a47e402e78ec Mon Sep 17 00:00:00 2001 From: Yue Wang Date: Tue, 16 Sep 2014 18:46:43 +1200 Subject: [PATCH 05/20] Update README.md --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 377bbb05..db70bb54 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,26 @@ -#C++ Primer (第5版) 课后习题答案 +#C++ Primer (第5版) 习题答案 ##C++ Primer (5th Edition) exercise answers. -### Something I hope you know before go into the answers. +### Note - Use `-std=c++11`(optional: `-pedantic -Wall`) flag when compiling.(or you can use Visual Studio 2012+) -- I don't know the standard answer, but I tried my best to keep the correctness, if you found any bug, please [tell me](https://github.com/Mooophy/Cpp-Primer/issues/new), thanks. +- If you found any bug, please [let me know](https://github.com/Mooophy/Cpp-Primer/issues/new), thanks. - I have downloaded the headers from this book's [web site](http://www.informit.com/store/c-plus-plus-primer-9780321714114) and put them in the `include` folder. - In order to test the program in an efficient way, I also put the test data file in the `data` folder. -- If you find any mistake of the questions. Please check the [Errata](http://ptgmedia.pearsoncmg.com/images/9780321714114/errata/9780321714114_errata_10-31-12.html) first. -### If you want to contribute this repository. +### Contributions - Please **fork**([How?](https://help.github.com/articles/fork-a-repo)) this repository. - **commit**([How?](https://help.github.com/articles/create-a-repo#commit-your-first-change)) in your own repository. -- Create a **pull request**([How?](https://help.github.com/articles/using-pull-requests)) for me. +- Give me a **pull request**([How?](https://help.github.com/articles/using-pull-requests)). -### Getting Start +### More read [Begin to read](http://pezy.viewdocs.io/Cpp-Primer) Thanks for [viewdocs](https://github.com/progrium/viewdocs). -### Read more? +### If you speak Chinese 1. [PO在StackOverflow上的习题](http://book.douban.com/review/6500246/) 2. [C++ Primer issues(豆瓣讨论组)](http://www.douban.com/group/532124/) From 771e8ec46b8162e978c53a2ffeaa3fbc321d99ca Mon Sep 17 00:00:00 2001 From: Yue Wang Date: Tue, 16 Sep 2014 18:50:01 +1200 Subject: [PATCH 06/20] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index db70bb54..d87cbd58 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ - I have downloaded the headers from this book's [web site](http://www.informit.com/store/c-plus-plus-primer-9780321714114) and put them in the `include` folder. - In order to test the program in an efficient way, I also put the test data file in the `data` folder. -### Contributions +### How to contribute -- Please **fork**([How?](https://help.github.com/articles/fork-a-repo)) this repository. +- Please **fork**([How?](https://help.github.com/articles/fork-a-repo)) this repository first. - **commit**([How?](https://help.github.com/articles/create-a-repo#commit-your-first-change)) in your own repository. - Give me a **pull request**([How?](https://help.github.com/articles/using-pull-requests)). From 12fef81a0e55b9345c8b77f79718ba4b562e7fb2 Mon Sep 17 00:00:00 2001 From: Queequeg Date: Fri, 19 Sep 2014 11:41:01 +0800 Subject: [PATCH 07/20] change operators of StrBlobPtr modify operators : == and != add operators: > and < --- ch14/ex14.18.19/StrBlob.h | 74 +++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/ch14/ex14.18.19/StrBlob.h b/ch14/ex14.18.19/StrBlob.h index eeb4e7a4..91918643 100644 --- a/ch14/ex14.18.19/StrBlob.h +++ b/ch14/ex14.18.19/StrBlob.h @@ -161,8 +161,10 @@ StrBlob::operator =(const StrBlob &sb) */ class StrBlobPtr { - friend bool eq (const StrBlobPtr&, const StrBlobPtr&); - friend bool operator == (const StrBlobPtr&, const StrBlobPtr&); + friend bool operator==(const StrBlobPtr&, const StrBlobPtr&); + friend bool operator!=(const StrBlobPtr&, const StrBlobPtr&); + friend bool operator<(const StrBlobPtr&, const StrBlobPtr&); + friend bool operator>(const StrBlobPtr&, const StrBlobPtr&); public: StrBlobPtr(): curr(0) { } StrBlobPtr(StrBlob &a, size_t sz = 0) : wptr(a.data), curr(sz) { } @@ -177,7 +179,8 @@ class StrBlobPtr //! check returns a shared_ptr to the vector if the check succeeds std::shared_ptr> check(std::size_t, const std::string&) const; - + //! a valid iterator ? + bool valid()const; //! store a weak_ptr, which means the underlying vector might be destroyed std::weak_ptr> wptr; std::size_t curr; // current position within the array @@ -191,20 +194,40 @@ class StrBlobPtr //! in eq(), if l and r both are null then it returns true wiout caomparing curr //! in this operator, it returns true only when both pointer and curr are identical. //! -inline bool -operator==(const StrBlobPtr& lhs, const StrBlobPtr& rhs) +inline +bool operator==(const StrBlobPtr &lhs, const StrBlobPtr &rhs) { - //! lock () returns shared_ptr when possible ,or nullptr otherwise. - auto l = lhs.wptr.lock(); - auto r = rhs.wptr.lock(); + //only valid StrBlobPtrs which point to the same element are compatible + if (lhs.valid() && rhs.valid() && lhs.wptr.lock() == rhs.wptr.lock()) + return lhs.curr == rhs.curr; + else + throw std::logic_error("StrBlobPtr incompatible"); +} - return (l == r) ? (lhs.curr == lhs.curr) : false; +inline +bool operator!=(const StrBlobPtr &lhs, const StrBlobPtr &rhs) +{ + return !(lhs == rhs); } -inline bool -operator !=(const StrBlobPtr& lhs, const StrBlobPtr& rhs) +inline +bool operator<(const StrBlobPtr &lhs, const StrBlobPtr &rhs) { - return !(lhs == rhs); + //only valid StrBlobPtrs which point to the same element are compatible + if (lhs.valid() && rhs.valid() && lhs.wptr.lock() == rhs.wptr.lock()) + return lhs.curr < rhs.curr; + else + throw std::logic_error("StrBlobPtr incompatible"); +} + +inline +bool operator>(const StrBlobPtr &lhs, const StrBlobPtr &rhs) +{ + //only valid StrBlobPtrs which point to the same element are compatible + if (lhs.valid() && rhs.valid() && lhs.wptr.lock() == rhs.wptr.lock()) + return lhs.curr > rhs.curr; + else + throw std::logic_error("StrBlobPtr incompatible"); } @@ -229,6 +252,15 @@ StrBlobPtr::check(std::size_t i, const std::string &msg) const return ret; // otherwise, return a shared_ptr to the vector } +inline +bool StrBlobPtr::valid()const +{ + auto ret = wptr.lock(); + if (ret&&curr <= ret->size()) + return true; + return false; +} + //! prefix: return a reference to the incremented object inline StrBlobPtr& StrBlobPtr::incr() @@ -264,23 +296,5 @@ StrBlob::end() return ret; } -//! named equality operators for StrBlobPtr -inline -bool eq(const StrBlobPtr &lhs, const StrBlobPtr &rhs) -{ - auto l = lhs.wptr.lock(), r = rhs.wptr.lock(); - // if the underlying vector is the same - if (l == r) - // then they're equal if they're both null or - // if they point to the same element - return (!r || lhs.curr == rhs.curr); - else - return false; // if they point to difference vectors, they're not equal -} -inline -bool neq(const StrBlobPtr &lhs, const StrBlobPtr &rhs) -{ - return !eq(lhs, rhs); -} #endif From 505a0ca293045495e6470979470fb406154dfe9c Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 16:43:20 +0800 Subject: [PATCH 08/20] test --- ch05/ex5_14.cpp | 53 ++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/ch05/ex5_14.cpp b/ch05/ex5_14.cpp index 74cf8f7b..508415f5 100644 --- a/ch05/ex5_14.cpp +++ b/ch05/ex5_14.cpp @@ -12,44 +12,39 @@ #include #include -#include using namespace std; -int main() +int main(void) { - string current_str, previous_str, max_str, current_repeating_str; - int current_repeating=0, max_repeating=0; - - cout<<"Please Enter:\n"; - while (cin>>current_str) + string curr_str, pre_str, re_str; + int cnt = 1, max = 1; + cin >> pre_str; + while (cin >> curr_str) { - if(current_str.compare(previous_str) == 0) + if (curr_str == pre_str) { - current_repeating ++ ; - current_repeating_str = current_str; + ++cnt; + if (cnt > max) + { + max = cnt; + re_str = curr_str; + } } else { - current_repeating = 0; - current_repeating_str.clear(); - } - - if(current_repeating > max_repeating) - { - max_repeating = current_repeating; - max_str = current_repeating_str; + cnt = 1; } - - cout<<"The Max repeating string now is " - < Date: Sat, 20 Sep 2014 17:12:03 +0800 Subject: [PATCH 09/20] ex5_10 --- ch05/ex5_10.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ch05/ex5_10.cpp diff --git a/ch05/ex5_10.cpp b/ch05/ex5_10.cpp new file mode 100644 index 00000000..5042bbc0 --- /dev/null +++ b/ch05/ex5_10.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main(void) +{ + char c; + int aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0; + while (cin >> c) + { + if (c == 'a' || c == 'A') + ++aCnt; + else if (c == 'e' || c == 'E') + ++eCnt; + else if (c == 'i' || c == 'I') + ++iCnt; + else if (c == 'o' || c == 'O') + ++oCnt; + else if (c == 'u' || c == 'U') + ++uCnt; + } + cout << "Num of vowel a : " << aCnt << endl; + cout << "Num of vowel e : " << eCnt << endl; + cout << "Num of vowel i : " << iCnt << endl; + cout << "Num of vowel o : " << oCnt << endl; + cout << "Num of vowel u : " << uCnt << endl; + return 0; +} \ No newline at end of file From 9f5eac3a2fbcc580309e13fca7daf48b371192fc Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 19:51:42 +0800 Subject: [PATCH 10/20] ex5_23 --- ch05/ex5_23.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ch05/ex5_23.cpp diff --git a/ch05/ex5_23.cpp b/ch05/ex5_23.cpp new file mode 100644 index 00000000..61b0cd36 --- /dev/null +++ b/ch05/ex5_23.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main(void) +{ + int a, b; + cin >> a >> b; + cout << static_cast(a) / b << endl; + + return 0; +} \ No newline at end of file From 063e3aafcd2e0d784159bdac507f1f78f9a59d00 Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 19:51:52 +0800 Subject: [PATCH 11/20] ex5_24 --- ch05/ex5_24.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ch05/ex5_24.cpp diff --git a/ch05/ex5_24.cpp b/ch05/ex5_24.cpp new file mode 100644 index 00000000..7f9b488d --- /dev/null +++ b/ch05/ex5_24.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +int main(void) +{ + int a, b; + cin >> a >> b; + + if (b == 0) + throw runtime_error("divisor is 0"); + + cout << static_cast(a) / b << endl; + + return 0; +} \ No newline at end of file From cfaf1857af5cbf65fceffbfbdd94364234add5c9 Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 19:52:01 +0800 Subject: [PATCH 12/20] ex5_25 --- ch05/ex5_25.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ch05/ex5_25.cpp diff --git a/ch05/ex5_25.cpp b/ch05/ex5_25.cpp new file mode 100644 index 00000000..e69de29b From d094769a405c3ec68bcc593dccc788d7863b1a6f Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 19:55:08 +0800 Subject: [PATCH 13/20] error in 5_23 --- ch05/ex5_23_24_25.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch05/ex5_23_24_25.cpp b/ch05/ex5_23_24_25.cpp index 2ba9f850..e40f82b3 100644 --- a/ch05/ex5_23_24_25.cpp +++ b/ch05/ex5_23_24_25.cpp @@ -36,7 +36,7 @@ int main() while(cin>>n1>>n2) { - if(n2==1) + if(n2==0) { try { From 2d694518b5bf8410667803e6429b7262360c2ab9 Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 20:12:55 +0800 Subject: [PATCH 14/20] ex5_25 just made a mistake --- ch05/ex5_25.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ch05/ex5_25.cpp b/ch05/ex5_25.cpp index e69de29b..3bd23aeb 100644 --- a/ch05/ex5_25.cpp +++ b/ch05/ex5_25.cpp @@ -0,0 +1,34 @@ +#include +#include + +using namespace std; + +int main(void) +{ + int a, b; + cout << "Enter two numbers :" << endl; + + while (cin >> a >> b) + { + try{ + if (b == 0) + throw runtime_error("divisor is 0"); + cout << static_cast(a) / b << endl; + break; + } + catch (runtime_error err){ + cout << err.what() + << "\nTry again ? Enter y or n" << endl; + char c; + cin >> c; + if (!cin || c == 'n') + break; + else + { + cout << "Enter two numbers :" << endl; + } + } + } + + return 0; +} From 24483aa1e9d494f6de56cc92994a2525869b78b4 Mon Sep 17 00:00:00 2001 From: codewyh Date: Sat, 20 Sep 2014 20:42:36 +0800 Subject: [PATCH 15/20] Revert "test" This reverts commit 505a0ca293045495e6470979470fb406154dfe9c. --- ch05/ex5_14.cpp | 53 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/ch05/ex5_14.cpp b/ch05/ex5_14.cpp index 508415f5..74cf8f7b 100644 --- a/ch05/ex5_14.cpp +++ b/ch05/ex5_14.cpp @@ -12,39 +12,44 @@ #include #include +#include using namespace std; -int main(void) +int main() { - string curr_str, pre_str, re_str; - int cnt = 1, max = 1; - cin >> pre_str; - while (cin >> curr_str) + string current_str, previous_str, max_str, current_repeating_str; + int current_repeating=0, max_repeating=0; + + cout<<"Please Enter:\n"; + while (cin>>current_str) { - if (curr_str == pre_str) + if(current_str.compare(previous_str) == 0) { - ++cnt; - if (cnt > max) - { - max = cnt; - re_str = curr_str; - } + current_repeating ++ ; + current_repeating_str = current_str; } else { - cnt = 1; + current_repeating = 0; + current_repeating_str.clear(); } - - pre_str = curr_str; - } - if (!re_str.empty()) - { - cout << re_str << " occurs " << max << " times" << endl; - } - else - { - cout << "no such number" << endl; + + if(current_repeating > max_repeating) + { + max_repeating = current_repeating; + max_str = current_repeating_str; + } + + cout<<"The Max repeating string now is " + < +#include"quote.h" class Bulk_quote : public Quote { diff --git a/ch15/ex15.11/limit_quote.cpp b/ch15/ex15.11/limit_quote.cpp index 6fe3b4d1..7ac4150c 100644 --- a/ch15/ex15.11/limit_quote.cpp +++ b/ch15/ex15.11/limit_quote.cpp @@ -3,7 +3,7 @@ void Limit_quote::debug() const { - std::cout << "data members of this class:\n" - << "max_qty= " << this->max_qty << " " - << "discount= " << this->discount<< " \n"; + Quote::debug(); + std::cout << "max_qty= " << this->max_qty << " " + << "discount= " << this->discount<< " "; } diff --git a/ch15/ex15.11/main.cpp b/ch15/ex15.11/main.cpp index abd9b8f4..36cd82fd 100644 --- a/ch15/ex15.11/main.cpp +++ b/ch15/ex15.11/main.cpp @@ -33,10 +33,13 @@ int main() */ Quote& r = q; r.debug(); + std::cout << "\n"; r = bq; r.debug(); + std::cout << "\n"; r = lq; r.debug(); + std::cout << "\n"; std::cout << "====================\n"; @@ -54,10 +57,13 @@ int main() * */ print_debug(q); + std::cout << "\n"; print_debug(lq); + std::cout << "\n"; print_debug(bq); + std::cout << "\n"; - + system("pause"); return 0; } diff --git a/ch15/ex15.11/quote.cpp b/ch15/ex15.11/quote.cpp index de2b8844..7ab50533 100644 --- a/ch15/ex15.11/quote.cpp +++ b/ch15/ex15.11/quote.cpp @@ -4,5 +4,5 @@ void Quote::debug() const { std::cout << "data members of this class:\n" << "bookNo= " <bookNo << " " - << "price= " <price<< " \n"; + << "price= " <price<< " "; } From c6cfc63ea859dffaa75689b1f8678d0fe8bf18f6 Mon Sep 17 00:00:00 2001 From: Queequeg Date: Mon, 22 Sep 2014 09:51:24 +0800 Subject: [PATCH 18/20] remove system("pause") --- ch15/ex15.11/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ch15/ex15.11/main.cpp b/ch15/ex15.11/main.cpp index 36cd82fd..eba4e2d6 100644 --- a/ch15/ex15.11/main.cpp +++ b/ch15/ex15.11/main.cpp @@ -63,7 +63,6 @@ int main() print_debug(bq); std::cout << "\n"; - system("pause"); return 0; } From 069ae56461b29f2b0f0b74e1f60c5337c4a5aa28 Mon Sep 17 00:00:00 2001 From: Queequeg Date: Mon, 22 Sep 2014 11:31:24 +0800 Subject: [PATCH 19/20] add error information --- ch15/ex15.15.16.17/bulk_quote.cpp | 3 ++- ch15/ex15.15.16.17/limit_quote.cpp | 5 +++-- ch15/ex15.15.16.17/main.cpp | 5 +++++ ch15/ex15.15.16.17/quote.cpp | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ch15/ex15.15.16.17/bulk_quote.cpp b/ch15/ex15.15.16.17/bulk_quote.cpp index 7191b9cf..010544f9 100644 --- a/ch15/ex15.15.16.17/bulk_quote.cpp +++ b/ch15/ex15.15.16.17/bulk_quote.cpp @@ -7,7 +7,8 @@ double Bulk_quote::net_price(std::size_t n) const void Bulk_quote::debug() const { + Quote::debug(); std::cout //<< "data members of this class:\n" << "min_qty= " << quantity << " " - << "discount= " << this->discount<< " \n"; + << "discount= " << discount<< " "; } diff --git a/ch15/ex15.15.16.17/limit_quote.cpp b/ch15/ex15.15.16.17/limit_quote.cpp index fa9100fc..37996259 100644 --- a/ch15/ex15.15.16.17/limit_quote.cpp +++ b/ch15/ex15.15.16.17/limit_quote.cpp @@ -3,7 +3,8 @@ void Limit_quote::debug() const { + Quote::debug(); std::cout //<< "data members of this class:\n" - << "max_qty= " << this->quantity << " " - << "discount= " << this->discount<< " \n"; + << "max_qty= " << quantity << " " + << "discount= " << discount<< " "; } diff --git a/ch15/ex15.15.16.17/main.cpp b/ch15/ex15.15.16.17/main.cpp index cd4744ca..981399ba 100644 --- a/ch15/ex15.15.16.17/main.cpp +++ b/ch15/ex15.15.16.17/main.cpp @@ -39,6 +39,11 @@ int main() { + /* + error C2259 : 'Disc_quote' : cannot instantiate abstract class + 1> due to following members : + 1> 'double Disc_quote::net_price(size_t) const' : is abstract + */ Disc_quote d; return 0; diff --git a/ch15/ex15.15.16.17/quote.cpp b/ch15/ex15.15.16.17/quote.cpp index f1b6b5ed..d6526321 100644 --- a/ch15/ex15.15.16.17/quote.cpp +++ b/ch15/ex15.15.16.17/quote.cpp @@ -4,5 +4,5 @@ void Quote::debug() const { std::cout //<< "data members of this class:\n" << "bookNo= " <bookNo << " " - << "price= " <price<< " \n"; + << "price= " <price<< " "; } From e190945ffa651aa71932fb1882474f832f14386a Mon Sep 17 00:00:00 2001 From: Queequeg92 Date: Wed, 24 Sep 2014 11:21:22 +0800 Subject: [PATCH 20/20] Modify test data --- ch15/ex15.30/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch15/ex15.30/main.cpp b/ch15/ex15.30/main.cpp index 72e64857..b2673026 100644 --- a/ch15/ex15.30/main.cpp +++ b/ch15/ex15.30/main.cpp @@ -33,10 +33,10 @@ int main() basket.add_item(Bulk_quote("Bible",20.6,20,0.3)); for (unsigned i = 0; i != 10; ++i) - basket.add_item(Bulk_quote("C++Primer",30.9,20,0.4)); + basket.add_item(Bulk_quote("C++Primer",30.9,5,0.4)); for (unsigned i = 0; i != 10; ++i) - basket.add_item(Bulk_quote("CLRS",40.1,10,0.5)); + basket.add_item(Quote("CLRS",40.1)); std::ofstream log("log.txt",std::ios_base::app|std::ios_base::out);