首页 > > 详细

辅导MAT00021M讲解留学生C/C++设计

Module Code 
MAT00021M 
MMath and MSc Examinations 2019/20 
Department: 
Mathematics 
Title of Exam: 
C++ Programming with Applications in Finance 
Time Allowed: 
You have 24 hours from the release of this exam to upload your solutions. However, this 
exam should take approximately 2 hours to complete. 
Allocation of Marks: 
The marking scheme shown on each question is indicative only. 
Question: 1 2 Total 
Marks: 50 50 100 
Instructions for Candidates: 
Answer both questions. 
Further instructions appear on page 3. 
Queries: 
If you believe that there is an error on this exam paper, then please use the “Queries” link 
below the exam on Moodle. 
This will be available for the first four hours after the release of this exam. 
No corrections will be announced after four hours. 
After that, if a question is unclear, then answer it as best you can and note the 
assumptions you’ve made to allow you to proceed. 
Submission: 
Please write clearly and submit a single copy of your solution to each question. Any 
handwritten work in your electronic submission must be legible. Black ink is 
recommended for written answers. View your submission before uploading. 
Number each page of your solutions consecutively. Write the exam title, your candidate 
number, and the page number at the top of each page. 
Upload your solutions to the “Exam submission” link below the exam on Moodle 
(preferably as a single PDF file). If you are unable to do this, then email them to 
Page 1 (of 5) 
MAT00021M 
A Note on Academic Integrity 
We are treating this online examination as a time-limited open assessment, and you are 
therefore permitted to refer to written and online materials to aid you in your answers. 
However, you must ensure that the work you submit is entirely your own, and for the whole 
time the assessment is live (up to 48 hours) you must not: 
• communicate with departmental staff on the topic of the assessment (except by means of 
the query procedure detailed overleaf), 
• communicate with other students on the topic of this assessment, 
• seek assistance on this assessment from the academic and/or disability support services, 
such as the Writing and Language Skills Centre, Maths Skills Centre and/or Disability 
Services (unless you have been recommended an exam support worker in a Student 
Support Plan), 
• seek advice or contribution from any third party, including proofreaders, friends, or 
family members. 
We expect, and trust, that all our students will seek to maintain the integrity of the assessment, 
and of their awards, through ensuring that these instructions are strictly followed. Failure to 
adhere to these requirements will be considered a breach of the Academic Misconduct 
regulations, where the offences of plagiarism, breach/cheating, collusion and commissioning 
are relevant — see Section AM.1.2.1 of the Guide to Assessment (note that this supersedes 
Section 7.3). 
Page 2 (of 5) 
MAT00021M 
Further Instructions for Candidates: 
(a) This exam paper is accompanied by three files: 
• A data file YieldCurve.txt, which you should use in in Question 1. 
• Header files Solver02.h and Solver03.h, one of which you should use in 
Question 2. 
These files should not be modified, and should be submitted with your code. 
(b) You should complete the Exam quiz on Moodle as part of your work on Questions 1(a) 
and 2(c). 
(c) Submit your code as a single compressed .zip file, including all Code::Blocks project 
(.cbp) files (if applicable), source code and header (.cpp and .h) files, and the 
executable file produced by compiling and linking the project, all residing in a single 
parent directory. The .zip file should preserve the subdirectory structure of the parent 
directory (that is, the subdirectory structure must be automatically recreated when 
unzipping the file). 
(d) Submit your answer to Question 2(b) by uploading it separately to your code. Your 
answer can either be written by hand and scanned, or typed using a word processor or 
text editor. 
(e) If you use code written by somebody else in the exam, or code that you have previously 
written, then you should add a brief comment to your code indicating the source. 
Page 3 (of 5) Turn over 
MAT00021M 
1 (of 2). Given a collection of data points (x0, y0) , (x1, y1) , . . . , (xN , yN), modellers are often 
interested in producing a curve that fits the data and adequately represents their 
trend so as to be able to estimate new data at intermediate values. 
Assume that the nodes x0, x1, . . . , xN are all distinct (not necessarily equally spaced). 
Define the predicting function as 
PN(x) � y0LN,0(x) + y1LN,1(x) + . . . + yNLN,N(x) = 
N� 
j=0 
y jLN, j(x) , (1) 
with coefficients given by 
LN, j(x) � 
(x − x0) (x − x1) . . . 
� 
x − x j−1 
� � 
x − x j+1 
� 
. . . (x − xN)� 
x j − x0 
� � 
x j − x1 
� 
. . . 
� 
x j − x j−1 
� � 
x j − x j+1 
� 
. . . 
� 
x j − xN 
� = N� 
k=0 
k� j 
x − xk 
x j − xk 
for each j ∈ {0, 1, . . . ,N}. It can be easily checked that 
LN, j(xi) = 
� 
1, if i = j, 
0, if i � j, 
whence PN(xi) = yi for all i ∈ {0, 1, . . . ,N}; i.e. the predicting function PN passes 
through all N + 1 data points. Therefore, y¯ � PN(x¯) can be used to construct a new 
data point (x¯, y¯) at an intermediate x¯. 
(a) Write a piece of code to solve the problem in Question 1 of the Exam quiz. 
[15] 
(b) Generalise the code in part (a) to write a function pred taking two arrays 
x,y of size N + 1 (representing the data points), N, and x¯ as parameters, and 
returning the value of the predicting function given by (1) at x¯. The function 
pred should be prevented from modifying its arguments. [20] 
(c) A text file YieldCurve.txt has been provided; the first line contains 9 dis- 
tinct maturities (in years), while the second line contains the corresponding 
yield rates. Start by writing a piece of code to read the data from the file and 
store them into two arrays, then use the function pred of part (b) to estimate 
the yield rate for a maturity of 8 months. Your answer should be rounded to 
2 decimal places. [15] 
[Total: 50] 
Page 4 (of 5) 
MAT00021M 
2 (of 2). An investor deposits a fixed amount D > 0 into a bank account at the start of each 
year. The account balance after Y years is 
V(r) = 
Y−1� 
k=0 
Der(Y−k), 
where r > 0 is the (continuously compounded) interest rate. The derivative of V is 
V �(r) = 
Y−1� 
k=0 
D(Y − k)er(Y−k). 
(a) Create a C++ class Investment with the following members: 
D Private data member of type double representing D 
Y Private data member of type int representing Y 
Value Public member function (taking a single parameter r) for calculating 
the value of V(r) 
The class should also have a suitable constructor. [20] 
Two header files Solver02.h and Solver03.h have been provided, containing 
code implementing the bisection and Newton-Raphson methods for solving non- 
linear equations using both virtual functions (Solver02.h) and function templates 
(Solver03.h). 
(b) Describe the factors that should be considered when choosing one of the 
methods in Solver02.h and Solver03.h to solve a non-linear equation of 
the form 
V(r) = x, 
where x is a given number. 
Your answer for this question should not exceed 200 words. [10] 
(c) Write a program that uses the Investment class to solve the problem in 
Question 2 of the Exam quiz. The value of r should be accurate to 4 decimal 
places. 
You should use one of the files Solver02.h and Solver03.h without any 
change. It is permissible to add additional member function(s) to the class 
Investment and/or use an inherited class in order to use the code in the 
chosen header file. [20] 
[Total: 50] 
Page 5 (of 5) End of examination. 
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!