lect4_1

lect4_1 - Predefined Functions 1 Predefined Functions The...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Predefined Functions 1 Predefined Functions The programs that we have seen so far are very simple ones. In larger and more complicated programs, we have to divide the problem into smaller subtasks and then implement each subtask as a function . Instead of dealing with the complexity of the entire program all at once, a good plan of attack is to divide the task into a few smaller and more manageable subtasks, decompose each of these subtasks further into more smaller subtasks, and so forth. Eventually the subtasks become so small that they are very easy to implement in C++. This method is called top-down design . The top-down method is also some- times referred to as stepwise refinement . Maintaining the top-down structure makes it easy to write a program. to test a program. to debug a program. to understand a program functionality. to modify a program if there is a need for it. Functions A function is a named block of code. It is a small program that performs some well-defined subtask. Like a program, a function is usually given some data to accomplish the subtask. A function can have its own variables. We will discuss two types of functions in detail. 1. Functions that compute a single value based on the data they are given and then return that value. Such functions are called value-returning functions. 2. Functions that perform a specific task, based on the data they are given, but do not return any value. Such functions are called void functions . We begin with some predefined functions that are packaged in the C++ standard library. Later we discuss how we can create our own functions. Predefined functions C++ provides several predefined mathematical functions. These functions are avail- able in the library file cmath . Any program that uses a function from a library file must have an include statement specifying that library file. Otherwise, the compiler will be unable to identify the function. Predefined Functions 2 A program using any of the basic mathematical functions from the library file cmath requires the following include statement ....
View Full Document

Page1 / 6

lect4_1 - Predefined Functions 1 Predefined Functions The...

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

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