D语言编程指南:免费英文教程

需积分: 1 1 下载量 190 浏览量 更新于2024-07-23 收藏 2.12MB PDF 举报
“Programming in D”是一本由Ali Çehreli编写的关于D语言的开发教程,它提供了一个免费的英文学习资源,与之前的版本有所不同。该教程的内容基于ddili.org论坛和维基页面的集体智慧,并在Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License下授权。此外,用户可以在ddili.org网站上找到最新的PDF版本,以获取关于D语言编程的最新修订和更新。 D语言是一种高效、现代的系统编程语言,设计时兼顾了性能和生产力。本书“Programming in D”涵盖了D语言的基础到高级主题,旨在帮助读者全面掌握该语言。以下是一些关键章节的概述: 1. **Memory Management(内存管理)**:D语言支持自动垃圾回收,但也允许手动内存管理。这一章深入探讨了内存分配、释放、智能指针以及如何有效地处理内存,包括使用`new`和`delete`操作符,以及使用`scope`关键字来确保资源的正确清理。 2. **Type Traits(类型特性)**:D语言提供了丰富的类型系统,包括类型特性和条件编译。类型特性允许在编译时检查和操作类型属性,这对于编写泛型代码和模板非常有用。 3. **Data Sharing Concurrency(数据共享并发)**:D语言提供了强大的并发原语,如`mutex`、`semaphore`和`atomic`类型,使得在多线程环境中安全地共享数据成为可能。这一章详细介绍了这些工具以及如何避免竞态条件和死锁。 4. **More Functions(更多函数)**:除了基础的函数定义和调用,D语言还支持函数指针、闭包和函数对象。这部分内容可能涵盖函数作为参数、递归函数以及高阶函数的概念。 5. **Mixins(混入)**:混入是D语言的一个独特特性,允许在编译时将一个模块的源代码插入到另一个模块中,这有助于代码复用和创建元编程解决方案。 6. **More Ranges(更多范围)**:D语言的范围概念提供了一种高效的迭代方式,减少了对显式索引和数组遍历的需求。这部分可能讲解了范围的创建、自定义范围以及范围操作符的使用。 7. **Tuples(元组)**:元组允许在一个变量中存储多个不同类型的数据,方便临时数据结构的创建和传递。 8. **More Templates(更多模板)**:D语言的模板功能强大,可以用于泛型编程。这部分可能涵盖了模板的高级用法,如模板元编程和模板约束。 9. **Constants and Const-Correctness(常量和常量正确性)**:D语言强调常量正确性,这意味着在编写代码时需要考虑到值是否可变。这一章可能讨论了如何正确使用`const`关键字以及其在类型系统中的作用。 通过阅读和实践“Programming in D”的各个章节,读者可以逐步熟悉D语言的语法、特性,并能够运用这些知识开发出高效、可靠的软件。教程的持续修订确保了内容的时效性和准确性,为学习者提供了最新的D语言编程指南。

(a) Consider the case of a European Vanilla Call option which is path independent. Examine the convergence of the Monte Carlo Method using the programme given in ‘MC Call.m’. How does the error vary with the number of paths nP aths? The current time is t = 0 and the Expiry date of the option is t = T = 0.5. Suppose that the current value of the underlying asset is S(t = 0) = 100 and the Exercise price is E = 100, with a risk free interest rate of r = 0.04 and a volatility of σ = 0.5. (b) Now repeat part (a) above but assume that the volatility is σ = 0.05. Does the change in the volatility σ influence the convergence of the Monte Carlo Method? (c) Now repeat part (a) but instead of taking one big step from t = 0 to t = T divide the interval into nSteps discrete time steps by using the programme given in ‘MC Call Small Steps.m’. Confirm that for path independent options, the value of nP aths determines the rate of convergence and that the value of nSteps can be set to 1. (d) Now let us consider path dependent options. The programme given in ‘MC Call Small Steps.m’ is the obvious starting point here. We assume that the current time is t = 0 and the expiry date of the option is t = T = 0.5. The current value of the underlying asset is S(t = 0) = 100 and the risk free interest rate is r = 0.05 and the volatility is σ = 0.3. (i) Use the Monte Carlo Method to estimate the value of an Arithematic Average Asian Strike Call option with Payoff given by max(S(T) − S, ¯ 0). (ii) Use the Monte Carlo Method to estimate the value of an Up and Out Call option with Exercise Price E = 100 and a barrier X = 150. (iii) Comment on the the rate of convergence for part (i) and (ii) above with respect to the parameters nP aths and nP aths使用matlab编程

2023-06-11 上传

The programme should have the following features: ● A menu including Open and Exit where Open starts a JFileChooser to select the file with the questions inside and Exit ends the programme. ● Once a file is loaded, the GUI should display one question and its answers at a time. ● The user should be able to select an answer and they should be informed if they were correct or not. ● The user should be made aware of the number of correctly answered and the total number of questions answered. ● The user should only be able to proceed to the next question once they answered the current one. ● Once all questions have been answered, the user should be informed of their overall score and that the game has finished. The Open menu item should now be enabled to start a new quiz. Optionally, you can add a restart menu item to redo the current quiz. Concrete sub-tasks: a) define a class called Question to hold a single question, i.e. the text, the possible answers, and the correct answer index; (0.25P) b) write a method to select a file via a JFileChooser and to read all the questions from that file into an array/list of Question objects (assume that file has the structure mentioned above); (0.25P) c) design and implement a GUI with the components mentioned above: A menu, ability to display the question and answers, ability to select an answer, show the outcome and score, and proceed to the next question. (Appropriate layout: 1P, Class extends JFrame: 0.25P, Class follows OOP principles: 0.25P, Global set-up in main method: 0.25P)1 d) write a method to display a question on the GUI you designed; (0.25P) e) implement an actionPerformed method to respond to user interactions with the GUI. Make sure to enable and disable interactive components as required, e.g. the user should not be able to skip to the next question without selecting an answer first and they should not be able to load a new quiz before finishing the current one;

2023-05-29 上传