int main() { Mortgage first(10000, 5.0, 500) ; //uses non-default constructor Mortgage second ; //uses default constructor, mortage for $100,000 at 4.5% interest and $2,500 payment second.credit(10000) ; cout << "Current balance after rediting second mortgage 10K: " << second.getPrincipal() << endl ; cout << "Amortization schedule for first mortgage:" << endl ; first.amortize() ; }
int main(void) { double creditAmount = 10000; Mortgage defaultMortgage; //creates default-initialized object Mortgage secondMortgage(100000, 5.0, 500); //creates non-default object secondMortgage.credit(creditAmount); //credits account cout << fixed << setprecision(2) << "Current balance after crediting account $" << creditAmount; cout << fixed << setprecision(2) << ": $" << secondMortgage.getPrincipal() << endl; cout << "Amortization schedule for first mortgage: " << endl; defaultMortgage.amortize(); return 0; }
int main(){ Mortgage first(10000,5.0,500); //Normal mortgage Mortgage second; //Default constructor Mortgage bad(10000,-5,12); //Invalid mortgage (will give error message as soon as the program hits this line.) second.credit(10000); //Credits the second mortgage (reduces the total from $100,000 to $90,000 cout <<"Current balance after crediting second mortgage: "<<second.getPrincipal()<<endl; //Print this to the user cout<<"Amortization schedule for the first mortgage:"<<endl; first.amortize(); //Display the amortization table for the first mortgage. }
int main () { //create four new mortgages, one using default constructor, two display error message Mortgage one(300000,.01,3200);//this one will work cout << "Mortgage two: "; Mortgage two(100000,.5,200); //this one has a rate too large for the monthly payment and will display an error message cout << "Mortgage three: "; Mortgage three(100000,-2,500);//will display negative rate error Mortgage four; //default constructor, will have 100000 with 5% and $500 payment one.credit(50000);//This credits the first mortgage $50,000, will reduce initial principle to $250,000 cout << "Fourth mortgage balance: $" << four.getPrincipal() << endl; cout << "Current balance after crediting mortgage one 50K: $" << one.getPrincipal() << endl; cout << "Amortization schedule for first mortgage:" << endl; one.amortize(); }
/******************************************************************** Function Name: MortgageCalculator::reportMortgageDetails Function Description: displays the details of the mortgage the user has input **********************************************************************/ void MortgageCalculator::reportMortgageDetails() { // amortize a mortgage and get the monthly payment Mortgage mortgage = Mortgage(m_principalAmount, m_interestRate, m_term); const double monthlyPayment = mortgage.getMonthlyPayment(); // display a nice report tot he user cout << endl << fixed << setprecision(2) // all numbers as fixed-point with 2 digits << setw(24) << left << "Term in Years:" << " " << setw(7) << right << m_term << endl << setw(24) << left << "Interest Rate:" << " " << setw(10) << right << m_interestRate << "%" << endl << setw(24) << left << "Mortgage Principal:" << "$" << setw(10) << right << m_principalAmount << endl << setw(24) << left << "Monthly Payment:" << "$" << setw(10) << right << monthlyPayment << endl << endl; }
int main(){ Mortgage myMort; double amount; double ir; int years; double term; cout << "Enter total loan amount :" << endl; cin >> amount; myMort.set_loan(amount); cout << "Enter interest rate :" << endl; cin >> ir; myMort.set_interest(ir); cout << "Enter number of years :" << endl; cin >> years; myMort.set_years(years); term = (1 + ir/12) * pow (12, years); cout << "Your monthly payment will be :" << myMort.getmonthlypayment(term); cout << "Your total payment will be :" << myMort.getpay(); }
int main() { Mortgage first; // using default constructor Mortgage second( 10000, 5, 500 ); // using non-default constructor cout << "\nError-check on invalid principal: "; Mortgage error1( -10000, 5, 500 ); // testing for error from invalid principal amount (negative) cout << "Error-check on invalid interest (below 0): "; Mortgage error2_1( 10000, -5, 500 ); // testing for error from invalid interest rate (below 0) cout << "Error-check on invalid interest (above 100): "; Mortgage error2_2( 10000, 105, 500 ); // testing for error from invalid interest rate (above 100) cout << "Error-check on invalid payment: "; Mortgage error3( 10000, 5, -500 ); // testing for error from invalid payment amount (negative) cout << "Error-check on multiple constructing invalidities: "; Mortgage error4( -100, -5, -50 ); // testing for multiple invalid inputs cout << "\nInitial principal of first mortgage: " << first.getPrincipal() << endl; first.credit( 10000 ); // credit the first mortgage with a $10000 payment cout << "Initial principal of a formerly invalid mortgage: " << error1.getPrincipal() << endl; error1.credit( 1000 ); cout << "\nPrincipal of the first mortgage after a $10000 credit: " << first.getPrincipal() << endl; cout << "Principal of the formerly invalid mortgage after a $1000 credit: " << error1.getPrincipal() << endl; cout << "Error-check on invalid credit: "; first.credit( -1000 ); // testing for error from invalid credit amount (negative) Mortgage error5( 0, 5, 5 ); cout << "Error-check on paid-off mortgage: "; error5.credit( 100 ); // testing for error when attempting to credit a mortgage that has been paid off cout << "\nAmortization table of the second mortgage:" << endl; second.amortize(); }
QDataStream& MtgCalculator::LoadOldVersion(QDataStream& stream) { Q_D(MtgCalculator); RETURN_WHEN_RUNNING(true, stream) Reset(); qint32 tempInt, TempKey; stream >> tempInt; stream >> d->m_UseStoredCashFlows; stream >> d->m_CPRass; stream >> d->m_CDRass; stream >> d->m_LSass; stream >> d->m_RecoveryLag; stream >> d->m_Delinquency; stream >> d->m_DelinquencyLag; stream >> d->StartDate; Mortgage TmpMtg; while (tempInt--) { stream >> TempKey; TmpMtg.SetLoadProtocolVersion(loadProtocolVersion()); stream >> TmpMtg; SetLoan(TmpMtg, TempKey); } return TemplAsyncCalculator<MtgCalculatorThread, MtgCashFlow>::LoadOldVersion(stream); }
/******************************************************************** Function Name: MortgageCalculator::reportMortgageDetails Function Description: displays the details of the mortgage the user has input **********************************************************************/ void MortgageCalculator::reportMortgageDetails() { // amortize a mortgage and get the monthly payment Mortgage mortgage = Mortgage(m_interestRate, m_term, m_principalAmount); const double monthlyPayment = mortgage.getMonthlyPayment(); const int numberOfPayments = mortgage.getNumberOfPayments(); // display a nice report to the user cout << endl << fixed << setprecision(2) // all numbers as fixed-point with 2 digits << setw(24) << left << "Term in Years:" << " " << setw(7) << right << m_term << endl << setw(24) << left << "Interest Rate:" << " " << setw(10) << right << m_interestRate << "%" << endl << setw(24) << left << "Mortgage Principal:" << "$" << setw(10) << right << m_principalAmount << endl << setw(24) << left << "Monthly Payment:" << "$" << setw(10) << right << monthlyPayment << endl << endl; // print a payment breakdown by month printBreakdownHeader(1, monthlyPayment); for (int month = 1; month <= numberOfPayments; month++) { const double interestPayment = mortgage.getInterestPayment(month); const double principalPayment = mortgage.getPrincipalPayment(month); const double remainingBalance = mortgage.getRemainingBalance(month); cout << setw(10) << right << month << " " << "$" << setw(10) << right << interestPayment << " " << "$" << setw(10) << right << principalPayment << " " << "$" << setw(10) << right << remainingBalance << endl; // pause and print a new header every year if ((month % Mortgage::MONTHS_IN_YEAR) == 0 && month < numberOfPayments) { pausePrompt(); printBreakdownHeader(month / Mortgage::MONTHS_IN_YEAR + 1, monthlyPayment); } } }
int main() { //Main class Mortgage User; //Set the Loan double loan; cout << "What is the current amount of dollars you have on your loan : $"; while ((!(cin >> loan)) || (loan <= 0)) //If cin does NOT accept input for loan, OR, loan <= 0, then: { cin.clear(); //Clear any warning cin.ignore(); //Ingore everything that is in the buffer cout << "ERROR: Loan must be a number greater than 0." << endl; cout << "What is the current amount of dollars you have on your loan : $"; //Try again } cin.ignore(); //This removes any excess i.e. 10h would be accepted as 10, then the next cin would have h. This gets rid of the h. User.setLoan(loan); //Set the Interest Rate double intR; cout << "What is your annual interest rate on your loan : %"; while ((!(cin >> intR)) || (intR <= 0)) { cin.clear(); cin.ignore(); cout << "ERROR: Interest must be a number greater than 0." << endl; cout << "What is your annual interest rate on your loan : %"; } cin.ignore(); intR = intR/1200; //Divide rate by months, and divide by 100 to turn into % User.setIntR(intR); //Set the Years remaining double term; cout << "How many years do you have left on your loan : "; while ((!(cin >> term)) || (term <= 0)) { cin.clear(); cin.ignore(); cout << "ERROR: Years must be a number greater than 0." << endl; cout << "How many years do you have left on your loan : "; } cin.ignore(); term = term*12; //Turn years into Months User.setTerm(term); //Seperate Input from Output cout << endl << "-----------------------------------------" << endl << endl; //Get the payment breakdown double blnc = loan; //set Balance = loan double mPay = User.getPymt(); //MonthlyPayment = getPymt(); this is done once to prevent having to re-calculate this every line. double intP, plPd; double totalIntPaid = 0; double totalPrnPaid = 0; cout << setw(5) << right << "Month" << " : " << setw(8) << "Interest" << " : " << setw(9) << "Principal" << " : " << setw(10) << "Balance" << endl; cout << "-----------------------------------------" << endl; cout << fixed << showpoint << setprecision(2); //Used to format the following for (int i=1; blnc > 0; i++) { if ((i % 21) == 0) cin.get(); intP = blnc * intR; //InterestPaid = Balance * interestRate plPd = mPay - intP; //PrincipalPaid = MonthlyPayment - InterestPaid blnc -= plPd; //Balance = Balance - PrincipalPaid totalIntPaid += intP; totalPrnPaid += plPd; cout << setw(5) << right << i << " : $" << setw(7) << intP << " : $" << setw(8) << plPd << " : $" << setw(9) << blnc << endl; } cout << "-----------------------------------------" << endl; cout << "Total Interest Paid : $" << totalIntPaid << endl; cout << "Total Principal Paid : $" << totalPrnPaid << endl; //Get the monthly payment cout << "Your monthly payment is : $" << User.getPymt() << endl; //Get the total paid cout << "Total amount paid : $" << User.getTotl() << endl; return 0; }