Материал готовится,

пожалуйста, возвращайтесь позднее

пожалуйста, возвращайтесь позднее

All righty, so a couple things to cover real quickly. Last time we talked all about methods and some more about objects. There’s two things you should know in the programs that you’re going to be doing, is we talked a little bit about one of them last time in terms of how to get input from the user. There’re these functions that you should know about.

One is called READ INT and there’s some prompt inside double quotes that you give and what that does is ask the user basically for an integer and gives you back some value that you can say, assign to an integer. There’s also a version of this to get doubles, which surprisingly enough is called RE DOUBLE and has exactly sort of the same properties. So it’s called RE DOUBLE; it has some string here as it’s parameter or some text here in its parameter inside double quotes which it displays to the screen and then gets you back a value which is a double one you can assign to a double. Those are just two things off the bat that you should know about because that’s how you’re going to get input, at least for the time being, from the user in a lot of cases.

Now, one thing you want to do once you actually get some input from the user is, you want to do some manipulation on it like some expressions that we talked about last time. We talked about some of the different operators like addition, subtraction or unary minus, it’s the same symbol, multiplication, division and my favorite, the remainder. And so we talked about all those except for this little guy last time. All of the operators kind of work the way you would expect them to, okay. And we’ll talk a little bit more about division in just a second. The interesting thing about division – so all of these things work with both – or I should say – all of these work with both integers and doubles. The remainder, as we talked about, only works with integers, right because it doesn’t make sense to have a remainder when you have real values.

These three guys work exactly the same for integers and double, just the way you would expect addition, multiplication, all that happy stuff, to work. Division kind of rears its ugly head because it actually works slightly differently if you’re doing division for integers versus doubles. Okay? The whole point of that is, if you’re doing a division and the two arguments that you’re dividing, right if both of these things are integers; in this case I have integer constant which is what I mean, the values, right. If both of these integers, what it does is integer division which means it does the division and throws away any remainder. So what you get back is an integer. So 5 divided by 2 when these are integers gives you back the Value 2. That little remainder thing is just gone. If you want to get the remainder you use this guy. Okay?

If either one of these particular values happens to be a real value, like a double, then it will do real-value division and give you back a real value. So if you happen to divide 5, even if 5 is an integer, by the Value 2.0 and so it knows it’s a real value because it’s got a decimal point in it, this will give you back 2.5 as a double and so you can assign that to a double. Okay?

So if either one of the arguments is a double, you get real-value division; if they’re both integers, you get back the integer portion. Un huh?

Student:I’m a little confused about the double; the double is just a real number?

Instructor (Mehran Sahami):It’s just a real number. Yes.

One is called READ INT and there’s some prompt inside double quotes that you give and what that does is ask the user basically for an integer and gives you back some value that you can say, assign to an integer. There’s also a version of this to get doubles, which surprisingly enough is called RE DOUBLE and has exactly sort of the same properties. So it’s called RE DOUBLE; it has some string here as it’s parameter or some text here in its parameter inside double quotes which it displays to the screen and then gets you back a value which is a double one you can assign to a double. Those are just two things off the bat that you should know about because that’s how you’re going to get input, at least for the time being, from the user in a lot of cases.

Now, one thing you want to do once you actually get some input from the user is, you want to do some manipulation on it like some expressions that we talked about last time. We talked about some of the different operators like addition, subtraction or unary minus, it’s the same symbol, multiplication, division and my favorite, the remainder. And so we talked about all those except for this little guy last time. All of the operators kind of work the way you would expect them to, okay. And we’ll talk a little bit more about division in just a second. The interesting thing about division – so all of these things work with both – or I should say – all of these work with both integers and doubles. The remainder, as we talked about, only works with integers, right because it doesn’t make sense to have a remainder when you have real values.

These three guys work exactly the same for integers and double, just the way you would expect addition, multiplication, all that happy stuff, to work. Division kind of rears its ugly head because it actually works slightly differently if you’re doing division for integers versus doubles. Okay? The whole point of that is, if you’re doing a division and the two arguments that you’re dividing, right if both of these things are integers; in this case I have integer constant which is what I mean, the values, right. If both of these integers, what it does is integer division which means it does the division and throws away any remainder. So what you get back is an integer. So 5 divided by 2 when these are integers gives you back the Value 2. That little remainder thing is just gone. If you want to get the remainder you use this guy. Okay?

If either one of these particular values happens to be a real value, like a double, then it will do real-value division and give you back a real value. So if you happen to divide 5, even if 5 is an integer, by the Value 2.0 and so it knows it’s a real value because it’s got a decimal point in it, this will give you back 2.5 as a double and so you can assign that to a double. Okay?

So if either one of the arguments is a double, you get real-value division; if they’re both integers, you get back the integer portion. Un huh?

Student:I’m a little confused about the double; the double is just a real number?

Instructor (Mehran Sahami):It’s just a real number. Yes.

Загрузка...

Выбрать следующее задание

Ты добавил

Выбрать следующее задание

Ты добавил