CP1_7a_Functions1_1112

CP1_7a_Functions1_1112 - Functions Functions 1 Intro and...

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

View Full Document Right Arrow Icon
unctions 1 Functions 1 Intro and Predefined Functions
Background image of page 1

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

View Full DocumentRight Arrow Icon
Breaking a task into subtasks So far, we've written our programs as a group of statements ain() {…} in main() {…} . If we structured large programs like this, their code would be very difficult to understand, test, debug, maintain… We might also have to duplicate sections of code at many points in the program where we needed the same or similar functionality. In reality, we don't structure our programs like this. We use a simple but powerful approach to problem solving, which is to break a large problem into smaller sub-problems and then write small sub-programs to solve those. The sub-programs are then combined to solve the larger problem. 2 CSIS1117B Computer Programming 1 2010-2011
Background image of page 2
The sub-programs The sub-programs we write to deal with some small part of e overall problem are combined by alling em from the the overall problem are combined by calling them from the main control paths of the program or from other sub- programs. A good sub-program has a single responsibility . It does one thing and does that thing well. Everything else is kept out of that sub-program. Almost all programming languages support this form of structuring. In C++, we write these building blocks in the form of functions . 3 CSIS1117B Computer Programming 1 2010-2011
Background image of page 3

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

View Full DocumentRight Arrow Icon
What is a function in C++? nction a small program which accomplishes a specific A function is a small program which accomplishes a specific task. ode can all nctions help complete its own task For Code can call functions to help complete its own task. For example our code may pass input to a function and then use the output passed back (returned) when the function ompletes its task completes its task. As a first example, we can examine functions available in the C++ library. These are predefined functions that are available for use in our own programs and which make our life as programmers much easier.
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.

This note was uploaded on 12/15/2011 for the course CSIS 1117B taught by Professor Noneedtoknow during the Winter '11 term at HKU.

Page1 / 14

CP1_7a_Functions1_1112 - Functions Functions 1 Intro and...

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