CH09 - An Introduction to Programming with C+, Fifth...

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

View Full Document Right Arrow Icon
An Introduction to Programming with C++, Fifth Edition 9 - 1 Chapter 9 Value-Returning Functions At a Glance Instructor’s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Topics Classroom Activities/Additional Projects Key Terms
Background image of page 1

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

View Full DocumentRight Arrow Icon
An Introduction to Programming with C++, Fifth Edition 9 - 2 Lecture Notes Chapter Overview This chapter addresses the concept of the programmer writing his/her own functions in a program. More specifically, this chapter covers value-returning functions (void functions will be covered in the next chapter). In order for programmers to build their own functions, the concepts of a function prototype, understanding scopes of variables, and passing information (by value) to a function will also be covered. In addition to value-returning functions, the concepts of raising a number to a power and random numbers are also introduced. Chapter Objectives After completing the chapter, the student will be able to: Raise a number to a power Generate random numbers Create and invoke a function that returns a value Pass information, by value, to a function Write a function prototype Understand a variable’s scope and lifetime Use the .NET C++ Math::Pow() method Generate random integers in .NET C++ Instructor Notes Functions Remember that a function is a block of code that performs a task. Every C++ program contains at least one function called main(), and most programs contain many more functions. Programmers use functions for two reasons: functions allow the programmer to avoid duplicating code in different parts of the program, and they allow large and complex programs to be broken down into small and manageable tasks. Functions are categorized as either value-returning functions or void functions. Value-returning functions return a value to the statement that called the function, whereas void functions do not return a value. Void functions will be covered in the next chapter.
Background image of page 2
An Introduction to Programming with C++, Fifth Edition 9 - 3 Value-Returning Functions A value-returning function is a function that, after completing its assigned task, returns precisely one value. Some value-returning functions are built into the C++ language. Examples of these include the getline() and toupper() functions, which have been used in previous chapters. Raising a Number to a Power Most programming languages include a set of built-in functions for performing common mathematical tasks. In C++, these functions are defined in the cmath library file. Therefore, you will need to include the #include <cmath> directive in any program that uses these functions. The function covered in this chapter is only one of many functions contained in the
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CS 343 taught by Professor Katzman during the Spring '09 term at ITT Tech Tucson.

Page1 / 9

CH09 - An Introduction to Programming with C+, Fifth...

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

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