Professional Documents
Culture Documents
ASSIGNMENT 1
SUBMITTED
SUBMITTED BY
Dr. Ashu Gupta
Thakur
Assistant professor
154021
TO:
Taniya
Bca II
Functions
A function is a group of statements that together perform a task. Every C++ program
has at least one function, which is main(), and all the most trivial programs can
define additional functions.
You can divide up your code into separate functions. How you divide up your code
among different functions is up to you, but logically the division usually is so each
function performs a specific task.
A function declaration tells the compiler about a function's name, return type, and
parameters. A function definition provides the actual body of the function.
The C++ standard library provides numerous built-in functions that your program
can call. For example, function strcat() to concatenate two strings,
function memcpy() to copy one memory location to another location and many more
functions.
A function is knows as with various names like a method or a sub-routine or a
procedure etc.
Defult Arguments
Defult Arguments
One of the most useful facilities available in C++ is the facility to defined
default argument values for functions. In the function prototype declaration,
the default values are given. Whenever a call is made to a function without
specifying an argument, the program will automatically assign values to the
parameters from the default function prototype declaration. Fault arguments
facilitate easy development and maintenance of program.
PROGRAM
A program find the sum of the given numbers using default argument
declaration.
/ /default argument declaration
#include <iostream.h>
void sum ( int a, int b, int c= 6, int d = 10);
void main ( )
{
int a, b, c, d;
cout << enter any two numbers \n;
cin >> a >>b;
sum (a, b) ; / / sum of default values
}
void sum (int a1, int a2, int a3, int a4)
{
int temp;
temp = a1 + a2 + a3 + a4;
cout << a = << a1 << endl;
cout << b = << a2 << endl;
cout << c = << a3 << endl;
cout << d = << a4 << endl;