Which part of a function definition specifies the data type of the value that the function returns?

This is a prewritten function that is built into a programming language
a. standard function
b. library function
c. custom function
d. cafeteria

This term describes any mechanism that accepts input, performs some operation that cannot be seen on the input and produces output
a. glass box
b. white box
c. opaque box
d. black box

This part of a function definition specifies the data type of the value that the function returns
a. header
b. footer
c. body
d. return statement

This part of a function definition is comprised of one or more statement that are execute when function is called
a. header
b. footer
c. body
d. return statement

This statement causes a function to end and sends a value back to the part of the program that called the function
a. end
b. send
c. exit
d. return

This is a design tool that describes the input, processing, and output of a function
a. hierarchy chart
b. IPO chart
c. datagram chart
d. data processing chart

This type of function returns either True or False
a. binary
b. TrueFalse
c. Boolean
d. logical

This is an example of a data type conversion function
a. sqrt
b. toReal
c. substring
d. isNumeric

This type of error occurs when you try to assign a value of one data type to a variable of another data type
a. type mismatch error
b. Boolean logic error
c. relational error
d. bit conversion error

This is a string inside of another string
a. substring
b. inner string
c. mini string
d. component string

FUNCTION

You can write a program as a collection of functions - using functions allows you to write  modular programs. That is you can break down large problems into a collection of small problems and then write a function to solve each of the smaller problems. This programming approach avoids duplication of code and lets you write programs that are easier to read, write, debug, and maintain. To create a user-defined function, you need to perform the following steps:

  • Function declaration
  • Function definition
  • Function call

FUNCTION DECLARATION

You must declare all functions in your program before you can use them.

Syntax               return_type   func_name(arg_type(s));

You declare the functions before the main() function.

  • return_type - the data type the function return to the calling function. The return data type could be any C++ data type. You use the keyword void as the return data type if the function should return nothing. If the you don't specify the return_type, C++ will assume that the the return data type will be integer.
  • func_name- the name of the function. Use the same rule of naming a variable to name a function
  • arg_type - When you call a function, you may pass one or more arguments to the called function. You must specify the data type of each of its argument.
Example Explanation
int test( );
void main()
Declare a function named test. This function returns an integer value does not have any passing arguments.
float calculateArea(float, int);
void main()
Declare a function named calculateArea. This function has two passing arguments. The first argument is float data type and the second one is integer data type. The function also return a float value.
void hello( );
void main()
Declare a function named hello. This function does not have any passing argument as well as any return value.

FUNCTION DEFINITION

A function definition is a named block of code. A block of code is defined by opening and closing curly braces ({ and }).

Syntax:                  return_type   function_name(argument list)
{

                                function body;

                            }

You define a function after a main() function. If you defnine a function before a main(), then you don't need to declare a function.

  • A function definition should specify its return data type. It should also specify the data type of each of its arguments and assign a name to each argument. The same rules apply to naming functions that apply to naming variables.
  • If a function specify a return data type, then function body must have one or more return statements.

    return   something;

    where something could be a constant, a variable, an expression or a function call.  When C++ executes the
    return statement, it will exit the function and return a value back to the calling function.

Example Example Example
double  findArea(double radius)
{double area;
area= radius*radius*3.1416;
return area;
}
void print_value(double radius)
{ cout<<"The circle area is "     <<radius*radius*3.1416;
}
double calculateCost(int items, double unitprice)
{ return  items* unitprice;
}

FUNCTION CALL

When C++ encounters a function name in C++ program, it calls, or invokes, the function, causing program execution to stop in the current  or calling function. Program control is then transferred to the function that is being called, and the computer executes the statements in the called function.

When the function finish its execution, control returns to the point in the calling function at which the call it was made. If a function returns a value other than void, then the calling program should use the return value.

The following examples will demonstrate the creation of a user-define function.

Example Example
//Declare the function hello
void hello( );
void main()
{ hello( ); // Call the function hello
}
//Define a function hello
void hello( )
{ cout<<"Welcome to C++ programming"<<endl;
}
//Declare a function
double findArea(double);
void main( )
{double r, CirclArea;
cout<<"Enter radius"<<endl;
cin>>r;
CircleArea=findArea( r ); //Call the function
cout<<"The area is "<<CircleArea;
}
//Define the function
double  findArea(double radius)
{double area;
area= radius*radius*3.1416;
return area;
}

OVERLOADING FUNCTION

You can overload by giving the same name to more than one function. The function must have different numbers of arguments or the arguments must be of a different data type. C++ will figure out what function to call based on its arguments. Overloading functions allows C++ programmers to choose the most meaningful name for a function. It also permits the use of polymorphic code (applying to object-oriented programming).

Example
double average(double,double);
double average(double, double, double);
double average(int,double);
void main()
{  double x, y, z;
x=average(3.5 , 4.7);
y=average(10 , 20.4);
z=average(12.4, 4.8, 5.5);
cout<<x<<' '<<y<<' '<<z;
}
double average(double x, double y)
{ return (x+y)/2;
}
double average(int x, double y)
{ return (x+y)/2;
}
double average(double x, double y,double z)
{ return (x+y+z)/3;
}
Output
4.1  15.2   7.56

DEFAULT ARGUMENT

In C++, you can assign default values to function arguments. When actual arguments are not provided in the call to a function, C++  will use these default values. The default values for the arguments appear in the function declaration. You must follow one rule when creating default values: not all arguments need default values, but once a default value has been specified for an argument, all of the subsequent argument must have a default value as well.

Example
double average(double val1= 1.0, double val2= 3.0, double val3=5.0);
void main()
{  double x, y, z;
x=average( );
y=average(3.5 , 4.7);
z=average(12.4, 4.8, 5.5);
cout<<x<<' '<<y<<' '<<z;
}
double average(double x=1.0, double y=3.0,double z=5.0)
{ return (x+y+z)/3;
}
Output
3.0  4.4  7.6

STANDARD LIBRARY FUNCTION

A library is a collection of C++ built-in functions that you can use in many programs. To use the library functions, you need to know the function's name, its purpose, the number of arguments it expects and the data types of the arguments, its purpose, the number of  arguments it expects and the data type of the arguments, the value returned by the function and its data type, and the header file that you should #include to ensure that your program will have access to the correct function declaration for the function.

The pow( ) function, for example, is a C++ standard library function that you can use to raise a number to power of two, three, and so on. The example below shows the function declaration for this function and a C++ program that uses the pow( ) function.

double   pow(double, double)

The function declaration for pow( 0 is found in <math.h>. The function expects two arguments, both of which are doubles. The function returns a double, which is the value of the first argument raised to the power of the second argument.

Example

#include<iostream>
#include<math>
using namespace std;

void main()
double x = 3.0;
double y=5.0;
double result;
result=pow(x, y);
cout << result<<end;
}

Output

243

What part of the function definition contains the statements?

A function definition contains the statements which make up the function. 6.2 List and define the parts of a function definition. Return Type: A function can send a value to the part of the program that executed it. The return type is the data type of the value that is sent from the function.

When a conversion function is used to convert a real number to an Integer what usually happens to the real numbers fractional part?

The real to an integer conversion function accepts a real number as its argument and returns that number converted to an integer. If the real number has a fractional part, the fractional part will be thrown away.

Is a module that returns a value back to the part of the program that called it?

A value-returning function is a function that returns a value back to the part of the program that called it.

Which term describes the mechanism of a function?

A mode of action (MoA) describes a functional or anatomical change, resulting from the exposure of a living organism to a substance. In comparison, a mechanism of action (MOA) describes such changes at the molecular level.