ECE 1574 Week 9 Functions.docx

ECE 1574 Week 9 Functions.docx - Page 1 of 4 ECE1574...

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

ECE1574 – Problem Solving for Engineers With C++ Page 1 of 4 Week 9 – Notes (1) MODULAR PROGRAMMING (Etter, Chapter 6) A program may contain numerous functions. Every C++ program must contain a main() function. main() often references functions defined in one of the standard libraries. main()  can also call other programmer defined functions. Functions, or modules, are independent statement blocks that are written to perform a specialized task. A C++ source program can be thought of as an ordered collection of executable tasks: input data analyze data output results Why use multiple functions? Why not write the entire program in the main() function? Advantages of modular programming include: Ability for multiple programmers to work on the same program Supports abstraction – or the concept of a module being a block on a flowchart – so the programmer does not have to be concerned with the details Ease in Testing/Debugging/Maintaining Reduces duplication of code Types of Functions Pre-defined (standard libraries) User defined EXAMPLE of a pre-defined Function: sin() calculates the sine of an angle given in radians defined in the <cmath> header Think of our flowcharts with input blocks, process blocks, and output blocks. Functions may perform these tasks as a block of code embedded in a larger C++ program.
Image of page 1

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

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • RPBroadwater
  • C preprocessor

{[ 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