So, let's summarize some of the C++ advantages. Type safe, when I say, cin trials what is known is that cin is an istream Trials is an int type. So, the language understands, the compiler understands from cin, the standard input, which is the keyboard normally. I'm expecting some typing that is going to be interpretable as an integer, otherwise I have an error, but I don't have have to put any formatted characteristics. So, there's built-in implicit type safety. Type safety is always a good thing in programming. It's a way at runtime to catch errors. Notice, we had mentioned in that previous slide that there were declarations that could be intermixed with the executable. It doesn't mean I want you necessarily to not put declarations at the head of a block. That's still a very useful style guide. However, when you're writing longer programs, it's useful to have your declaration nearer to where it's used. That just makes the program a little more readable. So, if the code is a small amount of code, I would say, stay with the idea of putting all of your declarations at the head of the block, and common thing in right there. But if you have more lengthy things, and you have a need for putting something right near where it's used, that is a very useful idea, and frequently makes longer pieces of code more readable. There was also, though I didn't go over it, in that last slide, the use of new. And if you review that, new is a memory management. And the memory it's getting is heap based memory, so again, most of you should have one to two years of computer science background, either professionally, or at school. When you are running a program in which, for example you have main, and you're allocating variables. You're allocate them off the stack. So when you declare a simple int, the head of main, that memory allocation is automatic. And the allocation's automatic, it comes off what you call the stack. However, when you don't know what kind of memory you need yet, it has to be part of a calculation at runtime, then we use an alternate memory allocation strategy. And that's called memory allocation off the heap. And there's separate memory, a global chunk of memory that can be used to take memory off the heap, and return memory to the heap. And there in C, if you remember, there was a term or a standard function called malloc_( ). And there was also a function called free. These are replaced by new, and delete. And again, we will see, because of things like type safety, there is more implicit information available to the C++ compiler in using these new operators. These are keywords built-in to the language, rather than standard functions that come from the standard library, and it does provide improvements. So, here's C++. Here's the rest of that code. Again, this is where we're computing. If we roll 5 + 6, that would be our outcomes for 11. We would get a probability for it. And then I have a funky little thing sitting here, that you won't have noticed as well. And I have an interesting piece of code here, so let's look at those two pieces of codes, cuz they're also relatively new. If you've never programmed in C++. So, this is what you call your standard iterator state integers. This is your idiomatic for state. It says, iterate with a variable j starting at value 2, where j is less than a certain number of dice times sides. So, we have two dice, six sides. And then each iteration is +1, so we're gonna go from 2, 3, up to 12, and do this calculation. But this initialize segment of the for statement, allows for the declaration of a local iterative variable, so that's nice. That's new, because we generally don't really care about our is and js being global if we're just using them for iterations. So this again, localizes something. Localization drives down complexity, so this is another improvement. Small one, but another little improvement that we're allowed to have these local decorations inside for statements. Cout, which is type safe, prints a string, so we'll see on the screen j =, and then some value. So, it might be j =, let's say, the starting value will be 2, and then we'll see probability p =, and then we'll do this computation. So, this is another thing. There is something called static cast, static cast is what called a safe cast. C++ replaces old style unsafe casting in C with four different kinds of casting. So, C casting is deprecated, meaning obsolete, shouldn't be used. Compiler may still like to use it. If you remember, a C cast would look something like this, (double), here's some expression, and that would mean convert that expression. So, that is treated in the domain double, that's the same thing happening here. Here's the type that I want to convert to. But instead of just allowing it arbitrary forced conversion, this is telling me, only convert if you have a rule based conversion that you consider safe. If the conversion was not considered safe, then there would be an error. So, this is gonna protect you from non standard conversions. And again, it's an improvement. Why do I need that conversion? Because otherwise, these two things would be integer, and if they were both integer, and outcomes would be less than trials, then all your probabilities would be zero, and your probabilities aren't zero. So, if there were like 5 outcomes out of 20, you want this to become the number 5.0. And now this is no longer integer divide, and you would get 0.25. And endl is another way of saying, new line. So this is again, in the ioostream standard library, it's called an IO manipulator. It's something that can be put in an iostream, and it tells the iostream to skip to the next line. So all of that shows you various kinds of improvements, and it's pretty much what I want you to take away today in using this for your first homework assignment. These are all things that you're gonna make use of in converting your first C assignment. Let's summarize with what advantages we have. Safe casts, like static. There are going to be three other kinds of casts. One will be for example very dangerous, reinterpret cast. That means force the thing to look at it this way, and just look at the bit pattern, and whatever that bit pattern is on loke machine, reinterpret it. Generally speaking in most companies, you're gonna to need manager approval for that cast, it's something to avoid. But generally speaking, just a bad idea, so in a way it shouldn't be used. But it's there, and maybe some very obscure critical need for it. It's available, rather than have to return to, in effect that's like returning to the bad old days of an unrestricted C cast. For statement can include a declaration and initializer. So, we frequently see things, like int i, or int j = some initial value, this is most typical, typically, you start your loops with a 0. EndI is an iomanipulator. So again, those are little improvements over the C language that you can immediately use, and you can immediately become a C++ programmer. Now, Bjarne, he's currently a professor at the Texas A&M, distinguished professor there. He's still working on the latest versions of C++, and he has the classic book defining a language. A very, very detailed at his point, but from his perspective as chief architectural language, he more or less said, I believe C++ is better because I don't think purity is a virtue. He think Java as pure OO simula, as somewhat high-bred. Small talk as pure. And he is saying, purity is not necessarily a virtue. The single strength of C++ is exactly that it supports several effective styles of programming. Several paradigms, and combinations of styles. Often the most elegant, most efficient, and most maintainable solution involves more than one style. Swiss Army knives, think Swiss Army knife. What did we learn so far? More type safe than C, with more elegance. And then here is your first homework assignment, this is what you need to convert. And I'll see you next time.