// #include "stdafx.h" #include #include #include using namespace std; class Loan { private: string ID; double Notional; double APR; double rank; public: friend double combinedNotional(Loan const &l1, Loan const & l2); Loan(string id, double Notion, double apr, double r) { ID = id; Notional = Notion; APR = apr; rank = r; } string GetID() const { return ID; } double GetNotional() const { return Notional; } double GetAPR() const { return APR; } double GetRank() const { return rank; } string combined(Loan const& l1) { return this->GetID() + l1.GetID(); } }; bool operator<(Loan const & l1, Loan const & l2) { return l1.GetNotional()*l1.GetRank() > l2.GetNotional()*l2.GetRank(); } Loan operator+(Loan const & l1, Loan const & l2) { Loan new_loan(l1.GetID() + l2.GetID(), l1.GetNotional() + l2.GetNotional(), (l1.GetNotional()*l1.GetAPR() + l2.GetNotional()*l2.GetAPR()) / (l1.GetNotional() + l2.GetNotional()), (l1.GetNotional()*l1.GetRank() + l2.GetNotional()*l2.GetRank()) / (l1.GetNotional() + l2.GetNotional())); return new_loan; } double combinedNotional(Loan const &l1, Loan const & l2) { return l1.Notional + l2.Notional; } int main() { Loan l1("MyFirstLoan", 1000, 0.05, 0.01); Loan l2("MySecondLoan", 2000, 0.05, 0.00001); cout << "The notional of the loan is " << l1.GetNotional() << endl; cout << "If loan 1 is less than loan 2 " << (l1 < l2) << endl; cout << "Merged loan is " << (l1 + l2).GetNotional() << endl; cout << "The combined is " << l1.combined(l2) << endl; system("pause"); return 0; }