Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Final Project

LM Advanced Mathematical Finance Module

Part B C++ Spring Term 2021

INSTRUCTIONS FOR THE SUBMISSION

Submit your code on Canvas as a zip file:

Submit as a single zip file containing all the code for the problem.

The source files should compile without errors or warnings on Visual Studio 2019 as installed on the clusters, and the     resulting executables should run without problems, Using debug and x64 build options . You should delete the “ .vs” and run clean on the solution in Visual Studio, before compressing to keep the file size down.

You do not have to submit the executable. You should comment your code and describe what each function does and you should use intelligible naming, the only exception being i, j, and k for any loop counters.

If you use another compiler other than Visual Studio, you should take your final code and compile it on Visual Studio on the remote clusters (https://remoteclusters.bham.ac.uk/maps).

I really can’t stress enough that the better pieces of work were obviously written in Visual Studio 2019. Mistakes creep in during the conversion process.

Unfortunately, different compilers follow slightly different rules, and even a small difference may cause the code to fail on Visual Studio.

PLAGIARISM

You are not allowed to plagiarise. This means that you are not allowed to directly copy the code from any online sources or any of your fellow students.

PROBLEM 1 Finish the Chess game Ive started writing.

Essay: Talk about the problems of pointers and the solutions to this.(1000 words)

Write an essay on the problems of pointers and the solutions referring to things like unique_ptr. Only the first 1000 words will be marked.

Coding problem

Often in computing, we’ re faced with a situation where we are dealing with types that share nearly all the same properties and       methods but might only require a small tweak from each other. We do this by setting up a chain of inheritance, where a derived     class inherits a large amount of behavior and properites from its superclass. Additionally, the superclass can make the compiler    enforce that any derived classes implement a method. It’s important to note that you never need to be able to create objects of the superclass; it can be called an abstract class. The size of the inheritance chain is unlimited in C++.

Ideally, we’d like to call these different methods in exactly the same way, even though we’ re trying to get different results, and a    way of handling that in Object-Orientated code is known as Polymorphism. This means we can treat all the objects as the              superclass and call a method declared in the superclass. So as an example from Week 11; if you have a shape class (superclass) that has properties (area) that are shared with all types of shapes e.g. (derived classes) Triangle, Square, Rectangle … . If we

create a pure virtual function in shape (by setting the function =0, after the parameter brackets), that makes the shape class virtual and is done like this in the shape header.

class shape :

{

. . .

virtual double area()=0; //not defined here, all classes inheriting from this must implement this .

}

class rectangle : public shape

{

. . .

virtual double area(){

return height * width;

};

}

Now you can never create a shape, but you can use shape to refer to any derived class; e.g.

Shape s = Rectangle(2,3);

std : :cout << s .area() <<std : :endl;

This gets more useful when you’ re working with massive numbers of objects in a structure like a vector e.g. vector<shape>. There is a catch though, a vector or other stl class needs to know the size of the object you put into it and that depends on the size of the class with polymorphism. To get around this, you have to create the object on the heap and store the pointer into the vector, so it   needs to be vector<shape*>. A practical use case was where I was writing a graph application and I wanted differently styled         points for different datasets. Each dataset’s point objects were inherited from point and had a render method that was different for each dataset. Using polymorphism meant I didn’t have to worry about the datasets and could just call render() on each of the         points without worrying about testing for the type. Also if I wanted to add a new design, I didn’t have to change any of the code       calling render.

Brief description

I’ve built a chess game, but it’s unfortunately not finished yet. Your job for this assignment is to finish the code. I stress that you should only code as if the game is to played between two humans, you should not attempt to create a computer player, but you could see how this could be done based from this code.

I’ve implemented the Move method for the Knights (easiest piece, I think). I would next do Rooks, but ignore Castling to begin     with, but I advise you to study the code for at an hour or two in debug to see how it works. There is no guarantee any of the code here works, and if you find a bug, you will gain credit for spotting it, and more for solving it.

You also need to flesh out Board::validMovePossible() which determines when the games ends, and Board::IsKingInCheck which determines if a move is legal. No move is legal if it leaves the king in check, or places the king in check.

Additional things you could implement are:

 Pawns being able to move two spaces on first move.

 En Passant

 Castling

 Promotion (Will require a menu)

 Draw (quite complicated)

You should test your work thoroughly using a Google test

You should not add any other files, or add any other libraries via includes. Eveything you need for this assignment should be here.

Marks Scheme

For this project, 15% of the marks will be awarded for the essay and the remainder for the appropriateness of the overall attempt  at a solution. It is important that you ensure your submitted work compiles successfully in Visual Studio 2019 - if it does not do so, then your work will be unable to be marked.