CS161_Topic#9

CS161_Topic#9 - CS161 CS161 Introduction to Computer...

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

View Full Document Right Arrow Icon
1 CS161 CS161 Introduction to Introduction to Computer Science Computer Science Topic #9
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS161 Topic #9 2 Today in CS161 Introduction to Functions What is a function? Why would you want to use a function? How do you define functions? How do you call functions?
Background image of page 2
CS161 Topic #9 3 Functions: What are they? We can write our own functions in C++ These functions can be called from your main program or from other functions A C++ function consists of a grouping of statements to perform a certain task This means that all of the code necessary to get a task done doesn't have to be in your main program You can begin execution of a function by calling the function
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS161 Topic #9 4 Functions: What are they? When we write algorithms, we should divide our programs into a series of major tasks. .. where each major task is a function, called by the main program We can group together statements that perform a distinct task and give the overall action a name. This is accomplished by writing a C++ function.
Background image of page 4
CS161 Topic #9 5 Functions: What are they? For example, tasks such as driving a car, or cooking breakfast are every day functions that we use. The exact details of driving a car or cooking are hidden in the actual process, but even though you don't know the details -- just from the statement "driving a car" you know what that involves and what I am talking about. I don't need to have to tell you that first I get out my keys, then unlock the car door, then get inside, then. ....
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS161 Topic #9 6 Functions: What are they? The same thing applies to functions in C++. A function has a name assigned to it and contains a sequence of statements that you want executed every time you invoke the function from your main program! Data is passed from one function to another by
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

CS161_Topic#9 - CS161 CS161 Introduction to Computer...

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

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