Docsity

CS 101: Calculating the Annual Percentage Rate of Treasury Bills - Prof. James Cohoon, Assignments of Computer Science

Toggle sidebar
bg1
CS 101 Unpledged
Page 1 of 2 Spring 1997
Homework 1
Assigned Laboratory 2
Due start of Laboratory 3
Please perform the following activities. Note that although you are allowed to talk with others,
your work must be your own.
Objective
To practice creating programs that do interactive input and output, and to make sure that you
understand how to write simple programs that compute useful things.
Problem
The Treasury Department through the Bureau of Public Debt sells Treasury bills or as they are
commonly called T-bills. The T-bills are investment notes backed by the United States govern-
ment. The typical T-bill is a $10,000 note that is redeemable for that amount after some govern-
ment-specified number of days. A T-bill is sold at a discount where the difference between the
face value of a redeemed note and its buying price is the interest paid on the investment. For
example, the Bureau sold notes this month at a price of $9,872.90 with a term of 91 days that can
be redeemed for $10,000. We are interested in knowing the annual percentage rate of such an
investment. The annual percentage rate can be computed in the following manner.
Step 1. Let RedeemedValue be the value of note upon redemption. For the example given
above, this amount is $10,000.
Step 2. Let PurchasePrice be the cost of the note. For the above example, this amount is
$9,872.90.
Step 3. Let Te rm be the number of days for the note to mature. For the above example, this
value is 91.
Step 4. Compute the interest rate for the term of the note. This rate is given by the expression
(RedeemedValue ÷ PurchasePrice) - 1. For the above example, the value of this
expression is approximately 0.01287.
Step 5. Compute the number of terms per year. This number is given by the expression by 365
÷ Term. For the above example, the value of the expression is approximately 4.01098.
Step 6. Compute the annual interest rate per year. This value is given by the product of the
interest rate for the term of the note and the number of terms per year. For the above
example, the annual interest rate is approximately 0.05163.
Step 7. Compute the annual percentage rate. This value is the given by the product of the
annual interest rate and 100. For the above example, the annual interest rate is approx-
imately 5.16%.
Your task is to write a program that individually prompts its user for three values:
• Value of the note,
• Purchase price of the note,
• Number of days for the note to mature.
pf2

Partial preview of the text

Download CS 101: Calculating the Annual Percentage Rate of Treasury Bills - Prof. James Cohoon and more Assignments Computer Science in PDF only on Docsity!

CS 101 Unpledged

Page 1 of 2 Spring 1997

Homework 1

Assigned Laboratory 2

Due start of Laboratory 3

Please perform the following activities. Note that although you are allowed to talk with others, your work must be your own.

Objective

To practice creating programs that do interactive input and output, and to make sure that you understand how to write simple programs that compute useful things.

Problem

The Treasury Department through the Bureau of Public Debt sells Treasury bills or as they are commonly called T-bills. The T-bills are investment notes backed by the United States govern- ment. The typical T-bill is a $10,000 note that is redeemable for that amount after some govern- ment-specified number of days. A T-bill is sold at a discount where the difference between the face value of a redeemed note and its buying price is the interest paid on the investment. For example, the Bureau sold notes this month at a price of $9,872.90 with a term of 91 days that can be redeemed for $10,000. We are interested in knowing the annual percentage rate of such an investment. The annual percentage rate can be computed in the following manner.

Step 1. Let RedeemedValue be the value of note upon redemption. For the example given above, this amount is $10,000. Step 2. Let PurchasePrice be the cost of the note. For the above example, this amount is $9,872.90. Step 3. Let Term be the number of days for the note to mature. For the above example, this value is 91. Step 4. Compute the interest rate for the term of the note. This rate is given by the expression ( RedeemedValue ÷ PurchasePrice ) - 1. For the above example, the value of this expression is approximately 0.01287. Step 5. Compute the number of terms per year. This number is given by the expression by 365 ÷ Term. For the above example, the value of the expression is approximately 4.01098. Step 6. Compute the annual interest rate per year. This value is given by the product of the interest rate for the term of the note and the number of terms per year. For the above example, the annual interest rate is approximately 0.05163. Step 7. Compute the annual percentage rate. This value is the given by the product of the annual interest rate and 100. For the above example, the annual interest rate is approx- imately 5.16%.

Your task is to write a program that individually prompts its user for three values:

  • Value of the note,
  • Purchase price of the note,
  • Number of days for the note to mature.

CS 101 Unpledged

Page 2 of 2 Spring 1997

The program then computes and displays the annual percentage rate corresponding for the associ- ated T-bill. Figure 1 illustrates the type of input and output your program should produce.

Notes

  • Your program is to be named tbill.cpp.
  • All objects should be of type float.
  • All prompts should end with a flush.
  • To confirm to the user how the inputs were used, redisplay their values.
  • Your program should contain the standard program header. This header was developed in Laboratory 0.
  • File tbill.cpp should be copied electronically to your class account before the labora- tory in which it is due. See the course workbook or web page (www.cs.virginia.edu/ cs101) on how to do this.
  • The program should follow course programming style guidelines. The guidelines are con- tained in the course workbook and the course web page.
  • You should also turn in a hardcopy (print out) at the beginning of the laboratory in which its due.
  • The grading criteria for this assignment can be found on our course web page.
  • If you are interested, the web page for the Treasury Departments’s Bureau of Public Debt is www.publicdebt.treas.gov/bpd/bpdhome.htm

Figure 1: Sample input/output behavior of program tbill.cpp.