King’s College London
University Of London
This paper is part of an examination of the College counting towards the award of a degree. Examinations are governed by the College Regulations under the authority of the Academic Board.
MSc Examination
7CCMFM13 C++ for Financial Mathematics (MSc)
Summer Mock Exam 2020
Time Allowed: Two Hours
All questions carry equal marks.
Full marks will be awarded for complete answers to FOUR questions.
If more than four questions are attempted, then only the best FOUR will count.
You may consult lecture notes.
7CCMFM13
FOLLOW the instructions you have been given on how to upload your solutions
Mock Exam 2020 ⃝c King’s College London
1.
(i) Write a function max(double, double) which takes two doubles and returns the maximum of them. [20%]
(ii) Write a function mean which takes as input a vector of doubles (using
(iii) What’s wrong with the following code?
7CCMFM13
[20%]
int& Setx(){
int x=3;
return x;
}
(iv) What does the following code print out and why?
[20%]
# include
using namespace std;
void MyFunction(double& a){
a*=10;
}
int main() {
double a=1;
MyFunction(a);
cout< path(NSteps, 0.0);
double total=0.0;
double payoff;
for (int i=0;i
int NSteps) const;
… };
7CCMFM13
};
double PutOption::payoff(double x) const
{
if (x