You are on page 1of 2

HERNANDEZ MORALES EFREN DANIEL UNIVERSIDAD TECNOLOGICA DE ALTAMIRA

TASK 1: OBJECT ORIENTED LANGUAGE PROGRAMMING


24/03/2024

Object Oriented Language Programming


Object-oriented programming allows us to transfer to programs the way of thinking that
we have in the solution or description of problems in general. We usually refer to
entities (objects), which we usually classify into groups with characteristics and
functioning common (classes), and of which we are interested in certain characteristics
(properties) and their operation (methods).
Furthermore, when relating some objects to others to design complex systems, we
usually use encapsulation, that is, we allow objects to interact with each other only
through the features and functionalities exposed to the outside, while the features and
internal functionalities of each one are ignored by the rest.
Functions are a set of procedures encapsulated in a block, they usually receive
parameters, whose values they use to carry out operations and additionally return a
value. This definition comes from the definition of a mathematical function which has a
domain and a range, that is, a set of values that it can take and a set of values that it can
return after any operation.
Methods and functions are functionally identical, but their difference lies in the context
in which they exist. A method can also receive values, carry out operations with them
and return values, however, a method is associated with an object, basically a method is
a function that belongs to an object or class, while a function exists on its own, without
need of an object to be used.
SYNTAX OR STRUCTURE FOR CREATE FUNCTIONS IN C++
The syntax to declare a function is

Let's remember that a function always returns something, therefore it is mandatory to


declare a type (the first component of the previous syntax), then we must give said
function a name, to be able to identify it and call it during execution, then inside
parentheses, we can put the arguments or parameters. After the definition of the
"signature" of the function, its operation is defined between curly braces; Everything
inside the curly braces is part of the function body and is executed until the return
statement is reached.
There are some details regarding the arguments of a function :
1.- A function or procedure can have any number of parameters, that is, they can have
zero, one, three, ten, one hundred or more parameters. Although they usually do not
usually have more than 4 or 5.
2.- If a function has more than one parameter, each of them must be separated by a
comma.
3.- The arguments of a function also have a type and a name that identifies them. The
type of the argument can be any and has no relation to the type of the function.

1
HERNANDEZ MORALES EFREN DANIEL UNIVERSIDAD TECNOLOGICA DE ALTAMIRA
TASK 1: OBJECT ORIENTED LANGUAGE PROGRAMMING
24/03/2024

You must keep two important things in mind with the return statement:
1.- Any statement found after the execution of return will NOT be executed. It is
common to find functions with multiple return statements inside conditionals, but once
the code executes a return statement, everything from there on down will not be
executed.
2.- The type of the value returned in a function must match that of the type declared to
the function, that is, if int is declared, the returned value must be an integer.
Example 1:

As you can see, it is a simple example, if you execute this, the function will return the
sum value which is 10 (5+5). The subsequent lines will never be executed, although they
do not generate any errors, they are of no use. You can notice that in this case it is the
same to have written return sum as to write return 5+5. Both lines work equivalently.
Example 2:

Here we made use of multiple return statements and took advantage of the characteristic
that when executed they immediately terminate the execution of the remaining part of
the function. In this way we can ensure that the function will return 'a' only when the
value of parameter n is zero and will return an 'x' when said value is not zero.
Example 3:

Here we already have a function that receives two parameters, one of them is used in the
conditional and the other to display its value on the screen with cout, this time we return
boolean values 0 and 1, it could be true or false as well.

You might also like