LectureEleven - C+ Programming Lecture 11 Functions Part I...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 11 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Hashemite University 2 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 conquertechnique: ± Construct a program from smaller pieces or components ± Each piece more manageable than the original program
Background image of page 2
The Hashemite University 3 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.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 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:
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

LectureEleven - C+ Programming Lecture 11 Functions Part I...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online