Section 5 - Section 5.1 What is a Function Up until this...

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

View Full Document Right Arrow Icon
Section 5.1: What is a Function? Up until this point, every line of code we've shown you has done a simple task, such as performing an arithmetic operation, or checking a boolean condition, or assigning to a variable. Functions allow you to do a whole lot in one line of code. Instead of performing a simple task, a single line of code can display a menu of choices, or compute complicated three- dimensional transformations, or even play Tetris! How is this possible? Functions allow you to group a series of steps under one name. Remember in Section 1.1 when we were baking chocolate chip cookies? We had to perform the following steps: place two eggs in a bowl add 1.5 c. butter to the eggs ... bake cookies for 10-12 minutes at 375 degrees or until brown In C++, and in most programming languages, you can give a name to a series of steps. Let's say we want to call this procedure "bake cookies". Then, our algorithm for baking cookies becomes: bake cookies We've just created a function to do the work for us. Don't get too excited - you still need
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
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