Lec10 - Lecture 10 Functions PIC 10A Todd Wittman Sec 5.1...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 10: Functions PIC 10A Todd Wittman Sec 5.1 : Functions square6 C++ is modular , which means the program can be built out of smaller components. Much like Swedish furniture. square6 A function is a set of instructions separate from the main routine that can be called on at any time. square6 Generally we pass the function parameters . square6 The function often returns a value. square6 We’ve already used several built-in functions main ( ) Line.move (dx, dy) sqrt (x) cwin.coord (x1, y1, x2, y2) getline(cin,s) setw (columnWidth) square6 Today we’re going to learn how to write our own functions.
Image of page 1

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

View Full Document Right Arrow Icon
2 Sec 5.2 : Writing Functions square6 When we declare a function, we need to identify the data types of the parameters that are passed to the function and the type of variable that is returned by the function. type function_name ( type param1, type param2, ... ) { **FUNCTION CODE** } A dumb example... int add2Numbers ( int num1, int num2 ) { int sum = num1 + num2; return sum; } return type Parameters Braces enclose the code of the function. return ends the function, but not the whole program. Sends back a value. Calling Functions square6 When we call the function, we shouldn’t write out the data type.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern