What is "p" in Person p?


#1

I am bit confused about the p in the Person parameter. Why do I have to put this in the function for the body mass index? :blush:
amidabrian


#2

I’m not sure I understand the question. The function bodyMassIndex() takes a parameter – a Person structure – and returns that person’s BMI. So, when you call the function, you supply a Person structure.

The name of the parameter is p in the function. The name of the variable that is holding the person in the main function is person. Those variables are in different frames.


#3

I suppose what I am asking is what is p in the bodyMassIndex function? I followed your previous example but this example has throw me a bit. :cry: Sorry to act a bit stupid but I am trying to get my head around this. Why could the bodyMassIndex function be float bodyMassIndex(Person)
{
return weightInKilos/(heightInMeters*heightInMeters)
}

Great a book and looking forward to more discoveries.


#4

I get it now- The parameters takes the argument of 96 and 1.8. Is that right?


#5

I get it now- The parameters takes the argument of 96 and 1.8. Is that right?


#6

I see what you mean. I did a gut check the first time I saw “float bodyMassIndex(Person p)” as well. It’s similar to saying “float bodyMassIndex(int p)” only in that p is of type int just as p is of type Person (or is it “struct Person”?). If you understand how “float bodyMassIndex(int p)” works, then understanding “float bodyMassIndex(Person p)” is just a small step away.

Building on concepts is the name of the game in this book and you can always refer back to previous material to understand current material and that, for me, has been key in the learning process.

Good stuff.


#7

The example might be easier to understand if the human being who weighs 96 kg and is 1.8 m tall was called (for example) Aaron instead of person.


#8

Ironically I was thinking exactly the same thing about it being easier to follow with person/human rather than person/person as I was doing the example.


#9

Where I am confused is:

“float bodyMassIndex(Person p)
{
return p.weightInKilos / (p.heightInMeters * p.heightInMeters);
}”

If the function parameter is p then why do we need to have “p.weightInKilos” or “p.heightInMeters” or “p.heightInMeters”? p has already been specified in the function argument.