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. added debug for Quote/Bulk_quote/Limit_quote 2. Test output
- Loading branch information
Showing
16 changed files
with
174 additions
and
197 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 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 |
---|---|---|
|
@@ -11,8 +11,8 @@ If you have questions, try to connect with me: pezy<[email protected]> | |
================================================================================= | ||
*/ | ||
|
||
#ifndef QUOTE_H | ||
#define QUOTE_H | ||
#ifndef CP5_EX15_03_QUOTE_H_ | ||
#define CP5_EX15_03_QUOTE_H_ | ||
|
||
#include <string> | ||
#include <iostream> | ||
|
@@ -45,4 +45,4 @@ double print_total(ostream& os, Quote const& item, size_t n) { | |
|
||
} | ||
|
||
#endif // QUOTE_H | ||
#endif // CP5_EX15_03_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 |
---|---|---|
|
@@ -11,8 +11,8 @@ If you have questions, try to connect with me: pezy<[email protected]> | |
================================================================================= | ||
*/ | ||
|
||
#ifndef BULK_QUOTE_H_ | ||
#define BULK_QUOTE_H_ | ||
#ifndef CP5_EX15_05_BULK_QUOTE_H_ | ||
#define CP5_EX15_05_BULK_QUOTE_H_ | ||
|
||
#include "ex15_03_Quote.h" | ||
#include <string> | ||
|
@@ -36,4 +36,4 @@ class Bulk_quote : public Quote { | |
}; | ||
} | ||
|
||
#endif // BULK_QUOTE_H_ | ||
#endif // CP5_EX15_05_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 |
---|---|---|
|
@@ -11,8 +11,8 @@ If you have questions, try to connect with me: pezy<[email protected]> | |
================================================================================= | ||
*/ | ||
|
||
#ifndef LIMIT_QUOTE_H_ | ||
#define LIMIT_QUOTE_H_ | ||
#ifndef CP5_EX15_07_LIMIT_QUOTE_H_ | ||
#define CP5_EX15_07_LIMIT_QUOTE_H_ | ||
|
||
#include "ex15_05_Bulk_quote.h" | ||
#include <string> | ||
|
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,45 @@ | ||
/* | ||
================================================================================= | ||
C++ Primer 5th Exercise Answer Source Code | ||
Copyright (C) 2014-2015 github.com/pezy/Cpp-Primer | ||
Bulk_quote class | ||
added debug() function | ||
If you have questions, try to connect with me: pezy<[email protected]> | ||
================================================================================= | ||
*/ | ||
|
||
#ifndef CP5_EX15_11_BULK_QUOTE_H_ | ||
#define CP5_EX15_11_BULK_QUOTE_H_ | ||
|
||
#include "ex15_11_Quote.h" | ||
#include <string> | ||
|
||
namespace EX11 { | ||
using std::string; | ||
|
||
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; | ||
} | ||
|
||
virtual void debug() const override { | ||
Quote::debug(); | ||
cout << "\tminqty: " << min_qty << "\tdiscount: " << discount << endl; | ||
} | ||
|
||
protected: | ||
size_t min_qty = 0; | ||
double discount = 0.0; | ||
}; | ||
} | ||
|
||
#endif // CP5_EX15_11_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,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_11_LIMIT_QUOTE_H_ | ||
#define CP5_EX15_11_LIMIT_QUOTE_H_ | ||
|
||
#include "ex15_11_Bulk_quote.h" | ||
#include <string> | ||
|
||
namespace EX11 { | ||
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 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_11_LIMIT_QUOTE_H_ |
Oops, something went wrong.