forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. fixed 15.7, limit_quote should inherit from bulk_quote class. 2. added the question to README
- Loading branch information
Showing
17 changed files
with
115 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ If you have questions, try to connect with me: pezy<[email protected]> | |
|
||
namespace ch15 { | ||
#include "ex15_03_Quote.h" | ||
#include "ex15_05_Bulk_quote.h" | ||
#include "ex15_07_Limit_quote.h" | ||
} | ||
|
||
#endif // CH15_H_ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
================================================================================= | ||
C++ Primer 5th Exercise Answer Source Code | ||
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer | ||
Bulk_quote class | ||
If you have questions, try to connect with me: pezy<[email protected]> | ||
================================================================================= | ||
*/ | ||
|
||
#ifndef BULK_QUOTE_H_ | ||
#define BULK_QUOTE_H_ | ||
|
||
#include "ex15_03_Quote.h" | ||
#include <string> | ||
|
||
namespace EX05 { | ||
using std::string; | ||
using namespace EX03; | ||
|
||
class Bulk_quote : public Quote { | ||
public: | ||
Bulk_quote() = default; | ||
Bulk_quote(string const& book, double p, size_t qty, double disc) : Quote(book, p), min_qty(qty), discount(disc) {} | ||
|
||
virtual double net_price(size_t cnt) const override { | ||
if (cnt >= min_qty) return cnt * (1 - discount) * price; | ||
else return cnt * price; | ||
} | ||
protected: | ||
size_t min_qty = 0; | ||
double discount = 0.0; | ||
}; | ||
} | ||
|
||
#endif // BULK_QUOTE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
================================================================================= | ||
C++ Primer 5th Exercise Answer Source Code | ||
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer | ||
Limit_quote class | ||
If you have questions, try to connect with me: pezy<[email protected]> | ||
================================================================================= | ||
*/ | ||
|
||
#ifndef LIMIT_QUOTE_H_ | ||
#define LIMIT_QUOTE_H_ | ||
|
||
#include "ex15_05_Bulk_quote.h" | ||
#include <string> | ||
|
||
namespace EX07 { | ||
using namespace EX05; | ||
using std::string; | ||
|
||
class Limit_quote : public Bulk_quote { | ||
public: | ||
Limit_quote() = default; | ||
Limit_quote(string const& book, double p, size_t min, size_t max, double dist) : Bulk_quote(book, p, min, dist), max_qty(max) {} | ||
|
||
double net_price(size_t cnt) const override { | ||
if (cnt > max_qty) return max_qty * (1 - discount) * price + (cnt - max_qty) * price; | ||
else if (cnt >= min_qty) return cnt * (1 - discount) * price; | ||
else return cnt * price; | ||
} | ||
|
||
private: | ||
size_t max_qty = 0; | ||
}; | ||
} | ||
|
||
#endif // LIMIT_QUOTE_H_ |