function definning and calling

small]before asking question i tell you that i am new one learner of c++
explain answer in simple words and give example also.
How to define a DrawRectangle function and how can i call it.
and How to define a DrawSphere function and how can i call it.
and which file i have to include.
This looks like your homework and I suspect you will have very little takers in doing your homework for you.

However, I will try and explain functions for you and hopefully you can apply this to doing your homework.

When you use functions you need to declare it, define it and then call it.

The way I usually do it is declare it, then define it and then call it where I need it.

When you declare a function it needs to have a type, a name and parameters (parameters can be nil)

here is an example: int Area_of_Rectangle (int, int);//here int is the type, Area_of_Rectangle is its name and it takes 2 integers as its parameters.

Basically in your declaration you are telling the computer that Area_of_Rectangle will take 2 integer values and return an integer value.

Now you need to define the function.

1
2
3
4
int Area_of_Rectangle (int length, int width)//the type, name and number and types of parameters must match the declaration
{
     return (length * width);//here length is multiplied by width and the function returns that value
}


To call this function you would do this:

Area_of_Rectangle (length, width);

Hope this helps.
Topic archived. No new replies allowed.