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

C++ lecture 9

19 9 0

Đ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

C++ Programming Lecture Functions – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides) Outline  Introduction  C++ program components  Math library functions  Functions:     Prototype Definition Function call Header files The Hashemite University Introduction    Till now we have learned the basic concepts of C++ All the programs that we have written are simple, have few lines of code, and flat (i.e all the code resides inside the main() body) But:    What about large programs? What about code reuse (when the same code block is used many times within the program)? Divide and conquer technique:  Construct a program from smaller pieces or components  Each piece more manageable than the original program The Hashemite University Program Components in C++ I   C++ modules are functions and classes Programs are written by:    Combining new functions with “prepackaged” functions in the C++ standard library The standard library provides a rich collection of functions Functions are invoked by a function call   A function call specifies the function name and provides information (as arguments) that the called function needs Similar to the boss to worker analogy: A boss (the calling function or caller) asks a worker (the called function) to perform a task and return (i.e., report back) the results when the task is done The Hashemite University Program Components in C++ II  Function definition:      It is the body of the function which include all the processing done by the function It makes use of the parameters (arguments) passed by the function call and specifies what will be returned by the function (result of the function) Only written once These statements are hidden from other functions Boss to worker analogy: The boss does not know how the worker gets the job done; he just wants it done The Hashemite University Math Library Functions I  Math library functions    Allow the programmer to perform common mathematical calculations Are used by including the header file or Functions called by writing functionName (argument)  Example cout

Ngày đăng: 12/10/2021, 21:08

Xem thêm:

Mục lục

    C++ Programming Lecture 9 Functions – Part I

    Program Components in C++ I

    Program Components in C++ II

    Math Library Functions I

    Math Library Functions II

    Math Library Functions III

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

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w