ECE-1021

HOMEWORK #5A Solution Notes

(Last Mod: 27 November 2010 21:38:38 )

ECE-1021 Home


PROGRAM A - How much did that really cost?


Problem

The first step in the problem solving process is to understand the problem:

If an item is purchased with a credit card and paid back making only the minimum required payment each month, how much will that item end up costing the purchaser once it is finally paid off?

We are asked to prepare a table of the monthly transactions that would result under these conditions and to prepare a summary of the overall impact of using a credit card in this manner.


Inputs (Specifically stated)

"One of the first tasks your program should perform is to ask the user for the relevant information, namely the purchase price, interest rate, minimum payment percentage, and minimum absolute payment."


Outputs (Specifically stated)

1) Until the item is paid off:

"Your program should print a month-by-month table that gives the month number and the basic information that would be on the statement for that month, namely the old balance, the finance charges, the payment credited, the new balance, and the minimum payment due."

On the first statement, our "old balance" will be the purchase price and we will have made no payment so the payment credited will be zero. 

We need to know how to calculate each of the items in the table:

Month: Just the number of the previous month plus one. We can the first month "month 0" or "month 1", it doesn't really matter. But, in our summary, we probably want the length of time required to pay off the item to reflect the number of months in that we actually made payments - although the difference is pretty minor if we choose otherwise.

Old Balance: Just the "New Balance" from the prior month. The "Old Balance" for the first month is simply the purchase price.

old_balance = new_balance; // using new_balance from previous month

Finance Charge: The "Finance Charge" for a given month is "one month's interest on [the old] balance." Using the basic relationship that interest = principle * rate * time, this becomes:

interest = old_balance * apr * (1.0 / 12.0);

Payment: Simply the "Minimum Due" from the prior month. The "Payment" for the first month is zero since we make no payments until after we receive a statement telling us how much to pay.

payment = minimum_due; // using minimum_due from previous month

New Balance: This is specifically spelled out in the problem assignment: "Therefore the new balance (upon which the minimum payment is calculated) is the old balance, plus one month's interest on that balance, minus the previous month's payment."

new_balance = old_balance + interest - payment;

Minimum Due: This is explicitly spelled out in the problem assignment: "Your minimum payment is either a specific fraction of the new balance (typically between 2% and 3%) but not less than some absolute minimum (typically between $10 and $20) or the remaining balance if it is less than the absolute minimum."

if(new_balance > abs_minimum_pmt)

{

    minimum_due = new_balance * fraction;

 

    if(minimum_due < abs_minimum_pmt)

        minimum_due = abs_minimum_pmt;

}

else

{

    minimum_due = new_balance;

}

The output for this section should therefore look something like:

Month Old Balance Fin. Charge   Payment New Balance Minimum Due
  0  $ 2500.00  $   39.38  $    0.00  $ 2539.38  $   50.79
  1  $ 2539.38  $   40.00  $   50.79  $ 2528.59  $   50.57
  2  $ 2528.59  $   39.83  $   50.57  $ 2517.85  $   50.36

2) After the item is paid off:

"Once the item is paid off, you should print a summary that gives the following information:

The original purchase amount, the total number of months required to pay of the purchase, the total amount of the finance charges, and the total cost of the purchased item."

The output for this section should therefore look something like (using random values):

Number of months to pay off: .......... 37

Original Purchase Price: ....... $ 2500.00

Total Finance Charges: ......... $  300.00

Total Cost of Item: ............ $ 2800.00

The number of months required to pay off the item comes directly from the number of the last month printed in the table. The original purchase price was entered by the user. The Total Finance Charge and the Total Cost can simply be a running total of the corresponding quantity for each month.


Top-Down Pseudocode Development

Top Level:

  1. TASK: Get Input Data from User.

  2. TASK: Generate a Month-by-Month Table until item is paid off.

  3. TASK: Generate a Final Summary after the item is paid off.

Next Level of Detail:

  1. TASK: Get Input Data from User.

    1. GET: purchase price (purchase)

    2. GET: interest rate (apr)

    3. GET: minimum payment percentage (fraction)

    4. GET: minimum absolute payment (abs_minimum_pmt)

  2. TASK: Generate a Month-by-Month Table until item is paid off.

    1. TASK: Output Table Header (first row of table)

    2. TASK: Initialize variables for first month

    3. TASK: Initialize variable for running totals

    4. WHILE (balance > 0)

      1. TASK: Update variables for that month's activity

      2. TASK: Update running totals

      3. TASK: Print out activity for that month

  3. TASK: Generate a Final Summary after the item is paid off.

    1. OUT: Number of months

    2. OUT: Purchase Price

    3. OUT: Total Finance Charges

    4. OUT: Total Cost

At this point, we can see exactly how to implement all of the tasks provided we are willing to look back at the discussions leading up to this point. The pseudocode that is turned in for grading needs to be able to stand on its own showing enough detail that it convinces the grader that an adequate understanding of the problem exists and that a viable solution is represented. So the pseudocode turned in should have at least one more level of detail:

Submitted Level of Detail:

  1. TASK: Get Input Data from User.

    1. GET: purchase price (purchase)

    2. GET: interest rate (apr)

      1. SET: apr = apr / 100.0 

    3. GET: minimum payment percentage (fraction)

      1. SET: fraction = fraction / 100.0

    4. GET: minimum absolute payment (abs_minimum_pmt)

  2. TASK: Generate a Month-by-Month Table until item is paid off.

    1. TASK: Output Table Header (first row of table)

    2. TASK: Initialize variables for first month

      1. SET: month = -1 (i.e., month prior to "month 0")

      2. SET: new_balance = 0.0

      3. SET: minimum_due = 0.0

    3. TASK: Initialize variable for running totals

      1. SET: TotalFinanceCost = 0.0

      2. SET: TotalCost = 0.0

    4. WHILE (balance > 0)

      1. TASK: Update variables for that month's activity

        1. SET: month++

        2. SET: old_balance = new_balance

        3. SET: interest = old_balance * apr * (1.0/12.0)

        4. SET: payment = minimum_due

        5. SET: new_balance = old_balance + interest - payment

        6. TASK: Set Minimum Payment

          1. IF: (new_balance > abs_minimum_pmt)

            1. SET: minimum_due = new_balance * fraction

            2. IF: (minimum_due < abs_minimum_pmt)

              1. SET: minimum_due = abs_minimum_pmt

          2. ELSE:

            1. SET: minimum_due = new_balance

      2. TASK: Update running totals

        1. TotalFinanceCost += interest

        2. TotalCost += payment

      3. TASK: Print out activity for that month

        1. OUT: month

        2. OUT: old_balance

        3. OUT: interest

        4. OUT: payment

        5. OUT: new_payment

        6. OUT: minimum_due

  3. TASK: Generate a Final Summary after the item is paid off.

    1. OUT: Number of months (month)

    2. OUT: Purchase Price (purchase)

    3. OUT: Total Finance Charges (TotalFinanceCost)

    4. OUT: Total Cost (TotalCost)

Planned Input/Output Format:

Enter Original Purchase Price ($): ...... 2500

Enter Annual Percentage Rate (%): ....... 18.9

Enter Minimum Payment Fraction (%): ..... 2

Enter Minimum Payment Amount ($): ....... 10

MONTH-BY-MONTH SUMMARY

Month Old Balance Fin. Charge   Payment New Balance Minimum Due
  0  $ 2500.00  $   39.38  $    0.00  $ 2539.38  $   50.79
  1  $ 2539.38  $   40.00  $   50.79  $ 2528.59  $   50.57
  2  $ 2528.59  $   39.83  $   50.57  $ 2517.85  $   50.36

FINAL SUMMARY

Number of months to pay off: .......... 37

Original Purchase Price: ....... $ 2500.00

Total Finance Charges: ......... $  300.00

Total Cost of Item: ............ $ 2800.00

I strongly recommend including a planned I/O format section with your pseudocode. It gets you to consider such items as how you will word your prompts and whether you want the user to enter data, such as the interest rate, as a percentage (18.9) or as a fraction (0.189). In general, choose the one that is the most natural and convenient for the user and then perform any necessary manipulation in your code. Having a planned I/O format also makes it so that you don't have to be as explicit in your pseudocode regarding your GET and OUT statements since the reader can look at your I/O format to see what the prompts, headers, delimiters, or format specifications are likely going to be.