Download presentation
Presentation is loading. Please wait.
Published byNorman Newton Modified over 6 years ago
1
COMP 2710 Software Construction Homework 2 – Design and Algorithm
Note: 45 Minutes (5 Minutes question and practice time not included) History: Fall’11 Spring’14 Lec03b: homework 1 assigned in week 1 (Ideal) Spring’15 Lec04c: homework 1 assigned in week 2 (Late) Dr. Xiao Qin Auburn University
2
Student Performance Homework 1 vs. Homework 2
3-2 2
3
Time Management for Your Homework 2c
Reading: 15 Minutes Analysis: 15 Minutes Algorithm: 30 Minutes Coding: 1-2 Hours
4
User Input See /comp3000/demo/display.cpp 2-4 4
5
Output * * * * * * * See /comp3000/demo/display.cpp 2-5 5
6
Description You have just purchased a stereo system that cost $1000 on the following credit plan: no down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest, and whatever is left is used to pay part of the remaining debt. Your Task: Write a program that will tell you how many months it will take you to pay off this loan in particular and any loan in general. Your program also needs to calculate the total amount of interest paid over the life of any loan. 2-6 6
7
What candidate variables and constants should you consider?
Your First Question What candidate variables and constants should you consider? You have just purchased a stereo system that cost $1000 on the following credit plan: no down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest, and whatever is left is used to pay part of the remaining debt. Give you two minutes to work on candidate variables and constants. Loan Amount Interest Rate, Monthly Interest Rate Monthly Payment Balance 2-7 7
8
Your Second Question How to use the following variables and constants to calculate principal and interests? (Consider regular cases) Loan Amount Interest Rate, Monthly Interest Rate Monthly Payment Balance $50 monthly payment. The first month you pay 1.5% of $1000 in interest. That is $15 in interest. The remaining $35 is deducted from your debt, which leaves you with a debt of $ The next month you pay interest of 1.5% of $965.00, which is $ Hence, you can deduct $35.52 (which is $50–$14.48) from the amount you owe.
9
Your Second Question How to repeatedly calculate principal and interests for regular cases (i.e., non-last payment)? Monthly Payment 1. Monthly Interests 2. Principal = Monthly payment – Monthly Interests 3. Balance = Balance - Principal 4. Monthly Interests = Balance * Monthly Rate
10
How to determine the last month and last payment?
Your Third Question How to determine the last month and last payment? while (balance > 0) { if (balance > monthly_payment) { /* regular case */ monthly_interest = _______; total_interest = _______; principal = _______; balance = ________; } else /* special case: last payment */ last_payment = monthly_interest + balance; balance = 0; Problem here! (balance * monthly_rate + balance > monthly_payment)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.