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 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).

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

The source code should also be well formatted according to Google’s C++ guidelines and this will be checked against cpplint as described in the previous project.

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 from outside your group.

PROBLEM 1 Calculate Students grades for different courses in C++

Essay: Discuss the use cases for different types of STL container (1000 words)

Collaboratively write an essay on use cases of the different types of STL containers. Only the first 1000 words will be marked.

Coding problem

In this project, we’ re going to set up a demonstration of Polymorphism, I’m going to try and bring together a few strands that I find useful across computing, especially data science. To that end we’ re going to use Regular Expressions, command-line arguments and JSON file manipulation using a JSON library available through NuGet in Visual Studio ( https://github.com/nlohmann/json).     We’ve done some work with regular expressions in the week 10 lecture about dates, and some work serializing a class into JSON and back again in the week 11 zip file.

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 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, 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() <

This gets more useful when you’ re working with massive numbers of objects in a structure like a vector e.g. vector . 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. 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.

So for the main static library project, were going to need;

A CourseResult object containing:

Variables

score (double) in the interval (0-100)

result for the course (bool)

Methods

Constructor taking score and result in that order

getScore method returning score

getResult method returning result

A student class containing;

Variables

identifier (string of format yyxxxxxxxx, where y are letters A-Z and x are numbers 0-9)

givenName (string

familyName (string)

email

a map (grades) linking course code to the marks for each assignment in the course, treat the first value as an exam grade, in appropriate. All grades are double in range(0-100)

a map (results) linking course code to a CourseResult object.

Functions

Constructor

Contructor from a csv file (

getIdentifier, getGivenName, getFamilyName, getEmail, getGrades, and getResults

methods validateIdentifier, validateEmail to return for valid entries, returns std::smatch.

method getGrades(std::string courseCode, std::vector * grades) which returns the results for the a course code through a parameter, returning true if course found, false if not.

method populateResults(courseHolder ) supply the courseholder object and use that to fill the results map. method needsResit() returns true if any of the courses have failed.

method numberOfCredits(courseHolder) returning an int which is the sum of all the credits the student is enrolled on

A Course abstract base class

Variables

std::string identifier (yyyxxx, where y are letters A-Z and x are numbers 0-9)

std::vector weights each in range (0-100). All the members of this must

an variable called numberOfCredits which uses an enum Credits taking values TenCredits and TwentyCredits Functions

Constructor

validateCourseCode returns smatch

validateWeight returns true if weights add up to 100.

getNumberOfCredits

a pure virtual method getGrade(std::vector) that takes a students grade list

A derived Course class ExamOnly Functions an implementation of getGrade (note that students can only pass if they get more than forty percent in the exam)

A derived Course class Hybrid Functions an implementation of getGrade (note that students can only pass if they get more than forty percent in the exam and overall in coursework

A derived Course class CourseworkOnly Functions an implementation of getGrade (note that students can only pass if they get more than forty percent overall in the coursework.

Two classes; studentHolder and courseHolder; these provide methods to store maps of student identifier to student object, and course identifier to a pointer to course object.

studentHolder should contain a method to run getGrades for each course.

studentHolder should contain a method to produce nicely formatted output, which you can use from

MarkingApplication.

As always include any other functions and members if that makes your task easier.

I expect three projects,

a static library called Marking

a Google test project called Marking-test

a Console executable project called MarkingApplication

When loading the data, the data should be checked using the validate functions. You can load data programmatically, from CSV, or JSON for either the students or the courses. Note that due to the derived classes, deserializing data (technical term for            constructing objects from a text file) is quite a bit harder, as you have to find the type in the text, and then construct the                 appropriate object. To do this, you might

Marking Application should take a file of students and a file of courses and print out lines of the following format ,,, These should be alphabetically sorted by studentName and course.

Marking Application should also take flags using the getopts library

(https://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html)and if given the “-r” flag display an alphabetical list of students requiring resits.

An example of this would be; “MarkingApplication -r student_list_file’ ‘course_list_file’”

I will award extra marks to anyone using a Logger to output data to where errors can be written; plog on NuGet looks simple, but the standard is anything that looks like log4j (the java version), such a log4cpp.

Bear in mind a significant part of this project will be taken up with generating test data, and doing that first can guide your development. I used python’s mimesis library for some of the student library.

Marks Scheme

For this project, this is likely to be somewhat arbitrary, on the grounds that if you do something good, I want to be able to give you marks for it and not be told I can’t do it due to a mark scheme I wrote earlier, but use this as a guide.

essay (10%)

a visual studio 2019 solution that compiles and has the three projects described earlier (5%).

all .cpp and .h files submitted passing the cpplint checks (5%).

Programmatically loading student data (5%), rising to 10% for reading in from a csv file, and 20% for importing from JSON. Programmatically loading course data (5%), rising to 10% for reading in from a csv file, and 20% for importing from JSON. Correctly implementing an inheritance system (10%) and polymorphism (10%).

Implementing MarkingApplication (10%).

Writing tests using google test to cover a significant amount of the code (10%).

Using a logger to output debug information to a text file (10%).

Although theres 110% available, the total mark is capped at 100%.

Ill aim to get more specifics and a test file out to you ASAP, but I want you to have something to be going on with.