Download Exam2 Programming Review questions

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Greeks (finance) wikipedia , lookup

Continuous-repayment mortgage wikipedia , lookup

Present value wikipedia , lookup

Transcript
Exam 2 Programming Review questions
1.
(15%) An input data file named Temperature.dat, contains a positive, integer value on the first line
that indicates how many temperature values are in the file (each line after that contains a temperature
value which is a real number). The temperatures, in degrees Fahrenheit, are average daily
temperatures taken in Ames, IA. You will never have more than 365 temperatures in the file.
Write a complete program which:
a) Reads the value on the first line of the file (the count of temperatures).
b) Reads the temperatures into a one-dimensional array.
c) Determines the mean daily temperature.
d) Determines the deviation (xi – xmean) from the mean on each day and stores this in a new, onedimensional array.
e) Output to a file the deviation array and the original array, in table form (two columns) with
appropriate headings.
2.
(15%) Given the following partial Main program, you are to complete the main program and write a
Function subprogram that, provided a frequency of compounding, Compound (as a string), a rate of
interest, i, (as a percentage) and an amount of dollars deposited, P, will calculate and return the amount
of money saved, F, after n years. Notice that the user is prompted to enter the frequency of
compounding.
F  P 1  0.01i 
n
0.01i 

F  P1 

4 

4n
0.01i 

F  P1 

12 

12 n
for annual compounding
for quarterly compounding
for monthly compounding
Option Explicit
Sub MainP()
'
Dim F As Single, P As Single, i As Single
Dim n As Integer
Dim Compound As String
Compound = InputBox("What type of compounding frequency, (annual, quarterly or monthly)?")
P = InputBox("How much have you deposited?")
n = InputBox("How many years are you going to leave the money in the savings account?")
i = InputBox("What is the interest rate (enter as a percentage)?")
(Enter the statements here to access the function subprogram and output the answer to
the screen)
End Sub
FUNCTION SUBPROGRAM, SHOW BELOW:
3.
Fix the items that are wrong with this program.
Option Explicit
Sub Main()
Dim A(1 To i) As Integer, B As Single, C As Single
Dim i As Integer
Open (U:\DataIn.dat) For Input As 1
Open (U:\DataOut.dat) For Output as 1
For i = 1 To 10
Input #1, A(i)
Next i
Call Calc(A(i), B, C)
Print #1, B, C
Print #2, A(i)
Close
End Sub
Sub Calc(ByRef A(i)as Single , ByVal X as Single)
For i = 1 To n
X = X + A(i)
Next i
End Sub