联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2025-11-15 08:33

Assessment 1

Exercise A-20 Marks

Write a C program that calculates the definite integral of a polynomial of up to order 3 (a cubic function) over a specified range.

The polynomial is given by:

f(x) =a + bx + cx2+ dx3

Write a program that will prompt the user to enter the order of a polynomial, up to a maximum of 3 (cubic, four coefficients a, b, c, and d). A quadratic is order 2, a straight line of order l, a constant of order 0. Arrays may not be used. Ask the user to enter the lower and upper limits of integration (x_1 and x_2). Calculate the definite integral of f(x) between these limits, using the analytical formula for theintegralfapolynomial:

Display the result of the integration in the form.

The definite integral of f(x) from x - <number> to x = <number> is:l <result>

Your code must capture invalid inputs (x_1>=x_2 is invalid, the polynomial order must be between between 0 and 3). The program should repeat until the user selects that they have no more funetions to input. It should also confirm with the user that the coefficients they have entered are correct before completing the integral. It should not ask for coefficients outside of the order of the polynomial. Comment effusively. Your code may not use arrays, functions, classes, strings to solve the problem. You must use the material from lectures 1-4 only.

Hint: d= 0 in a quadratic (order 2) polynomial, c=d=0 in a straight line (order 1) and b=c=d=0 in ad constant function (order 0).

Sample output:

Enter order of equation (0 to 3): 3

Enter coefficient of x^3: 2

Enter coefficient of x^2: 0

Enter coefficient of x^1: -4

Enter constant term: 3

Confirming that your equation is:

f(x) = 2.00x^3 + 0.00x^2 + -4.00x + 3.00 ?

(1 for yes, 0 for no): 1

Enter lower limit of integration: 0

Enter upper limit of integration: 2

The definite integral of f(x) from x = 0.00 to x = 2.00 is: 6.0000

Do you want to enter another function? (1 for yes, O for no): 0 

Program finished. Goodbye!

Exercise B-20 Marks

Write a C program that simulates the growth of a savings account alongside the repayment of a loan. The program will generate month by month comparisons of net money. The user will input:

the initial savings balance,

the monthly "excess money" amount (between £50 and £150 that can be used for either savings or loan repayment),

the initial loan amount,

the interest rate for the loan,

and the number of years for the simulation to run (i.e. the time length of the loan) (up to 4 years).

The savings account offers an annual interest rate of 5.5% on the balance up to £5,000, and 1.06% on any portion of the balance above £5,000. All interest is compounded monthly. You will need to convert the annual effective interest rates into a monthly rate for the calculations. The formula for finding the monthy interest rate (i) from an annual rate is:

                           Equation 1

Hint: remember that 5.5% is expressed as 0.055 in this equation.

To find the amount of interest earned you will take the savings balance and multiply it by i. This can then be added to the balance, along with the monthly "excess cash" deposit for finding the savings balance. Note you will have to amend this equation to handle amounts above and below £5000.

savings balancenew = savings balancecurrent (1 + i) + excess money

In parallel, you will calculate repaying a loan with a user-specified initial value. The loan's annual effective interest rate can be chosen to be one percentage point lower, equal to, or one percentage point higher than the savings account's top rate (i.e. 4.5%, 5.5% or 6.5%). You will assume that the user will pay the standard monthly repayment (P) of the loan in addition to the "excess money" that is being entered. For a loan of initial amount (V) paid over years (Y), and with an effective monthly rate found using Equation 1 (i), you can calculate this by using:

A loan balance is calculated by finding the interest earned on the loan and adding that to the balance of the loan, then subtracting the repayment put into the loan as well as subtracting any of the "excess money" that is paid into the loan.

loan balancenew = loan balancecurrent (1 + i) - P — excess money

Once the loan is paid off, P should also go into savings. The program will show the scenario of putting:

1. all the excess money into the loan until the loan is paid off then all into savings,

2. all the excess money into savings,

3. all the excess money into savings until the savings reaches £5000 then all into the loan.

You must display, for each month of the year period, the balance of the savings and balance of the loan for each of the 3 scenarios in a table, side by side. Remember the loan balance must stop at £0: it cannot become less than £0. An example output is available on the next page. You may not use user defined functions, arrays or strings. You should use define to store the annual interest rates of the savings account and then calculate all monthly effective rates in the code.



版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp