Giáo trình tin học chương 3
Số trang: 78
Loại file: pdf
Dung lượng: 266.13 KB
Lượt xem: 20
Lượt tải: 0
Xem trước 8 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
3.2 Program Components in C++• Modules: functions and classes• Programs use new and “prepackaged” modules– New: programmer-defined functions, classes– Prepackaged: from the standard library • Functions invoked by function call– Function name and information (arguments) it needs• Function definitions– Only written once– Hidden from other functions
Nội dung trích xuất từ tài liệu:
Giáo trình tin học chương 3 1 Chapter 3 - Functions Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number Generation 3.9 Example: A Game of Chance and Introducing enum 3.10 Storage Classes 3.11 Scope Rules 3.12 Recursion 3.13 Example Using Recursion: The Fibonacci Series 3.14 Recursion vs. Iteration 3.15 Functions with Empty Parameter Lists 2003 Prentice Hall, Inc. All rights reserved. 2 Chapter 3 - Functions Outline 3.16 Inline Functions 3.17 References and Reference Parameters 3.18 Default Arguments 3.19 Unary Scope Resolution Operator 3.20 Function Overloading 3.21 Function Templates 2003 Prentice Hall, Inc. All rights reserved. 3 3.1 Introduction • Divide and conquer – Construct a program from smaller pieces or components – Each piece more manageable than the original program 2003 Prentice Hall, Inc. All rights reserved. 4 3.2 Program Components in C++ • Modules: functions and classes • Programs use new and “prepackaged” modules – New: programmer-defined functions, classes – Prepackaged: from the standard library • Functions invoked by function call – Function name and information (arguments) it needs • Function definitions – Only written once – Hidden from other functions 2003 Prentice Hall, Inc. All rights reserved. 5 3.3 Math Library Functions • Perform common mathematical calculations – Include the header file • Functions called by writing – functionName(argument1, argument2, …); • Example cout 6 3.3 Math Library Functions • Function arguments can be – Constants • sqrt( 4 ); – Variables • sqrt( x ); – Expressions • sqrt( sqrt( x ) ) ; • sqrt( 3 - 6x ); 2003 Prentice Hall, Inc. All rights reserved. 7 M e th o d D e sc rip t io n Exa m p le ceil( x ) ro u n d s x to th e sm a lle st in te g e r c e i l ( 9 . 2 ) is 1 0 . 0 n o t le ss th a n x c e i l ( - 9 . 8 ) is - 9 . 0 cos( x ) trig o n o m e tric c o sin e o f x c o s ( 0 . 0 ) is 1 . 0 (x in ra d ia n s ) exp( x ) e x p o n e n tia l fu n c tio n e x e x p ( 1 . 0 ) is 2 . 7 1 8 2 8 e x p ( 2 . 0 ) is 7 . 3 8 9 0 6 fabs( x ) a b so lu te v a lu e o f x f a b s ( 5 . 1 ) is 5 . 1 f a b s ( 0 . 0 ) is 0 . 0 f a b s ( - 8 . 7 6 ) is 8 . 7 6 floor( x ) ro u n d s x to th e la rg e st in te g e r f l o o r ( 9 . 2 ) is 9 . 0 n o t g re a te r th a n x f l o o r ( - 9 . 8 ) is - 1 0 . 0 fmod( x, y ) re m a in d e r o f x /y a s a flo a tin g - f m o d ( 1 3 . 6 5 7 , 2 . 3 3 3 ) is 1 . 9 9 2 p o in t n u m b e r log( x ) n a tu ra l lo g a rith m o f x (b a se e ) l o g ( 2 . 7 1 8 2 8 2 ) is 1 . 0 l o g ( 7 . 3 8 9 0 5 6 ) is 2 . 0 log10( x ) lo g a rith m o f x (b a s e 1 0 ) ...
Nội dung trích xuất từ tài liệu:
Giáo trình tin học chương 3 1 Chapter 3 - Functions Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number Generation 3.9 Example: A Game of Chance and Introducing enum 3.10 Storage Classes 3.11 Scope Rules 3.12 Recursion 3.13 Example Using Recursion: The Fibonacci Series 3.14 Recursion vs. Iteration 3.15 Functions with Empty Parameter Lists 2003 Prentice Hall, Inc. All rights reserved. 2 Chapter 3 - Functions Outline 3.16 Inline Functions 3.17 References and Reference Parameters 3.18 Default Arguments 3.19 Unary Scope Resolution Operator 3.20 Function Overloading 3.21 Function Templates 2003 Prentice Hall, Inc. All rights reserved. 3 3.1 Introduction • Divide and conquer – Construct a program from smaller pieces or components – Each piece more manageable than the original program 2003 Prentice Hall, Inc. All rights reserved. 4 3.2 Program Components in C++ • Modules: functions and classes • Programs use new and “prepackaged” modules – New: programmer-defined functions, classes – Prepackaged: from the standard library • Functions invoked by function call – Function name and information (arguments) it needs • Function definitions – Only written once – Hidden from other functions 2003 Prentice Hall, Inc. All rights reserved. 5 3.3 Math Library Functions • Perform common mathematical calculations – Include the header file • Functions called by writing – functionName(argument1, argument2, …); • Example cout 6 3.3 Math Library Functions • Function arguments can be – Constants • sqrt( 4 ); – Variables • sqrt( x ); – Expressions • sqrt( sqrt( x ) ) ; • sqrt( 3 - 6x ); 2003 Prentice Hall, Inc. All rights reserved. 7 M e th o d D e sc rip t io n Exa m p le ceil( x ) ro u n d s x to th e sm a lle st in te g e r c e i l ( 9 . 2 ) is 1 0 . 0 n o t le ss th a n x c e i l ( - 9 . 8 ) is - 9 . 0 cos( x ) trig o n o m e tric c o sin e o f x c o s ( 0 . 0 ) is 1 . 0 (x in ra d ia n s ) exp( x ) e x p o n e n tia l fu n c tio n e x e x p ( 1 . 0 ) is 2 . 7 1 8 2 8 e x p ( 2 . 0 ) is 7 . 3 8 9 0 6 fabs( x ) a b so lu te v a lu e o f x f a b s ( 5 . 1 ) is 5 . 1 f a b s ( 0 . 0 ) is 0 . 0 f a b s ( - 8 . 7 6 ) is 8 . 7 6 floor( x ) ro u n d s x to th e la rg e st in te g e r f l o o r ( 9 . 2 ) is 9 . 0 n o t g re a te r th a n x f l o o r ( - 9 . 8 ) is - 1 0 . 0 fmod( x, y ) re m a in d e r o f x /y a s a flo a tin g - f m o d ( 1 3 . 6 5 7 , 2 . 3 3 3 ) is 1 . 9 9 2 p o in t n u m b e r log( x ) n a tu ra l lo g a rith m o f x (b a se e ) l o g ( 2 . 7 1 8 2 8 2 ) is 1 . 0 l o g ( 7 . 3 8 9 0 5 6 ) is 2 . 0 log10( x ) lo g a rith m o f x (b a s e 1 0 ) ...
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin tin học văn phòng giáo trình tin học máy tính funtionsGợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
73 trang 427 2 0
-
Giáo trình Tin học (Trình độ: Trung cấp nghề) - Trường Trung cấp nghề Củ Chi
268 trang 334 4 0 -
Nhập môn Tin học căn bản: Phần 1
106 trang 329 0 0 -
Giáo trình Tin học văn phòng: Phần 2 - Bùi Thế Tâm
65 trang 315 0 0 -
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
74 trang 296 0 0
-
96 trang 292 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 280 0 0