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.
doesn't finish.
- Loading branch information
Showing
8 changed files
with
137 additions
and
20 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
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
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,36 @@ | ||
/* | ||
================================================================================= | ||
C++ Primer 5th Exercise Answer Source Code | ||
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer | ||
Disc_quote | ||
If you have questions, try to connect with me: pezy<[email protected]> | ||
================================================================================= | ||
*/ | ||
|
||
#ifndef CP5_EX15_15_BULK_QUOTE_H_ | ||
#define CP5_EX15_15_BULK_QUOTE_H_ | ||
|
||
#include "ex15_15_Disc_quote.h" | ||
#include <string> | ||
|
||
inline namespace EX15 { | ||
|
||
using std::string; | ||
|
||
class Bulk_quote : public Disc_quote { | ||
public: | ||
Bulk_quote() = default; | ||
Bulk_quote(string const& book, double price, size_t qty, double disc) : Disc_quote(book, price, qty, disc) { } | ||
virtual double net_price(std::size_t cnt) const override { | ||
if (cnt >= quantity) return cnt * (1 - discount) * price; | ||
else return cnt * price; | ||
} | ||
}; | ||
|
||
} | ||
|
||
#endif // CP5_EX15_15_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,36 @@ | ||
/* | ||
================================================================================= | ||
C++ Primer 5th Exercise Answer Source Code | ||
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer | ||
Disc_quote | ||
If you have questions, try to connect with me: pezy<[email protected]> | ||
================================================================================= | ||
*/ | ||
|
||
#ifndef CP5_EX15_15_DISC_QUOTE_H_ | ||
#define CP5_EX15_15_DISC_QUOTE_H_ | ||
|
||
#include "ex15_03_Quote.h" | ||
#include <string> | ||
|
||
inline namespace EX15 { | ||
|
||
using std::string; | ||
|
||
class Disc_quote : public EX03::Quote { | ||
public: | ||
Disc_quote() = default; | ||
Disc_quote(string const& b, double p, size_t q, double d) : EX03::Quote(b, p), quantity(q), discount(d){ } | ||
virtual double net_price(size_t) const = 0; | ||
protected: | ||
size_t quantity = 0; | ||
double discount = 0.0; | ||
}; | ||
|
||
} | ||
|
||
#endif // CP5_EX15_15_DISC_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,46 @@ | ||
/* | ||
================================================================================= | ||
C++ Primer 5th Exercise Answer Source Code | ||
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer | ||
Limit_quote class | ||
added debug function | ||
If you have questions, try to connect with me: pezy<[email protected]> | ||
================================================================================= | ||
*/ | ||
|
||
#ifndef CP5_EX15_15_LIMIT_QUOTE_H_ | ||
#define CP5_EX15_15_LIMIT_QUOTE_H_ | ||
|
||
#include "ex15_15_Bulk_quote.h" | ||
#include <string> | ||
|
||
namespace EX15 { | ||
using std::string; | ||
using std::cout; using std::endl; | ||
|
||
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 final 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; | ||
} | ||
|
||
virtual void debug() const final { | ||
Bulk_quote::debug(); | ||
cout << "\tmax_qty: " << max_qty << endl; | ||
} | ||
|
||
private: | ||
size_t max_qty = 0; | ||
}; | ||
} | ||
|
||
#endif // CP5_EX15_15_LIMIT_QUOTE_H_ |