1. Trang chủ
  2. » Công Nghệ Thông Tin

Procedural Abstraction and Functions That Return a Value

94 541 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 94
Dung lượng 2,85 MB

Nội dung

Procedural Abstraction and Functions That Return a Value

Chapter Procedural Abstraction and Functions That Return a Value Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables 4.6 Overloading Function Names Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 4.1 Top-Down Design Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Top Down Design  To write a program  Develop the algorithm that the program will use  Translate the algorithm into the programming language  Top Down Design (also called stepwise refinement)  Break the algorithm into subtasks  Break each subtask into smaller subtasks  Eventually the smaller subtasks are trivial to implement in the programming language Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- Benefits of Top Down Design  Subtasks, or functions in C++, make programs  Easier to understand  Easier to change  Easier to write  Easier to test  Easier to debug  Easier for teams to develop Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- 4.2 Predefined Functions Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Predefined Functions  C++ comes with libraries of predefined functions  Example: sqrt function  the_root = sqrt(9.0);  returns, or computes, the square root of a number  The number, 9, is called the argument  the_root will contain 3.0 Copyright © 2007 Pearson Education, Inc Publishing as Pearson Addison-Wesley Slide 4- Function Calls   sqrt(9.0) is a function call  It invokes, or sets in action, the sqrt function  The argument (9), can also be a variable or an expression A function call can be used like any expression  bonus = sqrt(sales) / 10;  Cout

Ngày đăng: 12/09/2012, 22:48

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w