forked from applenob/Cpp_Primer_Practice
-
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.
- Loading branch information
Showing
32 changed files
with
1,876 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "bulk_quote.h" | ||
|
||
double Bulk_quote::net_price(std::size_t n) const | ||
{ | ||
return n * price * ( n >= quantity ? 1 - discount : 1); | ||
} | ||
|
||
void Bulk_quote::debug() const | ||
{ | ||
std::cout //<< "data members of this class:\n" | ||
<< "min_qty= " << quantity << " " | ||
<< "discount= " << this->discount<< " \n"; | ||
} |
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,54 @@ | ||
#ifndef BULK_QUOTE_H | ||
#define BULK_QUOTE_H | ||
#include "disc_quote.h" | ||
|
||
class Bulk_quote : public Disc_quote | ||
{ | ||
|
||
public: | ||
Bulk_quote() { std::cout << "default constructing Bulk_quote\n"; } | ||
Bulk_quote(const std::string& b, double p, std::size_t q, double disc) : | ||
Disc_quote(b, p, q, disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; } | ||
|
||
// copy constructor | ||
Bulk_quote(const Bulk_quote& bq) : Disc_quote(bq) | ||
{ std::cout << "Bulk_quote : copy constructor\n"; } | ||
|
||
// move constructor | ||
//page 535, " In a constructor, noexcept appears between the parameter list and the : that begins the constructor initializer list" | ||
Bulk_quote(Bulk_quote&& bq) noexcept : Disc_quote(std::move(bq)) | ||
{ | ||
std::cout << "Bulk_quote : move constructor\n"; | ||
} | ||
|
||
// copy =() | ||
Bulk_quote& operator =(const Bulk_quote& rhs) | ||
{ | ||
Disc_quote::operator =(rhs); | ||
std::cout << "Bulk_quote : copy =()\n"; | ||
|
||
return *this; | ||
} | ||
|
||
|
||
// move =() | ||
Bulk_quote& operator =(Bulk_quote&& rhs) noexcept | ||
{ | ||
Disc_quote::operator =(std::move(rhs)); | ||
std::cout << "Bulk_quote : move =()\n"; | ||
|
||
return *this; | ||
} | ||
|
||
double net_price(std::size_t n) const override; | ||
void debug() const override; | ||
|
||
~Bulk_quote() override | ||
{ | ||
std::cout << "destructing Bulk_quote\n"; | ||
} | ||
}; | ||
|
||
|
||
|
||
#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 @@ | ||
#include "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,79 @@ | ||
#ifndef DISC_QUOTE_H | ||
#define DISC_QUOTE_H | ||
|
||
#include "quote.h" | ||
class Disc_quote : public Quote | ||
{ | ||
friend bool operator !=(const Disc_quote& lhs, const Disc_quote& rhs); | ||
public: | ||
Disc_quote() { std::cout << "default constructing Disc_quote\n"; } | ||
|
||
Disc_quote(const std::string& b, double p, std::size_t q, double d) : | ||
Quote(b, p), quantity(q), discount(d) | ||
{ | ||
std::cout << "Disc_quote : constructor taking 4 parameters.\n"; | ||
} | ||
|
||
// copy constructor | ||
Disc_quote(const Disc_quote& dq) : | ||
Quote(dq), quantity(dq.quantity), discount(dq.discount) | ||
{ | ||
std::cout << "Disc_quote : copy constructor.\n"; | ||
} | ||
|
||
// move constructor | ||
Disc_quote(Disc_quote&& dq) noexcept : | ||
Quote(std::move(dq)), quantity(std::move(dq.quantity)), discount(std::move(dq.discount)) | ||
{ | ||
std::cout << "Disc_quote : move constructor.\n"; | ||
} | ||
|
||
// copy =() | ||
Disc_quote& operator =(const Disc_quote& rhs) | ||
{ | ||
Quote::operator =(rhs); | ||
this->quantity = rhs.quantity; | ||
this->discount = rhs.discount; | ||
|
||
std::cout << "Disc_quote : copy =()\n"; | ||
|
||
return *this; | ||
} | ||
|
||
// move =() | ||
Disc_quote& operator =(Disc_quote&& rhs) noexcept | ||
{ | ||
if (*this != rhs) | ||
{ | ||
Quote::operator =(std::move(rhs)); | ||
this->quantity = std::move(rhs.quantity); | ||
this->discount = std::move(rhs.discount); | ||
} | ||
std::cout << "Disc_quote : move =()\n"; | ||
|
||
return *this; | ||
} | ||
|
||
virtual double net_price(std::size_t n) const override = 0; | ||
|
||
~Disc_quote() | ||
{ | ||
std::cout << "destructing Dis_quote\n"; | ||
} | ||
|
||
protected: | ||
std::size_t quantity = 3; | ||
double discount = 0.0; | ||
}; | ||
|
||
bool inline | ||
operator !=(const Disc_quote& lhs, const Disc_quote& rhs) | ||
{ | ||
return Quote(lhs) != Quote(rhs) | ||
&& | ||
lhs.quantity != rhs.quantity | ||
&& | ||
lhs.discount != rhs.discount; | ||
} | ||
|
||
#endif // 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,9 @@ | ||
#include "limit_quote.h" | ||
|
||
|
||
void Limit_quote::debug() const | ||
{ | ||
std::cout //<< "data members of this class:\n" | ||
<< "max_qty= " << this->quantity << " " | ||
<< "discount= " << this->discount<< " \n"; | ||
} |
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,19 @@ | ||
#ifndef LIMIT_QUOTE_H | ||
#define LIMIT_QUOTE_H | ||
|
||
#include "disc_quote.h" | ||
|
||
class Limit_quote : public Disc_quote | ||
{ | ||
public: | ||
Limit_quote() = default; | ||
Limit_quote(const std::string& b, double p, std::size_t max, double disc): | ||
Disc_quote(b, p, max, disc) { } | ||
|
||
double net_price(std::size_t n) const override | ||
{ return n * price * (n < quantity ? 1 - discount : 1 ); } | ||
|
||
void debug() const override; | ||
}; | ||
|
||
#endif // LIMIT_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,18 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include "quote.h" | ||
#include "bulk_quote.h" | ||
#include "limit_quote.h" | ||
#include "disc_quote.h" | ||
|
||
|
||
int main() | ||
{ | ||
Bulk_quote bq1; | ||
Bulk_quote bq2("ss", 2.05, 12, 0.3); | ||
bq2 = std::move(bq2); | ||
|
||
|
||
return 0; | ||
} |
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,8 @@ | ||
#include "quote.h" | ||
|
||
void Quote::debug() const | ||
{ | ||
std::cout //<< "data members of this class:\n" | ||
<< "bookNo= " <<this->bookNo << " " | ||
<< "price= " <<this->price<< " \n"; | ||
} |
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,73 @@ | ||
#ifndef QUOTE_H | ||
#define QUOTE_H | ||
|
||
#include <string> | ||
#include <iostream> | ||
|
||
class Quote | ||
{ | ||
friend bool operator !=(const Quote& lhs, const Quote& rhs); | ||
public: | ||
Quote() { std::cout << "default constructing Quote\n"; } | ||
Quote(const std::string &b, double p) : | ||
bookNo(b), price(p) { std::cout << "Quote : constructor taking 2 parameters\n"; } | ||
|
||
// copy constructor | ||
Quote(const Quote& q) : bookNo(q.bookNo), price(q.price) | ||
{ std::cout << "Quote: copy constructing\n"; } | ||
|
||
// move constructor | ||
Quote(Quote&& q) noexcept : bookNo(std::move(q.bookNo)), price(std::move(q.price)) | ||
{ std::cout << "Quote: move constructing\n"; } | ||
|
||
// copy = | ||
Quote& operator =(const Quote& rhs) | ||
{ | ||
if(*this != rhs) | ||
{ | ||
bookNo = rhs.bookNo; | ||
price = rhs.price; | ||
} | ||
std::cout << "Quote: copy =() \n"; | ||
|
||
return *this; | ||
} | ||
|
||
// move = | ||
Quote& operator =(Quote&& rhs) noexcept | ||
{ | ||
if(*this != rhs) | ||
{ | ||
bookNo = std::move(rhs.bookNo); | ||
price = std::move(rhs.price); | ||
} | ||
std::cout << "Quote: move =!!!!!!!!! \n"; | ||
|
||
return *this; | ||
} | ||
|
||
std::string isbn() const { return bookNo; } | ||
virtual double net_price(std::size_t n) const { return n * price; } | ||
virtual void debug() const; | ||
|
||
virtual ~Quote() | ||
{ | ||
std::cout << "destructing Quote\n"; | ||
} | ||
|
||
private: | ||
std::string bookNo; | ||
|
||
protected: | ||
double price = 10.0; | ||
}; | ||
|
||
bool inline | ||
operator !=(const Quote& lhs, const Quote& rhs) | ||
{ | ||
return lhs.bookNo != rhs.bookNo | ||
&& | ||
lhs.price != rhs.price; | ||
} | ||
|
||
#endif // QUOTE_H |
Oops, something went wrong.