Engineering 1114 Spring 2008 HW 13: While Loop Assignment, Assignments of Engineering

Instructions and problems for a programming assignment in matlab for engineering 1114 students during spring 2008. The assignment involves creating a script and a function for different problems, including determining the average of an unknown number of grades and creating a simple loan calculator. Students are required to add comments to their code, create flowcharts, and provide sample runs.

Typology: Assignments

Pre 2010

Uploaded on 12/14/2008

cboggs89
cboggs89 🇺🇸

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EngE 1114 Spring 2008
HW 13* Programming: While loop
*This assignment counts towards your programming average.
General Instructions:
For both problem solutions, you must add comments in your code so that someone who
types “help <filename>” will be able to tell what your m-files do.
You will need flowchart, listing and sample runs for each problem solution.
It is easiest to create a WORD document and copy and paste your flowchart from VISIO,
the listing of your program from your MATLAB editor window, and the output for any
sample runs from your MATLAB command window. Please put your paper header on all
pages.
You may NOT use any built-in MATLAB functions for this assignment other than trig and
inverse trig functions and sqrt. However you will be writing some of your own MATLAB
functions as part of this assignment.
Problems:
Pay particular attention to whether your algorithm should be programmed as a
FUNCTION or a SCRIPT.
PROBLEM 1: Prepare the flowchart and MatLab program (SCRIPT file) for an algorithm
that will determine and output the average of an unknown number of grades. You may
choose to allow the user to stop the program by entering an invalid grade or by explicitly
indicating that there are no more grades to enter. You should also add appropriate code so
that if the user starts the program but decides not to enter any grades the program terminates
without error. Provide sample output for following input values:
Run 1: No values input
Run 2: 98, 77, 56, 72, 65, 87, 83, 92, 74, 79
PROBLEM 2: Loan calculators available on the web will help users evaluate how long it
will take them to pay off a loan and how much they will be paying the loan company over
the entire life of the loan. The life of the loan starts when the loan is given and ends when
the loan balance reaches zero. We will program a simple version of a loan calculator. In
this problem, we assume the user is given a one-time cash payment from the loan company.
Each month thereafter, 1) the user makes a single fixed payment to the loan company in the
middle of each month and 2) the loan company adds a single interest charge on the current
value of the loan at the end of the month. This means that the loan amount fluctuates twice
a month, decreasing when a payment is made but increasing when the loan company adds
interest.
(continued on next page)
pf2

Partial preview of the text

Download Engineering 1114 Spring 2008 HW 13: While Loop Assignment and more Assignments Engineering in PDF only on Docsity!

EngE 1114 Spring 2008

HW 13* Programming: While loop *This assignment counts towards your programming average.

General Instructions: For both problem solutions, you must add comments in your code so that someone who types “help ” will be able to tell what your m-files do.

You will need flowchart, listing and sample runs for each problem solution.

It is easiest to create a WORD document and copy and paste your flowchart from VISIO, the listing of your program from your MATLAB editor window, and the output for any sample runs from your MATLAB command window. Please put your paper header on all pages.

You may NOT use any built-in MATLAB functions for this assignment other than trig and inverse trig functions and sqrt. However you will be writing some of your own MATLAB functions as part of this assignment.

Problems: Pay particular attention to whether your algorithm should be programmed as a FUNCTION or a SCRIPT.

PROBLEM 1: Prepare the flowchart and MatLab program (SCRIPT file) for an algorithm that will determine and output the average of an unknown number of grades. You may choose to allow the user to stop the program by entering an invalid grade or by explicitly indicating that there are no more grades to enter. You should also add appropriate code so that if the user starts the program but decides not to enter any grades the program terminates without error. Provide sample output for following input values:

Run 1: No values input Run 2: 98, 77, 56, 72, 65, 87, 83, 92, 74, 79

PROBLEM 2: Loan calculators available on the web will help users evaluate how long it will take them to pay off a loan and how much they will be paying the loan company over the entire life of the loan. The life of the loan starts when the loan is given and ends when the loan balance reaches zero. We will program a simple version of a loan calculator. In this problem, we assume the user is given a one-time cash payment from the loan company. Each month thereafter, 1) the user makes a single fixed payment to the loan company in the middle of each month and 2) the loan company adds a single interest charge on the current value of the loan at the end of the month. This means that the loan amount fluctuates twice a month, decreasing when a payment is made but increasing when the loan company adds interest.

(continued on next page)

EngE 1114 Spring 2008

Prepare the flowchart and MatLab program ( FUNCTION file) for an algorithm that will determine and output:

  1. the total amount paid to the loan company over the life of the loan (T). Note that the last payment may be less than the fixed monthly payment, if the amount owed in the last month is less than the fixed monthly payment. You will need to account for this when calculating the total amount paid (T).
  2. the total number of months needed to pay off the loan (TMP), rounded up to the nearest integer.

The function will accept:

  1. the original loan amount, in dollars (P)
  2. annual interest rate, in decimal form (R)
  3. a fixed monthly payment, in dollars (pay).

Note that the loan starts on the first day of the first month. Recall that payment is made in the middle of each month and interest is added on the last day of each month. So, for each month, when interest is added:

Amount owed after interest is added = (Amount owed before interest is added) × (1+ R/12)

You will need to use a while loop since you don’t know how many payments you will make. A good choice of control variable would be the amount owed on the loan.

Use the following to run your function in the command window:

  1. P=100, R=0.10, pay = 90 Hint: you should get that it takes 2 months and the total paid will be $100. (remember that functions don’t format numbers)
  2. P=1000, R=0.10, pay = 1000
  3. P = 40000, R = 0.045, pay=
  4. P = 10000, R = 0.14, pay = 500