收藏 分享(赏)

第6章计算机学科基础.ppt

上传人:gnk289057 文档编号:9358227 上传时间:2019-08-03 格式:PPT 页数:47 大小:5.54MB
下载 相关 举报
第6章计算机学科基础.ppt_第1页
第1页 / 共47页
第6章计算机学科基础.ppt_第2页
第2页 / 共47页
第6章计算机学科基础.ppt_第3页
第3页 / 共47页
第6章计算机学科基础.ppt_第4页
第4页 / 共47页
第6章计算机学科基础.ppt_第5页
第5页 / 共47页
点击查看更多>>
资源描述

1、Chapter 6,Problem Solving and Algorithm Design 问题求解和算法设计,6-2,Chapter Goals 本章目标,Determine whether a problem is suitable for a computer solution确定一个问题是否适合用计算机解决 Describe the computer problem-solving process and relate it to Polyas How to Solve It list结合Polya提出的如何解决问题的列表,描述计算机问题求解的步骤 Distinguish betwe

2、en following an algorithm and developing one区别执行算法和开发算法 Apply top-down design methodology to develop an algorithm to solve a problem应用自顶向下的方法开发算法来解决问题,6-3,Chapter Goals,Define the key terms in object-oriented design定义面向对象设计方法中的术语 Apply object-oriented design methodology to develop a collection of in

3、teracting objects to solve a problem应用面向对象的方法开发一组互动对象来解决问题 Discuss the following threads as they relate to problem solving: information hiding, abstraction, naming things, and testing求证与问题求解相关的几点思想,6-4,Problem Solving 问题求解,Problem solving The act of finding a solution to a perplexing, distressing, v

4、exing, or unsettled question问题求解:找到令人感到困惑的难题的解决方案的行动。,6-5,Problem Solving 问题求解,G. Polya wrote How to Solve It: A New Aspect of Mathematical Method如何解决它:数学方法的新视点 His How to Solve It list is quite general他的“如何解决它”这个列表是普遍适用的 Written in the context of solving mathematical problems 在解决数学问题这个背景下编写的 The li

5、st becomes applicable to all types of problems 这个列表完全适用于各种类型的问题,6-6,Ask Questions. 提出问题,to understand the problem What do I know about the problem? 对这个问题我了解多少? What is the information that I have to process in order the find the solution? 要找到解决方案我必须处理哪些信息? What does the solution look like? 解决方案是什么样的

6、?,6-7,Ask Questions. 提出问题,What sort of special cases exist? 存在什么特例? How will I recognize that I have found the solution? 我如何知道已经找到了解决方案了?,6-8,如何解决它?,第一步 必须理解问题 第二步 找到信息和解决方案之间的联系。如果找不到直接的联系,则可能需要考虑辅助问题。最终,应该得到解决方案。 第三步 执行方案 第四步 分析得到的解决方案,6-9,Look for Familiar Things 寻找熟悉的情况,You should never reinvent

7、 the wheel In computing, you see certain problems again and again in different guises在计算领域中,你会看到某种问题不断地以不同的形式出现。 A good programmer sees a task, or perhaps part of a task (a subtask), that has been solved before and plugs in the solution 一个好的程序员看到以前解决的任务或者任务的一部分时,会直接选用已有的解决方案。,6-10,Divide and Conquer

8、 分治法,Break up a large problem into smaller units that we can handle把一个大的问题分解为一些小的能够处理的部分。 Applies the concept of abstraction The divide-and-conquer approach can be applied over and over again until each subtask is manageable,6-11,Algorithms 算法,Algorithm A set of instructions for solving a problem or

9、 subproblem in a finite amount of time using a finite amount of data在有限的时间内用有限的数据解决问题或子问题的指令集合。 The instructions must be unambiguous指令必须是明确。,6-12,Computer Problem-Solving 计算机问题求解,Figure 6.2 The computer problem-solving process,6-13,Computer Problem-Solving 计算机问题求解,算法开发阶段 分析 理解(定义)问题 提出算法 开发用于解决问题的逻辑

10、步骤序列 测试算法 执行列出的步骤,看它们是否能真正地解决问题 实现阶段 编码 用程序设计语言翻译算法 测试 让计算机执行指令序列。检查结果,修改程序,直到得到正确的答案。 维护阶段 使用 使用程序 维护 修改程序,使它满足改变了的要求,或者纠正其中的错误。,6-14,Figure 6.3: The Interactions Between Problem-Solving Phases,问题求解阶段,实现阶段,6-15,Pseudocode 伪代码,Uses a mixture of English and formatting to make the steps in the solutio

11、n explicit,当商不为0用新基数除这个十进制数把余数作为答案左边的下一个数字把商替代这个十进制数,6-16,Following an Algorithm,Preparing a Hollandaise sauce 蛋黄奶油酸辣酱的做法,Figure 6.4,6-17,Following an Algorithm,Preparing a Hollandaise sauce,Page 150,6-18,Developing an Algorithm 开发算法,The plan must be suitable in a suitable form执行方案必须转换成计算机能够执行的形式 Tw

12、o methodologies that currently used Top-down design 自顶向下设计 Object-oriented design 面向对象设计,6-19,Top-Down Design 自顶向下设计,Breaking the problem into a set of subproblems called modules把问题分解成为一套称为模块的子问题 Creating a hierarchical structure of problems and subproblems (modules)构造一种包含问题和子问题的分层结构,6-20,Top-Down D

13、esign,This process continues for as many levels as it takes to expand every task to the smallest details A step that needs to be expanded is an abstract step,Figure 6.5 An example of top-down design,6-21,A General Example,Planning a large party,Figure 6.6 Subdividing the party planning,6-22,A Comput

14、er Example,Problem Create an address list that includes each persons name, address, telephone number, and e-mail address This list should then be printed in alphabetical order The names to be included in the list are on scraps of paper and business cards,6-23,A Computer Example,Page 156,6-24,A Compu

15、ter Example,Page 157,6-25,A Computer Example,Page 158,6-26,A Computer Example,Page 159,6-27,Testing the Algorithm 测试算法,The process itself must be tested过程自身必须经过测试 Testing at the algorithm development phase involves looking at each level of the top-down design算法开发阶段中的测试要查看自顶向下设计中的每个层次,6-28,Testing th

16、e Algorithm 测试算法,Desk checking 桌面检查 Working through a design at a desk with a pencil and paper Walk-through 走查 Manual simulation of the design by the team members, taking sample data values and simulating the design using the sample data Inspection 审查 One person (not the designer) reads the design (

17、handed out in advance) line by line while the others point out errors,6-29,Object-Oriented Design 面向对象设计,A problem-solving methodology that produces a solution to a problem in terms of self-contained entities called objects Object A thing or entity that makes sense within the context of the problem

18、对象是在问题背景中具有意义的事物或者实体。For example, a student,6-30,Object-Oriented Design 面向对象设计,A group of similar objects is described by an object classs对象类, or class类 A class contains fields that represent the properties and behaviors of the class A field can contain data value(s) and/or methods (subprograms) 域表示

19、类的属性和行为 A method is a named algorithm that manipulates the data values in the object 方法是处理对象中的数据的制定方法,6-31,Relationships Between Classes 类之间的关系,Containment 包容 “part-of” An address class may be part of the definition of a student class Inheritance 继承 Classes can inherit data and behavior from other c

20、lasses “is-a” Collaboration 协作 One class calls upon another class to provide information or a service,6-32,继承的实例,动物,哺乳动物,狗,爬行动物,马,棕色狗,白色狗,6-33,Object-Oriented Design Methodology,Four stages to the decomposition process Brainstorming 头脑风暴 Filtering 过滤 Scenarios 场景 Responsibility algorithms 责任算法,6-34,

21、CRC Cards,Page 165,类名,超类,子类,责任,协作,6-35,Brainstorming 头脑风暴(集体讨论),A group problem-solving technique that involves the spontaneous contribution of ideas from all members of the group All ideas are potential good ideas Think fast and furiously first, and ponder later A little humor can be a powerful for

22、ce Brainstorming is designed to produce a list of candidate classes,6-36,Filtering 过滤,Determine which are the core classes in the problem solution There may be two classes in the list that have many common attributes and behaviors There may be classes that really dont belong in the problem solution,

23、6-37,Scenarios 场景,Assign responsibilities to each class给每个类分配责任 There are two types of responsibilities What a class must know about itself (knowledge responsibilities) 类自身必须知道什么 What a class must be able to do (behavior responsibilities)类必须能够做什么,6-38,Scenarios 场景,Each class encapsulates 封装 its data

24、 but shares their values through knowledge responsibilities. Encapsulation封装 is the bundling of data and actions in such a way that the logical properties of the data and actions are separated from the implementation details封装是把数据和行为集中起来,使数据和行为的逻辑属性与它们的实现细节分离。,6-39,Responsibility Algorithms 责任算法,The

25、 algorithms must be written for the responsibilities Knowledge responsibilities usually just return the contents of one of an objects variables知识责任通常只返回一个对象的变量的内容。 Action responsibilities are a little more complicated, often involving calculations行为责任复杂一些,通常涉及到计算。,6-40,Computer Example,Lets repeat t

26、he problem-solving process for creating an address list Brainstorming and filtering Circling the nouns and underlining the verbs,Page 171,Computer Example,First pass at a list of classes,Page 172,6-37,Computer Example,Filtered list,Page 172,6-38,6-43,CRC Cards,Page 173,6-44,Responsibility Algorithms

27、,Page 175,6-45,Information Hiding/Abstraction 信息隐蔽/抽象,Information Hiding and Abstraction are two sides of the same coin. Information Hiding The practice of hiding the details of a module with the goal of controlling access to the details of the module. 隐蔽模块细节以控制对这些细节的访问的做法 Abstraction A model of a c

28、omplex system that includes only the details essential to the viewer.复杂系统的一种模型,只包括对观察者来说必须的细节,6-46,Information Hiding/Abstraction,Abstraction is the result with the details hidden Data abstraction Separation of the logical view of data from their implementation. Procedural abstraction Separation of

29、the logical view of actions from their implementation. Control abstraction Separation of the logical view of a control structure from its implementation.,6-47,Programming Languages,Instructions written in a programming language can be translated into the instructions that a computer can execute directly Program 程序 A meaningful sequence of instructions for a computer Syntax 语法 The part that says how the instructions of the language can be put together Semantics 语义 The part that says what the instructions mean,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报