In this lab, we are going to use knowledge of static method and friend class to implement a simple bond trading system. The source code is available here.
There are 3 roles in the bond trading system: Bond Issuer, Bond Holder, and Bond Certificate. From time to time, Bond Issuer will issue a certain amount of bonds and specify interest rate and period. Bond holders can purchase a certain amount of bonds with a discount (interest rate), and get a bond certificate. When bond maturity date comes (period arrives), Bond Holder can get back their money plus the interest from bond issuer. In this lab, the unit of time is year (period, maturity date, and residual time are all calculated by years)
Some terms you may find helpful.
class CertificateBase
: Base Class for Bond Certificate.
int residualTime_;
:double faceValue_;
:TestMaturity(int years)
:double GetFaceValue()
:void Maturity()
:class Certificate
: Template Class for Certificate, corresponding to one kind of bond of bondType. Most methods and data are declared as private, only accessed by friend class Issuer (including Constructor/Destructor).
static int transactionsNum_;
:static double interestRate_;
:static int period_;
:Issuer* issuer_;
:void Maturity()
:void SetRateAndPeriod(double rate, int year)
:Certificate(double value, Issuer* issuer)
:transactionsNum_
by one, initialize the issuer
and face value
of the certificate, set residual time
as the period (static)
of this bond.
~Certificate()
:transactionsNum_
by one.
class IssuerBase
: Base Class for Bond Issuer
int numOfBond_
:std::string name_
:IssuerBase(std::string name)
:void IssueBond(int amount)
:class Issuer
: Template Class for Bond Issuer, corresponding to one kind of bond of bondType, should be friend class of the corresponding Certificate class.
Issuer(std::string name)
:virtual void Settlement(Certificate* Certificate)
:virtual CertificateBase* SellBond(int amount)
:void SetRateAndPeriod(double rate, int year)
:class BondHolder
: Template Class for Bond Issuer, corresponding to one kind of bond of bondType.
double profit_;
:std::string name_;
:void PurchaseBond(IssuerBase* issuer, int amount)
:void Elapse(int year)
:BondHolder(std::string name)
:~BondHolder()
:
Issuer.h, Certificate.h
. Except for completing blank class method, you also need to declare friend class
and initialize static data
.
lab7
, check with the expected output below:[Transaction round 1] ---------------------- Issuer: HK Bond ---------------------- Num of ongoing transaction: 2 Num of bond pending sold : 45000 ---------------------- Issuer: New York Bond ---------------------- Num of ongoing transaction: 2 Num of bond pending sold : 64000 ---------------------- Issuer: London Bond ---------------------- Num of ongoing transaction: 2 Num of bond pending sold : 84000 [1 years later] John holds 1 certificates, and the current profit is -9800 Tom holds 2 certificates, and the current profit is -12000 Lucy holds 1 certificates, and the current profit is -9600 [Transaction round 2] ---------------------- Issuer: HK Bond ---------------------- Num of ongoing transaction: 2 Num of bond pending sold : 32000 ---------------------- Issuer: New York Bond ---------------------- Num of ongoing transaction: 4 Num of bond pending sold : 49000 ---------------------- Issuer: London Bond ---------------------- Num of ongoing transaction: 4 Num of bond pending sold : 46000 [2 years later] John holds 1 certificates, and the current profit is -18450 Tom holds 1 certificates, and the current profit is -16240 Lucy holds 0 certificates, and the current profit is 3000 [Transaction round 3] ---------------------- Issuer: HK Bond ---------------------- Num of ongoing transaction: 2 Num of bond pending sold : 16000 ---------------------- Issuer: New York Bond ---------------------- Num of ongoing transaction: 2 Num of bond pending sold : 33000 ---------------------- Issuer: London Bond ---------------------- Num of ongoing transaction: 4 Num of bond pending sold : 31000 [3 years later] John holds 0 certificates, and the current profit is 5800 Tom holds 0 certificates, and the current profit is 5420 Lucy holds 0 certificates, and the current profit is 5600 ---------------------- Issuer: HK Bond ---------------------- Num of ongoing transaction: 0 Num of bond pending sold : 16000 ---------------------- Issuer: New York Bond ---------------------- Num of ongoing transaction: 0 Num of bond pending sold : 33000 ---------------------- Issuer: London Bond ---------------------- Num of ongoing transaction: 0 Num of bond pending sold : 31000
The due date and time will be 10-min after your lab session. You are supposed to upload the following files in an archive to ZINC:
- Certificate.h Issuer.hYou can submit your codes multiple times by the deadline. Only the last submission will be graded.