# Has a relationship in c example function

### Classes (I) - C++ Tutorials

An operator is a symbol which operates on a value or a variable. For example: + is an operator to perform addition. C has wide range of operators to perform. In knowledge representation, object-oriented programming and design is-a (is_a or is a) is a The is-a relationship is to be contrasted with the has-a (has_a or has a) C++[edit]. The following C++ code establishes an explicit inheritance . The following example, function g just works for Rectangle class but not for Square. A function is an equation which shows the relationship between the input x and the In the example above with the carrots every input gives exactly one output.

So 1 is associated with 2. Let's say that 2 is associated with, let's say that 2 is associated with negative 3. So you'd have 2, negative 3 over there. And let's say on top of that, we also associate, we also associate 1 with the number 4. So we also created an association with 1 with the number 4.

So we have the ordered pair 1 comma 4. Now this is a relationship. We have, it's defined for a certain-- if this was a whole relationship, then the entire domain is just the numbers 1, actually just the numbers 1 and 2.

### C Operators: Arithmetic, Logical, Conditional and more

It's definitely a relation, but this is no longer a function. And the reason why it's no longer a function is, if you tell me, OK I'm giving you 1 in the domain, what member of the range is 1 associated with? Over here, you say, well I don't know, is 1 associated with 2, or is it associated with 4? It could be either one. So you don't have a clear association.

If I give you 1 here, you're like, I don't know, do I hand you a 2 or 4? That's not what a function does. A function says, oh, if you give me a 1, I know I'm giving you a 2.

If you give me 2, I know I'm giving you 2. Now with that out of the way, let's actually try to tackle the problem right over here. So let's think about its domain, and let's think about its range.

So the domain here, the possible, you can view them as x values or inputs, into this thing that could be a function, that's definitely a relation, you could have a negative 3. You could have a negative 2. You could have a 0. You could have a, well, we already listed a negative 2, so that's right over there. Or you could have a positive 3. Those are the possible values that this relation is defined for, that you could input into this relation and figure out what it outputs.

Now the range here, these are the possible outputs or the numbers that are associated with the numbers in the domain. The range includes 2, 4, 5, 2, 4, 5, 6, 6, and 8. I could have drawn this with a big cloud like this, and I could have done this with a cloud like this, but here we're showing the exact numbers in the domain and the range.

And now let's draw the actual associations. So negative 3 is associated with 2, or it's mapped to 2.

So negative 3 maps to 2 based on this ordered pair right over there. Then we have negative 2 is associated with 4. So negative 2 is associated with 4 based on this ordered pair right over there. Actually that first ordered pair, let me-- that first ordered pair, I don't want to get you confused.

It should just be this ordered pair right over here. Negative 3 is associated with 2. Then we have negative we'll do that in a different color-- we have negative 2 is associated with 4.

Negative 2 is associated with 4. We have 0 is associated with 5. Or sometimes people say, it's mapped to 5. We have negative 2 is mapped to 6. Now this is interesting. Negative 2 is already mapped to something. Now this ordered pair is saying it's also mapped to 6.

This example illustrates an important computer science problem solving technique called generalization. Assume we want to write a function to draw a square. The generalization step is to realize that a square is just a special kind of rectangle. To draw a rectangle we need to be able to call a function with different arguments for width and height. Unlike the case of the square, we cannot repeat the same thing 4 times, because the four sides are not equal.

However, it is the case that drawing the bottom and right sides are the same sequence as drawing the top and left sides.

## What is a Function?

So we eventually come up with this rather nice code that can draw a rectangle. In real programs, we will insist on better variable names than this. Concepts like rectangle, width, and height are meaningful for humans. They are not concepts that the program or the computer understands.

Thinking like a computer scientist involves looking for patterns and relationships. We did not just draw four sides.

Instead, we spotted that we could draw the rectangle as two halves and used a loop to repeat that pattern twice. But now we might spot that a square is a special kind of rectangle. A square simply uses the same value for both the height and the width. We already have a function that draws a rectangle, so we can use that to draw our square. Screen Set up the window wn. Turtle create tess drawSquare tess, 50 wn. Functions can call other functions. A caller of this function might say drawSquare tess, The parameters of this function, tx and sz, are assigned the values of the tess object, and the integer 50 respectively.