ImageVerifierCode 换一换
格式:PPT , 页数:59 ,大小:290KB ,
资源ID:7356055      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7356055.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Data Structures with C++ using STL 2E Chapter 2.ppt)为本站会员(j35w19)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

Data Structures with C++ using STL 2E Chapter 2.ppt

1、1,Software Design Overview (2)Software Design Stages (3 slides)Program Design -The Traditional Approach (3)calendar Class (3 slides)date Class (2 slides)Implementing the Calendar ClassError Handling -Program Termination (2 slides) -Setting a Flag (3 slides),Chapter 2 Object Design Techniques,C+ Exce

2、ptions (3 slides)Object Composition timeCard Class (3 slides)Implementing timeCard Class -Constructor -punchOut()Operator Overloading -With Free Functions (3 slides) -With Friend Functions (2 slides) -Stream I/O OperatorsOperator Functionstime24 Class (5 slides)Member Function Overloading -Implement

3、ationSummary Slides (15 slides),2,Software Design Overview,A computer program begins with a problem that the client wants solved. The process of building the program starts with an analysis of the problem. It proceeds through a series of stages to produce a product that is reliable and easy to maint

4、ain.,3,Software Design Overview,Prior to the standardization of the software development life cycle: Programmers added code to software with little attention to its integration into the system. Over time systems deteriorated and became so difficult to update that programmers had to develop new softw

5、are to replace them.,4,Software Design Stages,Request: Client perceives a need for a software system to solve a problem. A computer consultant undertakes a feasibility study for the project. Analysis: A systems analyst develops the requirements of the system and creates a functional specification th

6、at includes a list of needs and special requirements.,5,Software Design Stages,Design: Translate the functional specification into an abstract model of the system. Identify the components of the system and develop algorithms that will be used for implementation. Implementation: Use a programming lan

7、guage and the design specification to code the different components of the system.,6,Software Design Stages,Testing: Check the program for logical and runtime errors and verify that the system meets the specifications of the client. Maintenance: Periodically update of the software to stay current an

8、d to respond to changing needs of the client.,7,Program Design The Traditional Approach,The design phase of the software development life cycle translates the functional specifications from the analysis phase into an abstract model. The traditional design approach uses a top-down strategy. The model

9、 views a system as a layered set of subprograms. Execution begins in the main program and information flows in the system through a series of function calls and return values.,8,Program Design The Traditional Approach,When the problem becomes too large this approach can fail: The complexity overwhel

10、ms the ability of a single person to manage the hierarchy of subprograms. Design changes in subprograms near the top of the hierarchy can require expensive, time-consuming changes in the subprograms at lower levels in the chart.,9,Program Design The Traditional Approach,10,11,12,13,date Class,14,dat

11、e Class,15,Implementing the calendar Class,setMonth() : / update the current month void calendar:setMonth(int mm) / verify that mm is a valid month if (mm 12)throw dateError(“calendar setMonth():“,mm, “invalid month“);/ set d to new month d.setMonth(mm); ,16,Error handling: Program Termination,Imple

12、menting duration() by terminating the program in case of error: time24 time24:duration(const time24/ if t is earlier than the current time, / throw an exception,17,Error handling: Program Termination,if (tTime currTime) cerr “time24 duration(): argument is an earlier time“ endl;exit(1); elsereturn t

13、ime24(0, tTime-currTime); ,18,Error Handling: Setting a Flag,Implementing duration() with an error flag: time24 time24:duration(const time24,19,Error Handling: Setting a Flag,/ assume that no error will occur success = true;/ if t is earlier than the current time, / assign false to success if (tTime

14、 currTime) success = false;else/ successful. assign duration to / returnTimereturnTime = time24(0, tTime-currTime);return returnTime; ,20,Error Handling: Setting a Flag,The programmer can have the calling statement check the result of duration() by placing the call within a conditional expression. b

15、ool success; time24 currTime, nextTime, interval;. interval = currTime.duration(nextTime, success); if (success = false) / check success and deal with an error ,21,C+ Exceptions,22,C+ Exceptions,Implementing duration() by throwing an exception:time24 time24:duration(const time24,23,C+ Exceptions,/ i

16、f t is earlier than the current time, / throw an exceptionif (tTime currTime)throw rangeError(“time24 duration(): argument is an earlier time“);else return time24(0, tTime-currTime); ,24,Object Composition,Object Composition: refers to a condition that exists when a class contains one or more data m

17、embers that are objects of class type. Class included by composition = supplier class.Class that includes an object by composition = client class.,25,26,27,28,Implementing the timeCard Class: Constructor,Constructor: / use initialization list to initialize / data members. timeCard:timeCard(const str

18、ing& ssno, double rate, int punchInHour, int punchInMinute):workerID(ssno), payrate(rate), hasPunched(false),punchInTime(punchInHour, punchInMinute) ),29,Implementing the timeCard Class: punchOut(),punchOut(): void timeCard:punchOut(const time24 ,30,Operator Overloading,For programmer-defined object

19、s, functions are needed to enable the comparisons. Example: / compare two time24 objects bool equalTime(const time24 ,31,Operator Overloading - with Free Functions,Operators may be overloaded as free functions or as class member functions. The concepts have important differences; their syntax is dea

20、lt with separately.,32,Operator Overloading - with Free Functions,A free function could be used to compare two class objects.,/ compare two class objects bool equalItem(const className ,33,Operator Overloading - with Free Functions,The same comparison can be made using operator overloading.,bool ope

21、rator= (const className,34,Operator Overloading - With Friend Functions,Overloading an operator as a free function raises efficiency issues:The function is independent of the class Its implementation must use member functions to access the appropriate data members. If a class does not provide the ap

22、propriate access functions, The operator cannot be overloaded as a free function.,35,Operator Overloading - With Friend Functions,C+ allows a free function to be declared as a friend function in the class:A friend function has access to the private members of the class. Denoted in the class declarat

23、ion by placing the keyword friend immediately before its prototype. Despite having access to the private data members, a friend is not a member function of the class.,36,Operator Overloading - Stream I/O Operators,A class can overload the stream operators as friend functions. operator function proto

24、type for each operation:(Output) : istream,37,Assume the string s = “Hello“ and t = “ World!“. The string expression s + t returns a string that is the concatenation of s and t. The op. function for the op. + with arguments lhs and rhs and return type string is,Operator Functions,string operator+ (c

25、onst string,38,39,40,41,42,43,Member Function Overloading,/ update time by adding a time24 object / or an int time24 / lhs += min,44,Member Function Overloading -Implementation-,/ implement += by using addition with / operands *this and rhs time24 ,45,Summary Slide 1,- The software life cycle consis

26、ts of: A Request phase An Analysis phase A Design phase An Implementation phase A Testing phase The Maintenance phase - All share equal importance in the Software Development Lifecycle,46,Summary Slide 2,- The request phase- Meet with the client to discuss the needs and requirements for a software s

27、ystem.- Perform a feasibility study to see if building a software system is cost effective.,47,Summary Slide 3,- The analysis phase- Determine the system requirements.- Systems analyst determines requirements and is the intermediary between the client and the software engineers.- Result: a functiona

28、l specification of the software system that includes a list of needs and special requirements.,48,Summary Slide 4,- The design phase (continued)- Translate data from the analysis phase into an abstract model of the problem.- Identify the objects which are the building blocks of the program. - Determ

29、ine how these objects should collaborate and interact to solve the problem.,49,Summary Slide 4a,- The design phase cont - Create the declaration of the classes including their attributes and public member functions. - Describe how the classes are related to each other- Design the algorithms that all

30、ow the classes to effectively interact.,50,Summary Slide 5,- The implementation phase- Convert the design into a program.- Implement the classes independently and verify the action of their member functions.- Implement program units that coordinate object interaction. - code the main program that ma

31、nages the overall execution of the software system. - Often, the implementation stage will discover errors or oversights in design.,51,Summary Slide 6,- The Testing Phase- Analysis, design, and implementation phases interact to bring about modifications and corrections to the specifications and the

32、code. - effective interaction among the phases depends on frequent and systematic testing.- Test the classes and functions which are the individual units of the software system- perform integrative testing to ensure that the units fit together to create a program that runs correctly and efficiently.

33、,52,Summary Slide 7,- Program maintenance phase- Begins as soon as the client installs the system. - The client will identify bugs or features that must be changed or added.- A client may add new hardware and/or find new applications for the software. - Modern software systems must be regularly upgr

34、aded or they will eventually become obsolete and unusable.,53,Summary Slide 8,- Handling errors during function execution is an important aspect of program design.- There are three fundamental ways to handle errors: Output an error message and terminate the program. - Generally avoided unless necess

35、ary. Return a Boolean flag from the function call indicating that an error occurred. - Grants the advantage of leaving the decision about how to handle the error to the calling code block. use the C+ exception mechanism. - The best approach.,54,Summary Slide 9,- C+ exceptions are handled by three ke

36、ywords: - try- Function calls and code that may generate an exception are placed in a try block.,55,Summary Slide 9a,- catch- The exception handler.- Outputs an error message and either takes corrective action or terminates the program.,56,Summary Slide 9b,- throw- Bypasses the normal function retur

37、n mechanism searches chain of previous function calls until it locates a catch block.,57,Summary Slide 10,- Operator overloading:- important feature of object design in C+.- redefines an operator to accept operands of the class type. - Designing a class to take advantage of familiar operator notatio

38、n makes the class easier to use and extends its flexibility.,58,Summary Slide 11,- 1st way to overload an operator:- implement a free function using the operator function format. - requires the use of class member functions that give the function access to the private data of an object. - 2nd way to

39、 overload an operator- declare an operator function as a friend of a class. - The function is not a class member but has access to the private section of the class. - This technique avoids calling class access functions.,59,Summary Slide 12,- Some operators must be overloaded as class member functio

40、ns.- Overload unary operators and binary operators that modify an object as member functions. - An operator overloaded in this fashion has one less operand than the corresponding operator function. - In the case of a binary operator, the left operand is the object itself, and the right operand is the argument.- A unary operator has no argument list.,

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


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

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

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