WEBVTT 00:00:00.000 --> 00:00:10.000 00:00:10.000 --> 00:00:11.000 00:00:11.000 --> 00:00:15.000 This presentation is delivered by the Stanford Center for Professional 00:00:15.000 --> 00:00:25.000 Development. 00:00:25.000 --> 00:00:29.000 I'm guessing by the fact that I can see myself that we're on. 00:00:29.000 --> 00:00:33.000 Welcome back to CS106L. My name's Keith. I'm a section 00:00:33.000 --> 00:00:37.000 leader here. I teach CS106L, which is the standard C++ program and 00:00:37.000 --> 00:00:37.000 laboratory. 00:00:37.000 --> 00:00:39.000 I recognize a few people here, which 00:00:39.000 --> 00:00:40.000 is great. 00:00:40.000 --> 00:00:44.000 Julie wanted me to come in today and talk to you about the C++ 00:00:44.000 --> 00:00:47.000 programming language, what's it look like outside of CS106B? 00:00:47.000 --> 00:00:50.000 What sorts of things do you need to be aware of to just kind of give you a general 00:00:50.000 --> 00:00:53.000 picture of what this language looks like? 00:00:53.000 --> 00:00:56.000 Before I get into the actual C++ stuff, I wanted to start off by 00:00:56.000 --> 00:00:59.000 congratulating all of you for making it through this class. That's not a 00:00:59.000 --> 00:01:01.000 small accomplishment. 00:01:01.000 --> 00:01:04.000 If you think about when you started, day one, probably looking at this screen right here, probably 00:01:04.000 --> 00:01:05.000 thinking, 00:01:05.000 --> 00:01:08.000 what's that [inaudible], what's Genlib, what's C [inaudible], and why's it 00:01:08.000 --> 00:01:11.000 really, really less than something? 00:01:11.000 --> 00:01:12.000 Look where you are now. 00:01:12.000 --> 00:01:16.000 You now know how to be a client of the vector, the stack, the map, the queue 00:01:16.000 --> 00:01:17.000 and the set. 00:01:17.000 --> 00:01:20.000 You know that recursion, you know pointers, you know Linklis and binary 00:01:20.000 --> 00:01:21.000 [inaudible] and graphs. 00:01:21.000 --> 00:01:25.000 You know algorithmic analysis and graph algorithms and searching and sorting. 00:01:25.000 --> 00:01:26.000 You know how the lexicon works. 00:01:26.000 --> 00:01:29.000 You know how to implement all of these classes. You know data abstraction. 00:01:29.000 --> 00:01:34.000 That's not a small accomplishment. That's really something to be proud of. 00:01:34.000 --> 00:01:37.000 What I wanted to say is that these are real, practical tools that will follow 00:01:37.000 --> 00:01:39.000 you, no matter where you take them. 00:01:39.000 --> 00:01:43.000 Some of you might go on in CS. You might think, wow, I really like this class. I want to 00:01:43.000 --> 00:01:45.000 see where it goes. That's great. 00:01:45.000 --> 00:01:48.000 No matter where you take it, if you go and take algorithms, you take 00:01:48.000 --> 00:01:52.000 compliers or data bases or operating systems, the skills you've learned here is really 00:01:52.000 --> 00:01:54.000 going to be the foundation 00:01:54.000 --> 00:01:57.000 of all of your programing. You're always going to be using maps. You're always 00:01:57.000 --> 00:02:00.000 going to be using vectors. You're going to need recursion, no matter where you 00:02:00.000 --> 00:02:01.000 apply it. 00:02:01.000 --> 00:02:04.000 It's really wonderful that you have these skills. 00:02:04.000 --> 00:02:06.000 Of course, some of you aren't going to go on in computer science. That's totally fine. You 00:02:06.000 --> 00:02:11.000 took this class and said, it's not for me or, you know, maybe not. Well, 00:02:11.000 --> 00:02:12.000 that's fine too because 00:02:12.000 --> 00:02:15.000 whether you go into sociology or philosophy or psychology or math or 00:02:15.000 --> 00:02:16.000 physics or chemistry, 00:02:16.000 --> 00:02:18.000 there are problems to be solved, 00:02:18.000 --> 00:02:20.000 and there are problems you can solve with a computer. 00:02:20.000 --> 00:02:23.000 What you've learned in this class is the most valuable skill of them all, which 00:02:23.000 --> 00:02:25.000 is how to take a problem, 00:02:25.000 --> 00:02:26.000 model it 00:02:26.000 --> 00:02:27.000 and solve it. 00:02:27.000 --> 00:02:29.000 That really is something. 00:02:29.000 --> 00:02:32.000 The skills you've learned here transcend any specific programming language. 00:02:32.000 --> 00:02:36.000 You can do everything you've done in here, in Java, in C++, in PHP, 00:02:36.000 --> 00:02:41.000 in Python. Everything that you think of, you will be using these same tools. 00:02:41.000 --> 00:02:42.000 That said, 00:02:42.000 --> 00:02:46.000 we've taught you everything in this class using the C++ programming 00:02:46.000 --> 00:02:46.000 language. 00:02:46.000 --> 00:02:48.000 We use C++ 00:02:48.000 --> 00:02:52.000 because it's very good for expressing the concepts that we were going over. It 00:02:52.000 --> 00:02:56.000 has great support for recursion, has exposed pointers, so you can do things like 00:02:56.000 --> 00:02:58.000 Linklis and binary trees quite nicely. 00:02:58.000 --> 00:03:01.000 It has objects so you can do data abstraction. It's got templates. It's a very 00:03:01.000 --> 00:03:05.000 good mix of different programing strategies and different programming styles 00:03:05.000 --> 00:03:07.000 that means we can teach you things without having to bog you down in 00:03:07.000 --> 00:03:09.000 language syntax. 00:03:09.000 --> 00:03:11.000 That said, this really hasn't been much of a class 00:03:11.000 --> 00:03:13.000 in C++. 00:03:13.000 --> 00:03:16.000 Think of it was we all put you inside the C++ bus and drove 00:03:16.000 --> 00:03:19.000 you up to the top of the mountain of CS106B knowledge. 00:03:19.000 --> 00:03:21.000 You know that the bus got you up there, 00:03:21.000 --> 00:03:24.000 but you don't really know what's going on under the hood. 00:03:24.000 --> 00:03:27.000 That's okay because what you learn in this class is more important than that. 00:03:27.000 --> 00:03:30.000 All the programing language and knowledge in the universe is not going to help you 00:03:30.000 --> 00:03:33.000 solve a problem if you don't know how to use a vector, you don't know how to make a 00:03:33.000 --> 00:03:36.000 map, and you can't make a recursive function solve things. 00:03:36.000 --> 00:03:40.000 What I want to do today is talk about what the C++ language is. What's 00:03:40.000 --> 00:03:42.000 it look like the real world? 00:03:42.000 --> 00:03:43.000 What kind of stuff do you need to know? 00:03:43.000 --> 00:03:46.000 More importantly, how do you take these skills that you've learned, which are very 00:03:46.000 --> 00:03:50.000 generic, and go and apply them in this language. 00:03:50.000 --> 00:03:53.000 I love C++. I've been using it for years. I think it's a beautiful 00:03:53.000 --> 00:03:56.000 language. It's got support for so many different programing paradigms. It's 00:03:56.000 --> 00:03:59.000 easy to use once you get a handle on it. 00:03:59.000 --> 00:04:01.000 It lets you solve problems in so many different ways. 00:04:01.000 --> 00:04:04.000 Really, I just want to show you what it looks like. 00:04:04.000 --> 00:04:07.000 Think of this as an appetizer. I'm just going to give you the - this 00:04:07.000 --> 00:04:10.000 is the C++ appetizer plate. I'll show you a little bit of this, a 00:04:10.000 --> 00:04:11.000 little bit of that, 00:04:11.000 --> 00:04:15.000 give you enough working knowledge that you know where to go to get help. 00:04:15.000 --> 00:04:16.000 You can see 00:04:16.000 --> 00:04:18.000 this is what you need to learn, get 00:04:18.000 --> 00:04:21.000 an overview of what we've been doing, what we've provided you, what we haven't 00:04:21.000 --> 00:04:22.000 provided you, 00:04:22.000 --> 00:04:25.000 so that by the time you're done, you can think, 00:04:25.000 --> 00:04:27.000 maybe I want to go on in this language. 00:04:27.000 --> 00:04:30.000 I'm not going to force you to learn C++. I can't do that. I'm 00:04:30.000 --> 00:04:33.000 not going to follow you around, did you learn C++ yet? Did you learn C++ yet? 00:04:33.000 --> 00:04:35.000 No, I'm not going to do that. 00:04:35.000 --> 00:04:38.000 You guys are all competent programmers right now. 00:04:38.000 --> 00:04:41.000 You know how to solve these problems. You know how to take on these challenges. 00:04:41.000 --> 00:04:43.000 So I just want to show you the language so you can decide whether or not you 00:04:43.000 --> 00:04:44.000 want to pursue it. 00:04:44.000 --> 00:04:47.000 Maybe you will. That'd be great. If not, 00:04:47.000 --> 00:04:48.000 that's okay, too, 00:04:48.000 --> 00:04:51.000 because you know how to tackle problems, and all you need now is a language to 00:04:51.000 --> 00:04:53.000 do it 00:04:53.000 --> 00:04:56.000 in. I want to show you basically four aspects of C++. First 00:04:56.000 --> 00:05:00.000 some philosophy and some history because every language has a personality. 00:05:00.000 --> 00:05:03.000 Every language wants to treat you as a programmer a different way, give you some 00:05:03.000 --> 00:05:05.000 different options. So I just want to show you what to expect when 00:05:05.000 --> 00:05:07.000 you're working with C++. 00:05:07.000 --> 00:05:10.000 As a language, it has a lot of criticisms. How many of you have heard 00:05:10.000 --> 00:05:15.000 bad things about C++ in any way, shape or form? 00:05:15.000 --> 00:05:18.000 Wow, every, single person in this room, basically. 00:05:18.000 --> 00:05:21.000 So there's a lot of criticisms leveled at this language, and what I want to 00:05:21.000 --> 00:05:22.000 do 00:05:22.000 --> 00:05:25.000 is show you what the mindset is so you can take a look at these 00:05:25.000 --> 00:05:28.000 criticisms and evaluate them. In all seriousness, most of the 00:05:28.000 --> 00:05:30.000 criticisms leveled at this language are 00:05:30.000 --> 00:05:33.000 criticisms with things a language doesn't try to do. 00:05:33.000 --> 00:05:37.000 At the same time, if you get this philosophy and you get this history, you'll 00:05:37.000 --> 00:05:38.000 understand where this language came from, 00:05:38.000 --> 00:05:41.000 what it's designed to do and where it's going. 00:05:41.000 --> 00:05:44.000 The second thing I want to talk about is the actual mechanics. 00:05:44.000 --> 00:05:47.000 What does the programing language look like? So I'll talk about the 00:05:47.000 --> 00:05:47.000 libraries, and 00:05:47.000 --> 00:05:49.000 I'll talk about the core language features. 00:05:49.000 --> 00:05:52.000 What happens when you take away things like [inaudible] and Synfi? What are you going to have 00:05:52.000 --> 00:05:54.000 to do now that you don't have those? In 00:05:54.000 --> 00:05:58.000 terms of it's actually pretty straightforward and you already know most of it. 00:05:58.000 --> 00:06:00.000 Then some language features that we didn't cover, things that you would expect to 00:06:00.000 --> 00:06:02.000 see in a professional setting 00:06:02.000 --> 00:06:05.000 that we didn't go over in this class because it's needlessly complicated and 00:06:05.000 --> 00:06:08.000 doesn't have much to do with this general data structure and 00:06:08.000 --> 00:06:10.000 algorithm challenges we've been giving you. 00:06:10.000 --> 00:06:12.000 Finally, just some references. 00:06:12.000 --> 00:06:14.000 Where do you go? 00:06:14.000 --> 00:06:17.000 You want to learn C++? Great. We have a list of wonderful books and resources 00:06:17.000 --> 00:06:18.000 you can go and reference, 00:06:18.000 --> 00:06:20.000 and it can get you up to speed very quickly. 00:06:20.000 --> 00:06:22.000 So it's kind of a game plan. 00:06:22.000 --> 00:06:23.000 See what's out there, 00:06:23.000 --> 00:06:28.000 have some fun with it and learn where to go. Sound good? Okay. 00:06:28.000 --> 00:06:29.000 So I want to start off 00:06:29.000 --> 00:06:32.000 with a quick history of C++. 00:06:32.000 --> 00:06:34.000 So C++ did not come into being one day when a whole bunch of programmers came 00:06:34.000 --> 00:06:37.000 into a room, made some demonic incantations over a bubbling cauldron and 00:06:37.000 --> 00:06:39.000 walked out. It didn't happen. 00:06:39.000 --> 00:06:42.000 It was not invented in one day. People did not sit down and say, our language is going to look like 00:06:42.000 --> 00:06:44.000 this. 00:06:44.000 --> 00:06:45.000 It has a history. 00:06:45.000 --> 00:06:49.000 It has evolution, and you can see different traces of we tried doing 00:06:49.000 --> 00:06:51.000 this. It didn't work. 00:06:51.000 --> 00:06:54.000 Let's go add this feature, etc. 00:06:54.000 --> 00:06:56.000 It started off 00:06:56.000 --> 00:06:58.000 with this guy. 00:06:58.000 --> 00:07:02.000 So I will attempt to pronounce his name. It's Bjarne Stroustrup. 00:07:02.000 --> 00:07:05.000 I've been told that the way to pronounce this is to say Stroustrup with a 00:07:05.000 --> 00:07:10.000 Norwegian accent while cramming a potato down your throat. I'll 00:07:10.000 --> 00:07:10.000 just 00:07:10.000 --> 00:07:14.000 get it close. Anyway, he's a Danish computer scientist, and he was getting his PhD in computer 00:07:14.000 --> 00:07:15.000 science from Cambridge, 00:07:15.000 --> 00:07:19.000 and his specialty was in distributive systems and operating systems. So his goal 00:07:19.000 --> 00:07:22.000 was, let's take some problems, spread it out over several computers, have 00:07:22.000 --> 00:07:26.000 them communicate via network protocol and get some results. 00:07:26.000 --> 00:07:29.000 He chose to write this program in a language called Simula. I 00:07:29.000 --> 00:07:34.000 confess, I don't know much about this language. I haven't heard anyone using it, but 00:07:34.000 --> 00:07:37.000 back then, it was the his object-oriented language, and he said it helped him think 00:07:37.000 --> 00:07:38.000 about the problem. 00:07:38.000 --> 00:07:42.000 It had classes, so you could build a computer object, a protocol object, a 00:07:42.000 --> 00:07:43.000 network object, 00:07:43.000 --> 00:07:46.000 and they'd send messages to each other the same way that a 00:07:46.000 --> 00:07:48.000 physical computer, a physical network 00:07:48.000 --> 00:07:51.000 and a physical protocol would communicate with each other. He 00:07:51.000 --> 00:07:54.000 got it working pretty fast and ran it, 00:07:54.000 --> 00:07:57.000 and much to his surprise, he found out that it was so abysmally slow that he could get no 00:07:57.000 --> 00:07:59.000 practical results out of it. The 00:07:59.000 --> 00:08:01.000 question is what went wrong? 00:08:01.000 --> 00:08:04.000 It wasn't his program. It was the Simula language implementation. 00:08:04.000 --> 00:08:08.000 He actually ran a profiler on his code to figure out why it was going slowly. 00:08:08.000 --> 00:08:10.000 80 percent of the time his program was running, it was going automatic 00:08:10.000 --> 00:08:13.000 garbage collection, even though he was doing [inaudible] memory management. 00:08:13.000 --> 00:08:14.000 So think about this. 00:08:14.000 --> 00:08:17.000 You spend several weeks writing a program. 00:08:17.000 --> 00:08:17.000 You run it, 00:08:17.000 --> 00:08:20.000 and for every line of code you're writing, four lines of meaningless code 00:08:20.000 --> 00:08:24.000 that someone else wrote are also executing. That's really slow. So 00:08:24.000 --> 00:08:27.000 he had to change approaches. He went and rewrote this entire program in a 00:08:27.000 --> 00:08:30.000 different language called BCPL, which is related to C and the B 00:08:30.000 --> 00:08:33.000 programing language that came before C. 00:08:33.000 --> 00:08:36.000 Of course, it's very low-level, it's very fast, but it didn't have these nice 00:08:36.000 --> 00:08:37.000 high-level features in it. 00:08:37.000 --> 00:08:39.000 He got it working, but it took a lot of time. 00:08:39.000 --> 00:08:42.000 When it was done, he decided, I'm never going to tackle a 00:08:42.000 --> 00:08:46.000 problem like this again until I have a proper tool for the job. He 00:08:46.000 --> 00:08:49.000 ended up at AT&T Bell labs, which is the same place that the C programming language came 00:08:49.000 --> 00:08:53.000 out of. In fact, he knew Kernighan and Ritchie, who invented that, 00:08:53.000 --> 00:08:55.000 and came up with this language called C with classes. It was 00:08:55.000 --> 00:08:58.000 a precursor to C++, and people loved it. 00:08:58.000 --> 00:09:02.000 It combined the best features of Simula, which is this object-oriented design, 00:09:02.000 --> 00:09:04.000 with the best features of C, which is the runtime efficiency. 00:09:04.000 --> 00:09:06.000 It was something that was fast, 00:09:06.000 --> 00:09:09.000 flexible and helped you think about problems. 00:09:09.000 --> 00:09:11.000 What he would do is work on this implementation. 00:09:11.000 --> 00:09:14.000 He had people actually using the C++, and when they needed new 00:09:14.000 --> 00:09:15.000 features, they said, 00:09:15.000 --> 00:09:17.000 Bjarne, it doesn't work. He'd go fix it. 00:09:17.000 --> 00:09:20.000 We had this cycle of real programmers solving real problems 00:09:20.000 --> 00:09:23.000 with this developer saying, okay, let's go fix it. 00:09:23.000 --> 00:09:26.000 After a while, you ended up with C++. I think this 00:09:26.000 --> 00:09:28.000 is the 25th anniversary of C++, so 00:09:28.000 --> 00:09:30.000 how exciting. 00:09:30.000 --> 00:09:33.000 I want to talk about the philosophy a little bit. What is really driving the 00:09:33.000 --> 00:09:36.000 development of this language? What does it expect out of you? 00:09:36.000 --> 00:09:39.000 So I have some quotes from this book called The Design and Evolution of C++. It's 00:09:39.000 --> 00:09:40.000 a good book. You should read it. 00:09:40.000 --> 00:09:42.000 The first one, 00:09:42.000 --> 00:09:45.000 C++'s evolution should be driven by real problems, and you don't 00:09:45.000 --> 00:09:47.000 want to get down on a quest for perfection. 00:09:47.000 --> 00:09:51.000 Basically, this language is designed to solve real problems that 00:09:51.000 --> 00:09:53.000 real programmers like you are going to run into 00:09:53.000 --> 00:09:55.000 in not necessarily the best way. 00:09:55.000 --> 00:09:56.000 It tries to do a good job. 00:09:56.000 --> 00:10:01.000 It's not intended to be perfect. There are some sloppy edges, but it works. 00:10:01.000 --> 00:10:04.000 Because it is driven by real problems and real design issues, you can solve 00:10:04.000 --> 00:10:06.000 real problems with it. 00:10:06.000 --> 00:10:07.000 If you think that's a good thing in a language, 00:10:07.000 --> 00:10:11.000 I personally do. I think it's good to have a language that can solve problems, 00:10:11.000 --> 00:10:14.000 then C++ is a good choice. 00:10:14.000 --> 00:10:17.000 This is probably the one that you've seen the most. Don't try to force people. 00:10:17.000 --> 00:10:21.000 C++ gives you so many choices that your question should not be, 00:10:21.000 --> 00:10:24.000 how do I do this in the language, but more, which of these hundreds of 00:10:24.000 --> 00:10:26.000 options is the best choice for me? 00:10:26.000 --> 00:10:29.000 It really trusts you as a language. It will give you an incredible amount of 00:10:29.000 --> 00:10:33.000 flexibility, even to the point where it will let you make the wrong decision. 00:10:33.000 --> 00:10:36.000 I've always thought C++ is a language that will let you ride a 00:10:36.000 --> 00:10:37.000 bicycle without a helmet 00:10:37.000 --> 00:10:40.000 because that one time that you need to go under a bridge that's exactly a quarter inch over your 00:10:40.000 --> 00:10:43.000 head, you wont have your helmet knock you off your bike. You 00:10:43.000 --> 00:10:45.000 do have to worry about a lot of risks, 00:10:45.000 --> 00:10:48.000 but in the end, you'll have more flexibility than you'll find in most other 00:10:48.000 --> 00:10:50.000 languages you 00:10:50.000 --> 00:10:52.000 see. Finally, I think the most important one 00:10:52.000 --> 00:10:54.000 is this. 00:10:54.000 --> 00:10:56.000 C++ makes programming more enjoyable 00:10:56.000 --> 00:10:58.000 for serious programmers. 00:10:58.000 --> 00:11:01.000 The two things here are serious programmers and more enjoyable. 00:11:01.000 --> 00:11:04.000 This is a professional language. It's used in industry everywhere. 00:11:04.000 --> 00:11:05.000 It's very fast. 00:11:05.000 --> 00:11:08.000 It's very efficient. It has a bit of a learning curve. It is kind of 00:11:08.000 --> 00:11:11.000 tricky to get into the language, but once you've got it, 00:11:11.000 --> 00:11:13.000 the second part, the more enjoyable, is so true. 00:11:13.000 --> 00:11:16.000 This language is fun to write things in. 00:11:16.000 --> 00:11:19.000 Once you've got it down, you will actually step back from your program and say, wow, 00:11:19.000 --> 00:11:22.000 I just wrote something that took every, single word out of this set that I had 00:11:22.000 --> 00:11:24.000 [inaudible] contains a specific letter 00:11:24.000 --> 00:11:25.000 in a single line of code. 00:11:25.000 --> 00:11:29.000 Or I lettered all the contents of this file into my set in one line of code. Or I 00:11:29.000 --> 00:11:31.000 just wrote a template that 00:11:31.000 --> 00:11:34.000 is a multi-dimensional ray of any dimension I want. 00:11:34.000 --> 00:11:37.000 Those are not trivial accomplishments, and you can do it with 00:11:37.000 --> 00:11:38.000 this language. 00:11:38.000 --> 00:11:39.000 It's fun. 00:11:39.000 --> 00:11:41.000 It's a great language, and if you think that this sort of philosophy is what you 00:11:41.000 --> 00:11:43.000 want, where it will trust you, 00:11:43.000 --> 00:11:46.000 it will really let you make the decisions rather than forcing you into any one 00:11:46.000 --> 00:11:47.000 paradigm, 00:11:47.000 --> 00:11:48.000 learn C++. 00:11:48.000 --> 00:11:51.000 I think you'll love it. So 00:11:51.000 --> 00:11:55.000 philosophy. There's lots of it, but I'm not here to teach a philosophy 00:11:55.000 --> 00:11:58.000 class. I'm here to teach you about C++, so let's get down to some of the details. What does this 00:11:58.000 --> 00:12:00.000 language look like? 00:12:00.000 --> 00:12:02.000 The first thing I want to do is talk about 00:12:02.000 --> 00:12:04.000 what Genlib.H has. 00:12:04.000 --> 00:12:06.000 Since day one, you probably have seen 00:12:06.000 --> 00:12:07.000 things like this. How 00:12:07.000 --> 00:12:10.000 to include Genlib. Very first line, right here. 00:12:10.000 --> 00:12:14.000 What is in this Genlib thing? Has anybody actually looked at Genlib before? Actually, pulled up 00:12:14.000 --> 00:12:20.000 the Genlib file and looked inside? No one? Okay. 00:12:20.000 --> 00:12:22.000 If you look inside Genlib, 00:12:22.000 --> 00:12:24.000 it looks mostly like this. 00:12:24.000 --> 00:12:27.000 There are basically three important lines you need to know. 00:12:27.000 --> 00:12:28.000 Time includes string. 00:12:28.000 --> 00:12:31.000 So we talked to you about the string classes that was a built-in type, like Ent or 00:12:31.000 --> 00:12:35.000 double. It's a class. It's like any other object, like a vector or a map. You do need 00:12:35.000 --> 00:12:36.000 to pound include it. 00:12:36.000 --> 00:12:39.000 We just took care of it for you because since you use it everywhere and it's easy to 00:12:39.000 --> 00:12:42.000 forget and you can get some pretty nasty compiler errors if you don't, 00:12:42.000 --> 00:12:44.000 we thought, 00:12:44.000 --> 00:12:47.000 we'll be nice. We'll do that for you. 00:12:47.000 --> 00:12:48.000 The second thing is this error function. 00:12:48.000 --> 00:12:52.000 You've seen error. Genlib just gives you a prototype for it. The end. 00:12:52.000 --> 00:12:56.000 But this last one right here using name space STD. Using the standard 00:12:56.000 --> 00:12:58.000 name space. What on 00:12:58.000 --> 00:13:00.000 earth is this line? 00:13:00.000 --> 00:13:03.000 It looks almost like an English sentence. 00:13:03.000 --> 00:13:05.000 Compiler, make my code work. 00:13:05.000 --> 00:13:07.000 What's going on here? 00:13:07.000 --> 00:13:10.000 Well, I'll show you. 00:13:10.000 --> 00:13:14.000 Suppose I have this little program back here. Can anybody see this? So I want to pound include [inaudible] 00:13:14.000 --> 00:13:17.000 and pound include string. 00:13:17.000 --> 00:13:19.000 If you notice here, I don't have Genlib, and I'm going to make 00:13:19.000 --> 00:13:22.000 a string and print it out. 00:13:22.000 --> 00:13:26.000 So the question is, when I say string, my string, 00:13:26.000 --> 00:13:28.000 what am I referring to? 00:13:28.000 --> 00:13:31.000 Well, when this happens, the compiler says, well, go look for something called 00:13:31.000 --> 00:13:32.000 string. 00:13:32.000 --> 00:13:34.000 When we pound included string, 00:13:34.000 --> 00:13:38.000 it put it inside this big bucket of something called name space standard. 00:13:38.000 --> 00:13:41.000 The idea is that the real name of string is standard string. The real name of C out 00:13:41.000 --> 00:13:44.000 is standard C out. The real name of endal is standard endal. 00:13:44.000 --> 00:13:47.000 It's just so that if you make your own versions of those things, it doesn't have 00:13:47.000 --> 00:13:51.000 the same name as the standard. It won't conflict, and your program will still compile. 00:13:51.000 --> 00:13:54.000 But the problem is that if you try to run this, what 00:13:54.000 --> 00:13:55.000 will happen is that 00:13:55.000 --> 00:13:56.000 the compiler says string, 00:13:56.000 --> 00:13:59.000 looks up here and hits this wall. It 00:13:59.000 --> 00:14:03.000 says, oops, that's inside the standard name space. I can't go in there, 00:14:03.000 --> 00:14:06.000 and you'll get this really nasty compiler error, something like, string's not defined. C out's not defined. 00:14:06.000 --> 00:14:08.000 Endal's not defined. 00:14:08.000 --> 00:14:12.000 Now, most of the time when you're programming, you want things like C out and 00:14:12.000 --> 00:14:14.000 string to actually exist. 00:14:14.000 --> 00:14:17.000 So rather than saying you have to call it standard string, standard C out, standard 00:14:17.000 --> 00:14:19.000 endal, 00:14:19.000 --> 00:14:22.000 you can introduce this little phrase right here, 00:14:22.000 --> 00:14:24.000 using name space standard. What it says 00:14:24.000 --> 00:14:26.000 is take this wall and get rid of it. 00:14:26.000 --> 00:14:29.000 It's like, Mr. Compiler, tear down this wall, 00:14:29.000 --> 00:14:30.000 and the result 00:14:30.000 --> 00:14:34.000 is that this barrier gets a little bit 00:14:34.000 --> 00:14:34.000 transparent. 00:14:34.000 --> 00:14:38.000 It's all still included inside of the standard name 00:14:38.000 --> 00:14:39.000 space, but now it's accessible. 00:14:39.000 --> 00:14:42.000 So when you go, string goes, oh, yeah, that thing, and 00:14:42.000 --> 00:14:44.000 actually compiles. 00:14:44.000 --> 00:14:46.000 Now most of today, I'm not going to be hitting you with C++ and saying, 00:14:46.000 --> 00:14:49.000 you must know this. You must know this. There's just not enough time to 00:14:49.000 --> 00:14:50.000 go over everything, 00:14:50.000 --> 00:14:53.000 but this little line might be something worth committing to memory because it's 00:14:53.000 --> 00:14:56.000 the most noticeable change you'll see when you stop using Genlib. 00:14:56.000 --> 00:14:59.000 If you don't put that line in your code, you'll get lots of compiler errors, and it will 00:14:59.000 --> 00:15:00.000 just scare you. 00:15:00.000 --> 00:15:02.000 So if you put this line in, 00:15:02.000 --> 00:15:06.000 I'd say 90 percent of your compiler problems will go away. 00:15:06.000 --> 00:15:07.000 That's that line. 00:15:07.000 --> 00:15:10.000 That's Genlib, and if you want to take a look, 00:15:10.000 --> 00:15:13.000 if you right this code, you basically replace all of 00:15:13.000 --> 00:15:16.000 Genlib. The first header file you'll have to include is this one, CSTDLIB, the C 00:15:16.000 --> 00:15:18.000 standard library. 00:15:18.000 --> 00:15:22.000 I'm thinking that when the invented the C programing language, it cost them 00:15:22.000 --> 00:15:26.000 several million dollars per consonant or vowel they put in their header files. 00:15:26.000 --> 00:15:30.000 So they put it as small as possible but still readable. The idea 00:15:30.000 --> 00:15:32.000 is that you have these two lines. 00:15:32.000 --> 00:15:33.000 Pound include string 00:15:33.000 --> 00:15:35.000 using the standard name 00:15:35.000 --> 00:15:38.000 space. Then right here in this error function, you just 00:15:38.000 --> 00:15:41.000 print everything to C error, which is like C out. It's just designed for error 00:15:41.000 --> 00:15:45.000 handling. You call exit minus one, which says, quit this program. Report some error to 00:15:45.000 --> 00:15:49.000 the operating system and we're done. 00:15:49.000 --> 00:15:52.000 This is it. This is all that is contained in Genlib, and 00:15:52.000 --> 00:15:54.000 the only two important lines are these two right here. 00:15:54.000 --> 00:15:57.000 Including the string class and using the standard name space. If you do 00:15:57.000 --> 00:15:58.000 that, 00:15:58.000 --> 00:16:00.000 and you get [inaudible] Genlib, 00:16:00.000 --> 00:16:03.000 you're going to be in perfectly good shape. 00:16:03.000 --> 00:16:06.000 Now, Genlib is probably one of the easier ones, but what about some of these other 00:16:06.000 --> 00:16:08.000 headers you've seen? 00:16:08.000 --> 00:16:11.000 I could go into some detail about all of these, but I don't have 00:16:11.000 --> 00:16:14.000 time. I really wish I could show you how these work, 00:16:14.000 --> 00:16:17.000 but I'm going to give you a quick overview today 00:16:17.000 --> 00:16:19.000 to show you what you'll need to know if you want to get off these 00:16:19.000 --> 00:16:21.000 libraries. 00:16:21.000 --> 00:16:25.000 The first one is [inaudible]. This is the one that gives you string to integer, 00:16:25.000 --> 00:16:30.000 integer to string, string to reel, convert to uppercase, convert to lowercase, etc. 00:16:30.000 --> 00:16:32.000 Behind the scenes, most of this stuff is backed by this class called a string stream. You've seen 00:16:32.000 --> 00:16:33.000 [inaudible] 00:16:33.000 --> 00:16:37.000 streams, you've seen - they're all streams. You can do 00:16:37.000 --> 00:16:39.000 less than, you can do greater than. 00:16:39.000 --> 00:16:42.000 The point of the string stream, it does the same thing, except that 00:16:42.000 --> 00:16:44.000 it writes to a string buffer. 00:16:44.000 --> 00:16:48.000 So you can take some integer, dump it into a string, that's your integer to 00:16:48.000 --> 00:16:49.000 string function right there. 00:16:49.000 --> 00:16:52.000 There's a couple other things you can do with it. We use it for doing 00:16:52.000 --> 00:16:52.000 00:16:52.000 --> 00:16:56.000 conversion between strings in other data types like integers. 00:16:56.000 --> 00:16:59.000 So you might want to look into that if you want to play around with it. 00:16:59.000 --> 00:17:01.000 As for convert to upper or lower case, 00:17:01.000 --> 00:17:04.000 there are these functions, two upper and two lower, that take individual characters 00:17:04.000 --> 00:17:07.000 and convert them to upper or lower case. Just 00:17:07.000 --> 00:17:10.000 fore loop over your string. Call that function every time. 00:17:10.000 --> 00:17:13.000 Presto. Your string is in uppercase. That was pretty straightforward. 00:17:13.000 --> 00:17:16.000 If you're interested, in CS106L, we actually wrote some of these 00:17:16.000 --> 00:17:20.000 functions. If you want to have a working implementation of [inaudible], if you go to 00:17:20.000 --> 00:17:24.000 the CS106L web site, under the code section, there is a working implementation 00:17:24.000 --> 00:17:26.000 there. So if you want to keep using these things, 00:17:26.000 --> 00:17:28.000 just go download that file, take a look at it, 00:17:28.000 --> 00:17:31.000 play around with it, and it should work. 00:17:31.000 --> 00:17:32.000 So 00:17:32.000 --> 00:17:34.000 if you wanted to set up a 00:17:34.000 --> 00:17:36.000 coding environment on some 00:17:36.000 --> 00:17:38.000 Linux machine that 00:17:38.000 --> 00:17:41.000 doesn't have any of the standard PC or Mac startup files, 00:17:41.000 --> 00:17:46.000 we can just use that? Yeah, it uses only standard C++, so it will compile everywhere. 00:17:46.000 --> 00:17:49.000 It works pretty well. I think we only defined a few of them, but you 00:17:49.000 --> 00:17:51.000 can see how they work, and you can define it for 00:17:51.000 --> 00:17:55.000 - you can do string to integer, string to double or string to reel pretty easily just be changing a 00:17:55.000 --> 00:18:00.000 couple types around. Okay. 00:18:00.000 --> 00:18:03.000 This is probably the big one you're going to miss. Sympio.H. 00:18:03.000 --> 00:18:09.000 How many of you have ever played around with raw C++ input functions before? 00:18:09.000 --> 00:18:12.000 They're kind of nasty. I've always thought this thing called C in, which 00:18:12.000 --> 00:18:15.000 is the counterpart of C out that does input, is kind of like a rose. It's 00:18:15.000 --> 00:18:19.000 very sweet. It's very delicate, but the second you break it, it stabs you with a thorn, 00:18:19.000 --> 00:18:22.000 and it hurts a lot. 00:18:22.000 --> 00:18:25.000 Really, you have to think of this as probably one of the most powerful one of 00:18:25.000 --> 00:18:29.000 the hardest-to-use input libraries out of any programing language you'll see. 00:18:29.000 --> 00:18:32.000 We gave you this Sympio library just to take care of all these things for you so 00:18:32.000 --> 00:18:34.000 you don't have to worry about 00:18:34.000 --> 00:18:36.000 it. 00:18:36.000 --> 00:18:39.000 Everybody remember get line? You can use it to get a line out of a file? 00:18:39.000 --> 00:18:43.000 You can use get line on this C in stream to do input reading. 00:18:43.000 --> 00:18:44.000 Real line as text 00:18:44.000 --> 00:18:46.000 uses string stream to convert it to an integer, 00:18:46.000 --> 00:18:49.000 plus or minus a couple extra things. That's get integer. 00:18:49.000 --> 00:18:52.000 Again, if you go to the CS106L web site, there is a working implementation of 00:18:52.000 --> 00:18:53.000 this. 00:18:53.000 --> 00:18:56.000 If you do want to consider doing C++ beyond this, it actually is 00:18:56.000 --> 00:19:00.000 a pretty good set of input functions. You'd be surprised how many people don't 00:19:00.000 --> 00:19:01.000 actually know how to write these things. 00:19:01.000 --> 00:19:04.000 Go fire it up. Have some fun, 00:19:04.000 --> 00:19:05.000 see what they do and 00:19:05.000 --> 00:19:07.000 that way, you continue using the coding conventions that you've seen 00:19:07.000 --> 00:19:12.000 but by only using standard C++. What about 00:19:12.000 --> 00:19:14.000 random? 00:19:14.000 --> 00:19:17.000 The random functions in C++ are 00:19:17.000 --> 00:19:21.000 pretty simple. There's two functions, rand and Crand. 00:19:21.000 --> 00:19:23.000 Random and C, the randomizer. Again, 00:19:23.000 --> 00:19:27.000 consonants are expensive, vowels are expensive. 00:19:27.000 --> 00:19:30.000 Rand gives you random integers in the range zero 00:19:30.000 --> 00:19:31.000 to rand max. 00:19:31.000 --> 00:19:34.000 So if you want to get a random double, you want to get a random integer, a random Goulian, 00:19:34.000 --> 00:19:39.000 just take the number in that range, scale it down to zero one, scale it back up, translate it, 00:19:39.000 --> 00:19:40.000 etc. 00:19:40.000 --> 00:19:42.000 It turns out that this is probably the easiest one to rewrite from scratch. You just have to 00:19:42.000 --> 00:19:46.000 be a little bit careful of how you do our bounce checking, but it's not so bad. 00:19:46.000 --> 00:19:49.000 The header file for that is C standard library, but you can probably build 00:19:49.000 --> 00:19:53.000 this one up from scratch pretty simply. 00:19:53.000 --> 00:19:56.000 The one that you actually are going to be missing is this one. 00:19:56.000 --> 00:19:58.000 Graphics.H and extended graphics. 00:19:58.000 --> 00:20:02.000 Unfortunately, C++ does not have a standard graphics library. It 00:20:02.000 --> 00:20:05.000 just doesn't exist. There's a couple reasons. One, it's very hard to 00:20:05.000 --> 00:20:08.000 standardize graphics. You have to make sure that it's something that works on every, 00:20:08.000 --> 00:20:10.000 single platform, which is very hard to do. 00:20:10.000 --> 00:20:13.000 Also, if you're writing C++ code from a microprocessor where 00:20:13.000 --> 00:20:16.000 you don't have graphics, it would be difficult to support the 00:20:16.000 --> 00:20:18.000 library. 00:20:18.000 --> 00:20:21.000 So there's no standard C++ equivalent, but I bet you this program 00:20:21.000 --> 00:20:24.000 that I'm using right now is written in C++. It's got some kind of 00:20:24.000 --> 00:20:25.000 graphics. 00:20:25.000 --> 00:20:27.000 Most of this is from third-party libraries. I do 00:20:27.000 --> 00:20:29.000 some Windows programing, so I use - for the Win32 API, which does some 00:20:29.000 --> 00:20:31.000 graphics stuff. 00:20:31.000 --> 00:20:35.000 There's a bunch of cross-platform ones like open GL. You can do X Window system. 00:20:35.000 --> 00:20:36.000 I think Mac's is called Carbon. I 00:20:36.000 --> 00:20:38.000 might be wrong about that. 00:20:38.000 --> 00:20:41.000 [Crosstalk] Yeah, 00:20:41.000 --> 00:20:44.000 there's a lot, and you won't have trouble finding it. You just won't 00:20:44.000 --> 00:20:47.000 have a standard library that does it for you. So shop around with this. The 00:20:47.000 --> 00:20:48.000 00:20:48.000 --> 00:20:50.000 ones we give you are pretty nice. 00:20:50.000 --> 00:20:53.000 I might tell you how they work except that I don't know because it's 00:20:53.000 --> 00:20:55.000 really, really hard. 00:20:55.000 --> 00:21:00.000 So take a look around, and you'll find some ones that are quite nice. 00:21:00.000 --> 00:21:02.000 Everything I've shown you up to this point are simple, like 00:21:02.000 --> 00:21:03.000 how to read input, 00:21:03.000 --> 00:21:04.000 how to convert to a string, 00:21:04.000 --> 00:21:07.000 things that, while they're nice and important, are not going to 00:21:07.000 --> 00:21:08.000 make or break your program. 00:21:08.000 --> 00:21:11.000 The thing that is going to make a difference are 00:21:11.000 --> 00:21:12.000 these ADTs. 00:21:12.000 --> 00:21:14.000 The vector, the set, the map, 00:21:14.000 --> 00:21:15.000 the stack, the queue. 00:21:15.000 --> 00:21:16.000 Those are important. 00:21:16.000 --> 00:21:17.000 If you don't have a map, 00:21:17.000 --> 00:21:20.000 the number of things you can do in a program drops exponentially. 00:21:20.000 --> 00:21:24.000 It's really impressive how much you need these data structures. 00:21:24.000 --> 00:21:27.000 The good news is that C++ not only has a very good support for these data 00:21:27.000 --> 00:21:31.000 structures, it has probably the best library in any standard programming 00:21:31.000 --> 00:21:32.000 language 00:21:32.000 --> 00:21:33.000 that does these things for you. 00:21:33.000 --> 00:21:37.000 It's called the Standard Template Library, which is the 00:21:37.000 --> 00:21:41.000 STL. For every, single container class you have seen in this class, all the ADTs, 00:21:41.000 --> 00:21:42.000 you will find them in the STL. 00:21:42.000 --> 00:21:46.000 The names might be a little bit different, the syntax is a little bit weirder, but conceptually, 00:21:46.000 --> 00:21:49.000 it's the same thing. A vector is a vector, no matter what language 00:21:49.000 --> 00:21:51.000 you write it 00:21:51.000 --> 00:21:54.000 in. The STL 00:21:54.000 --> 00:21:57.000 on top of that gives you these things called algorithms. 00:21:57.000 --> 00:22:00.000 I'll talk about this in a little bit. 00:22:00.000 --> 00:22:02.000 Basically, it's the best thing since sliced bread. 00:22:02.000 --> 00:22:06.000 I'm not kidding. It's really wonderful and amazing, and I'll talk about that in a 00:22:06.000 --> 00:22:07.000 little bit. 00:22:07.000 --> 00:22:10.000 The STL is one of the major features of the C++ standard library. 00:22:10.000 --> 00:22:11.000 It's 00:22:11.000 --> 00:22:12.000 brilliantly designed. 00:22:12.000 --> 00:22:13.000 It's not necessarily 00:22:13.000 --> 00:22:17.000 the most intuitive thing, but once you get a handle of it, it's very 00:22:17.000 --> 00:22:20.000 powerful. 00:22:20.000 --> 00:22:23.000 The way you can visualize what this looks like is as this 00:22:23.000 --> 00:22:25.000 somewhat pyramid 00:22:25.000 --> 00:22:25.000 structure. 00:22:25.000 --> 00:22:27.000 At the very bottom, you've got containers. 00:22:27.000 --> 00:22:31.000 Your data structures, this is your vector, you map, your set. 00:22:31.000 --> 00:22:33.000 You have iterators on top of that. You've all seen iterators in this class. 00:22:33.000 --> 00:22:36.000 You've seen map and set iterators. 00:22:36.000 --> 00:22:37.000 The STL is basically 00:22:37.000 --> 00:22:41.000 all about iterators. Every, single container class has 00:22:41.000 --> 00:22:42.000 iterators. 00:22:42.000 --> 00:22:45.000 You can iterate over a vector or map or set. 00:22:45.000 --> 00:22:46.000 Those worked 00:22:46.000 --> 00:22:49.000 to build these things called algorithms where they're 00:22:49.000 --> 00:22:51.000 functions that operate on ranges of data. 00:22:51.000 --> 00:22:54.000 It's really impressive what you can do with these things. I'll show you a 00:22:54.000 --> 00:22:57.000 little bit of that 00:22:57.000 --> 00:23:01.000 later. These container classes, the good news is that the names are pretty similar. 00:23:01.000 --> 00:23:04.000 Basically, take the 106 version, make it lowercase, you've got your 00:23:04.000 --> 00:23:08.000 STL. So big vector turns into little vector. Big map turns into little map, 00:23:08.000 --> 00:23:13.000 etc. One exception is grid. There is no STL grid class. It's very easy to 00:23:13.000 --> 00:23:16.000 make one. All you have to do is take a vector and do some math to wrap 00:23:16.000 --> 00:23:20.000 a two-dimensional container into a one-dimensional one. In fact, that's how our 00:23:20.000 --> 00:23:22.000 grid works, so you'll have to build that one. 00:23:22.000 --> 00:23:25.000 Otherwise, everything's taken care for you, and that's nice. 00:23:25.000 --> 00:23:28.000 Again, they have the same fundamental abstractions. You know how to work with a 00:23:28.000 --> 00:23:33.000 stack, so you know how to use the STL stack with a little extra syntax. 00:23:33.000 --> 00:23:34.000 The big thing I will say up front, 00:23:34.000 --> 00:23:36.000 the emphasis in the STL 00:23:36.000 --> 00:23:37.000 is on speed. 00:23:37.000 --> 00:23:40.000 In fact, they are designed to be really, really fast. 00:23:40.000 --> 00:23:45.000 That means their notion of safety is, good one. 00:23:45.000 --> 00:23:48.000 So what this means is you'll have to do your own bounce checking. 00:23:48.000 --> 00:23:50.000 When you're iterating, you'll have to make sure you don't walk off the edge of your 00:23:50.000 --> 00:23:51.000 container 00:23:51.000 --> 00:23:52.000 and stuff like that. 00:23:52.000 --> 00:23:56.000 One of the major reasons we didn't go over the STL in this class 00:23:56.000 --> 00:23:57.000 is that, 00:23:57.000 --> 00:24:00.000 which is if you're trying to figure out how to work with a vector, it's 00:24:00.000 --> 00:24:03.000 really bad if you also have to worry about doing your own bounce checking. 00:24:03.000 --> 00:24:05.000 If you're working with a map and you have to use the STL map, 00:24:05.000 --> 00:24:07.000 you probably wouldn't ever want to use another map 00:24:07.000 --> 00:24:09.000 for the rest of your life. It's pretty complicated. 00:24:09.000 --> 00:24:12.000 The point is this is what you'll see in the professional environment because it's a very good library, and it's very 00:24:12.000 --> 00:24:16.000 fast. 00:24:16.000 --> 00:24:19.000 I want to give you a quick example of what this might look like. 00:24:19.000 --> 00:24:22.000 This is a program I've written using the CS106 vector. I want to go 00:24:22.000 --> 00:24:24.000 change it to use the STL to show you 00:24:24.000 --> 00:24:28.000 it's the same thing with a little bit different syntax. 00:24:28.000 --> 00:24:32.000 The first thing you have to do is say, the Specter.H we gave you, so you have 00:24:32.000 --> 00:24:33.000 to change that to the standard vector, 00:24:33.000 --> 00:24:36.000 which is vector in brackets. 00:24:36.000 --> 00:24:40.000 Number of characters we have changed so far. Three characters. 00:24:40.000 --> 00:24:44.000 Next thing, the big vector becomes little vector. Four characters. 00:24:44.000 --> 00:24:48.000 The only big difference is this add function. Anyone who isn't in 00:24:48.000 --> 00:24:50.000 my class want to guess 00:24:50.000 --> 00:24:54.000 what you would call the function to append something to the end of a vector? Anyone 00:24:54.000 --> 00:24:57.000 want to take a guess? [Inaudible]. 00:24:57.000 --> 00:24:58.000 Append? That would 00:24:58.000 --> 00:25:02.000 be nice. It's actually called push back. 00:25:02.000 --> 00:25:05.000 There's good reason for this. It means all these different containers 00:25:05.000 --> 00:25:08.000 have similar function names. Push back, 00:25:08.000 --> 00:25:09.000 append, potato, 00:25:09.000 --> 00:25:12.000 potato. 00:25:12.000 --> 00:25:15.000 Okay. That's probably about ten or eleven character changes. Then 00:25:15.000 --> 00:25:16.000 to loop over the thing, 00:25:16.000 --> 00:25:18.000 it's exactly what you've seen before. 00:25:18.000 --> 00:25:19.000 There is a size function. 00:25:19.000 --> 00:25:23.000 There are brackets. You can go and iterate. You can go and access things. 00:25:23.000 --> 00:25:26.000 The result, as you can see, is not that different. 00:25:26.000 --> 00:25:28.000 There are a couple subtleties that I didn't go into here about how the 00:25:28.000 --> 00:25:32.000 STL behaves different from the vector you've seen, but overall, it 00:25:32.000 --> 00:25:36.000 is the same container. 00:25:36.000 --> 00:25:39.000 The other one I want to call your attention to is the STL map. 00:25:39.000 --> 00:25:42.000 So if you work with the STL, you need to know two containers, and the rest 00:25:42.000 --> 00:25:44.000 follow from there. If you know vector and you know map, 00:25:44.000 --> 00:25:46.000 you've got the whole thing down. 00:25:46.000 --> 00:25:50.000 The STL map is like our map except that instead of going string to some value, it's 00:25:50.000 --> 00:25:51.000 any key type you want 00:25:51.000 --> 00:25:53.000 to any value type you want. 00:25:53.000 --> 00:25:56.000 So you can map strings to ints, you can map ints to strings, 00:25:56.000 --> 00:26:00.000 you can map stack of queue of int to vector of double. 00:26:00.000 --> 00:26:04.000 I don't know why you would, but you have the ability to do so. 00:26:04.000 --> 00:26:07.000 The problem is that the interface on map 00:26:07.000 --> 00:26:11.000 was probably designed by someone who didn't like people. It's really hard 00:26:11.000 --> 00:26:14.000 to use. Anyone who has used it will tell you that. Once you 00:26:14.000 --> 00:26:17.000 get the hang of it, though, it's pretty intuitive. The result is you have a 00:26:17.000 --> 00:26:22.000 very fast map container that is going to be the backbone of any of the programs that you write. 00:26:22.000 --> 00:26:23.000 It's quite a useful class. 00:26:23.000 --> 00:26:26.000 Again, I don't expect you to memorize every, single bit of syntax here, 00:26:26.000 --> 00:26:27.000 everything I'm saying. 00:26:27.000 --> 00:26:29.000 Just keep it in the back of the mind if this is what you want to look into. 00:26:29.000 --> 00:26:33.000 The map you do need to know. Go take a look at that one if you want to 00:26:33.000 --> 00:26:36.000 pursue C++. Now 00:26:36.000 --> 00:26:37.000 iterators. 00:26:37.000 --> 00:26:40.000 So the iterators you've seen in this class are very nice. They're well-behaved. 00:26:40.000 --> 00:26:44.000 Has next, 00:26:44.000 --> 00:26:45.000 next. Has next, 00:26:45.000 --> 00:26:47.000 next. I'm done. [Inaudible] 00:26:47.000 --> 00:26:50.000 iterators are designed to look like pointers. 00:26:50.000 --> 00:26:53.000 You might wonder why anyone would voluntarily make something look like a 00:26:53.000 --> 00:26:54.000 pointer. There's a very good reason. 00:26:54.000 --> 00:26:58.000 This means they're about as smart as a pointer, which means they know 00:26:58.000 --> 00:26:59.000 nothing. 00:26:59.000 --> 00:27:02.000 So if you want to iterate over a range, you have to have two different iterators. You have 00:27:02.000 --> 00:27:03.000 to say start here, 00:27:03.000 --> 00:27:04.000 stop there, 00:27:04.000 --> 00:27:07.000 keep walking forward until you get there. 00:27:07.000 --> 00:27:08.000 Admittedly, 00:27:08.000 --> 00:27:10.000 it's more work, 00:27:10.000 --> 00:27:12.000 but it's very useful because it means that 00:27:12.000 --> 00:27:15.000 if you want to iterate over a 20-element slice out of a 400 00:27:15.000 --> 00:27:17.000 million element container, 00:27:17.000 --> 00:27:19.000 you can do that. Try doing that with our libraries. You have to go iterate all the 00:27:19.000 --> 00:27:21.000 way up the start, 00:27:21.000 --> 00:27:23.000 then keep iterating more. 00:27:23.000 --> 00:27:26.000 The other thing you need to know about the iterators is that they're read/write. 00:27:26.000 --> 00:27:30.000 So you can actually crawl over a container and update the values with an iterator, 00:27:30.000 --> 00:27:32.000 something that you cannot do with our libraries. 00:27:32.000 --> 00:27:35.000 It's a bit more work. The syntax basically looks like pointer reading and 00:27:35.000 --> 00:27:35.000 writing, 00:27:35.000 --> 00:27:40.000 but the result is that they're much more powerful, and they're a lot more flexible. 00:27:40.000 --> 00:27:43.000 Here's a quick example. 00:27:43.000 --> 00:27:46.000 I just wrote some code here that uses a vector iterator. The thing to take a look at is this 00:27:46.000 --> 00:27:49.000 right here. 00:27:49.000 --> 00:27:53.000 So basically, there's a couple parts to point out. I want to show you this so that if you 00:27:53.000 --> 00:27:54.000 see this later on, 00:27:54.000 --> 00:27:57.000 you'll get it. Can everybody see this? 00:27:57.000 --> 00:27:59.000 The first thing is this begin function. 00:27:59.000 --> 00:28:03.000 We call it iterator, they call it begin. It just says, give me a start iterator. 00:28:03.000 --> 00:28:07.000 Since we need two iterators to define a range, we keep going until we hit this iterator called 00:28:07.000 --> 00:28:09.000 N, which means stop. To 00:28:09.000 --> 00:28:13.000 move the iterator forward, has next and next would be too nice, so it's ++, 00:28:13.000 --> 00:28:15.000 and then to read from an iterator or write to it, you just de-reference 00:28:15.000 --> 00:28:17.000 it. 00:28:17.000 --> 00:28:20.000 So you do star iterator, as if it's a pointer, which in many cases, it 00:28:20.000 --> 00:28:22.000 actually is. 00:28:22.000 --> 00:28:24.000 That's the gist of what this looks like. There's a few more nuances 00:28:24.000 --> 00:28:25.000 and subtleties, 00:28:25.000 --> 00:28:28.000 but if you keep in mind that if you're looking at STL stuff, just treat this 00:28:28.000 --> 00:28:34.000 like pointers, it will make a lot of sense. The 00:28:34.000 --> 00:28:37.000 last thing I want to talk about are algorithms. These things are 00:28:37.000 --> 00:28:40.000 amazing. The idea is that everything's got iterators, 00:28:40.000 --> 00:28:42.000 so if you write functions that work on iterators, they will work on any 00:28:42.000 --> 00:28:43.000 container type. 00:28:43.000 --> 00:28:47.000 So if you want a binary search or a vector, you call binary search. 00:28:47.000 --> 00:28:51.000 It's a prewritten function. You want to sort something? Great. Go call sort. 00:28:51.000 --> 00:28:55.000 You guys have seen permutations before, right? You have to go do recursion pulsing in the 00:28:55.000 --> 00:28:58.000 front, permute the rest, stick it back on, that sort of stuff? 00:28:58.000 --> 00:29:00.000 STL, you can do it in a while loop. 00:29:00.000 --> 00:29:02.000 You can while you next permutation something, 00:29:02.000 --> 00:29:05.000 come up with every, single permutation, and you don't have to write a single recursive 00:29:05.000 --> 00:29:07.000 function ever. 00:29:07.000 --> 00:29:10.000 These sorts of things, I think there's 75 different algorithms, anything 00:29:10.000 --> 00:29:12.000 from permuting to searching to sorting, 00:29:12.000 --> 00:29:15.000 to transforming to rearranging to sorting to splitting. 00:29:15.000 --> 00:29:18.000 You name it, there's probably an algorithm that does it. If 00:29:18.000 --> 00:29:19.000 you play around with the STL, 00:29:19.000 --> 00:29:26.000 you get to see all this stuff. It's a lot of fun. 00:29:26.000 --> 00:29:29.000 I've just been showing you some of the libraries. That's basically all the library changes you need to 00:29:29.000 --> 00:29:29.000 know. 00:29:29.000 --> 00:29:32.000 Basically, everything you want to do is still there. 00:29:32.000 --> 00:29:35.000 The syntax is a little different. Some of the libraries you'll have to write yourself, but it's 00:29:35.000 --> 00:29:39.000 all there. It's not like you have to relearn everything from scratch. 00:29:39.000 --> 00:29:42.000 But the libraries are only as good as the language is, 00:29:42.000 --> 00:29:45.000 and there are a couple of language features of C++ that we didn't really talk about 00:29:45.000 --> 00:29:48.000 in this class. I want to go over some of them because you will see them a lot in 00:29:48.000 --> 00:29:50.000 professional code. 00:29:50.000 --> 00:29:53.000 After all, you cannot use a library any more than you understand how the 00:29:53.000 --> 00:29:55.000 language works. So getting a rough understanding of what this will do 00:29:55.000 --> 00:29:59.000 will make your life easier in the long 00:29:59.000 --> 00:30:01.000 run. The first thing I want to talk about is 00:30:01.000 --> 00:30:06.000 const. You've seen const before in the context of const and my context equals five. 00:30:06.000 --> 00:30:10.000 Just make a global constant. Saying that const makes global constants is 00:30:10.000 --> 00:30:13.000 like saying a computer is something that adds numbers. 00:30:13.000 --> 00:30:13.000 Yes, 00:30:13.000 --> 00:30:17.000 but they can also run Windows, for example. 00:30:17.000 --> 00:30:21.000 Const shows up just about everywhere. It's the little keyword that could. 00:30:21.000 --> 00:30:24.000 You'd be amazed just how useful this little keyword can be. 00:30:24.000 --> 00:30:26.000 The biggest thing that it does 00:30:26.000 --> 00:30:29.000 is helps protect you against your own mistakes. 00:30:29.000 --> 00:30:32.000 If you're writing a program and you know something shouldn't change, tag 00:30:32.000 --> 00:30:33.000 it const 00:30:33.000 --> 00:30:36.000 because that way, later down the lie, if you do accidentally change it, it says, 00:30:36.000 --> 00:30:39.000 that's a mistake. Compiler error. You screwed up. 00:30:39.000 --> 00:30:42.000 It protects you. That should've been a double equal, not 00:30:42.000 --> 00:30:44.000 a single equal, 00:30:44.000 --> 00:30:46.000 those sorts of things. 00:30:46.000 --> 00:30:49.000 You've all probably seen that the C++ compiler doesn't treat anything as sacred. Like, oh, you don't 00:30:49.000 --> 00:30:51.000 want to return 00:30:51.000 --> 00:30:56.000 something? Or something like, oh, wow, you did single equal instead of double equal. 00:30:56.000 --> 00:30:57.000 You're the boss. 00:30:57.000 --> 00:31:00.000 The second you try to break const, it pulls out its big ruler of judgment and 00:31:00.000 --> 00:31:04.000 whacks you on the wrist with it, like shame on your for breaking this constants. It 00:31:04.000 --> 00:31:06.000 is the compiler trying to help you out. 00:31:06.000 --> 00:31:08.000 Please know about this keyword. I'll give you 00:31:08.000 --> 00:31:11.000 an example. See 00:31:11.000 --> 00:31:15.000 this function prototype? Void do something takes a vector by reference. 00:31:15.000 --> 00:31:18.000 So I've passed my vector into this function, and the question is, what's it going to 00:31:18.000 --> 00:31:20.000 hold when it comes back? 00:31:20.000 --> 00:31:22.000 Well, it could be the same. It 00:31:22.000 --> 00:31:25.000 could be completely empty. There could be 137 copies of the 00:31:25.000 --> 00:31:26.000 number 137. 00:31:26.000 --> 00:31:28.000 You don't know. 00:31:28.000 --> 00:31:31.000 In this class, we've shown you, pass by reference can be either for 00:31:31.000 --> 00:31:33.000 efficiency reasons because it's not fast enough, 00:31:33.000 --> 00:31:35.000 or it can be 00:31:35.000 --> 00:31:37.000 because you want to actually change the thing. 00:31:37.000 --> 00:31:40.000 It's difficult to see what this function does because you have no idea 00:31:40.000 --> 00:31:43.000 which of those two it is. 00:31:43.000 --> 00:31:46.000 The idea, though, and this is something that you will see in professional code everywhere, 00:31:46.000 --> 00:31:48.000 is doing something like this. 00:31:48.000 --> 00:31:51.000 If I say, void do something const 00:31:51.000 --> 00:31:53.000 vector and my vector, 00:31:53.000 --> 00:31:56.000 that says that this vector can't be modified within the function. 00:31:56.000 --> 00:32:00.000 It's like handing this thing off saying, I'm giving you this value 00:32:00.000 --> 00:32:01.000 for efficiency reasons. 00:32:01.000 --> 00:32:04.000 Donft try to modify it. In fact, you can't modify it. 00:32:04.000 --> 00:32:07.000 It makes your code self-documenting. Someone looking at your functions can go, 00:32:07.000 --> 00:32:09.000 that's const. I can't possibly change anything there, 00:32:09.000 --> 00:32:13.000 and they'll be totally fine handing off the string containing their graduate thesis 00:32:13.000 --> 00:32:14.000 to it, for example. 00:32:14.000 --> 00:32:18.000 If you had your graduate thesis stored as a string, 00:32:18.000 --> 00:32:19.000 which I don't 00:32:19.000 --> 00:32:20.000 know why you would ever do this, 00:32:20.000 --> 00:32:24.000 but if you see a function take the string and parameter, you'd probably be a little 00:32:24.000 --> 00:32:27.000 bit worried. Like, is it going to replace my graduate thesis with, 00:32:27.000 --> 00:32:30.000 hi, I don't have a graduate thesis or what? 00:32:30.000 --> 00:32:34.000 The const is useful. 00:32:34.000 --> 00:32:36.000 The question is, if it's such a useful keyword, 00:32:36.000 --> 00:32:39.000 why didn't we show you this? 00:32:39.000 --> 00:32:43.000 The biggest reason is you can't just use const every now and then. You can't say, I'm going 00:32:43.000 --> 00:32:47.000 to mark this parameter const. I'm gong to say that one's const right there. It 00:32:47.000 --> 00:32:48.000 doesn't work that way. 00:32:48.000 --> 00:32:52.000 Let's say I do mark something const. That object has to know how to behave 00:32:52.000 --> 00:32:53.000 when it can't modify itself. 00:32:53.000 --> 00:32:56.000 So you have to make the entire class written const correct. 00:32:56.000 --> 00:32:59.000 Then if it has any data members that are classes, that class has to be const correct. You get this 00:32:59.000 --> 00:33:00.000 00:33:00.000 --> 00:33:01.000 exploding effect where 00:33:01.000 --> 00:33:05.000 you stick a singe const in, and suddenly every, single piece of your code is marked 00:33:05.000 --> 00:33:06.000 const. 00:33:06.000 --> 00:33:09.000 That's a good thing because it makes your code self-documenting, 00:33:09.000 --> 00:33:13.000 but the point is it's an unnecessary language complication. When 00:33:13.000 --> 00:33:16.000 you're trying to write the PQ class, you should be worried, how do I build a 00:33:16.000 --> 00:33:17.000 chunk list, not oh, 00:33:17.000 --> 00:33:20.000 is this function const? So in the 00:33:20.000 --> 00:33:23.000 professional world, you will see it. Here we thought, it makes things too 00:33:23.000 --> 00:33:28.000 complicated. We'll give it a pass for right 00:33:28.000 --> 00:33:30.000 now. Another big one. Object copying an assignment. 00:33:30.000 --> 00:33:34.000 You've seen disallow copy. It says, don't copy this 00:33:34.000 --> 00:33:38.000 object. It's not standard C++, but I've been told that Google actually 00:33:38.000 --> 00:33:41.000 has a macro that does something just like this, so you're programming the same way Google 00:33:41.000 --> 00:33:42.000 people do. 00:33:42.000 --> 00:33:43.000 The difference is that 00:33:43.000 --> 00:33:45.000 if you're trying to write a PQ 00:33:45.000 --> 00:33:47.000 and it can't copy itself, 00:33:47.000 --> 00:33:51.000 it's a little bit frustrating. Think about it. You make some PQ. You can make a vector 00:33:51.000 --> 00:33:51.000 copy. 00:33:51.000 --> 00:33:52.000 You can make a map copy. 00:33:52.000 --> 00:33:56.000 If you can't make a PQ copy, you'll be wondering, why not? 00:33:56.000 --> 00:33:59.000 So it turns out C++ lets you redefine the way copying 00:33:59.000 --> 00:34:01.000 works. So these two functions here 00:34:01.000 --> 00:34:04.000 called copy constructors and assignment operators. 00:34:04.000 --> 00:34:07.000 While it's very useful to know how to do this, there's a major reason we didn't tell 00:34:07.000 --> 00:34:08.000 you about it in this class. 00:34:08.000 --> 00:34:12.000 It's because it's really hard. 00:34:12.000 --> 00:34:16.000 I think I spent, in 106L, an entire week going over this. 00:34:16.000 --> 00:34:18.000 We don't have a week to tell you how to do this. 00:34:18.000 --> 00:34:21.000 Here's a list of some of the things you have to keep in mind when writing these 00:34:21.000 --> 00:34:21.000 functions. 00:34:21.000 --> 00:34:25.000 [Inaudible] to clean up your own memory, not memory you don't own. To clean 00:34:25.000 --> 00:34:28.000 up the memory, to copy an object, to copy the object correctly, to handle 00:34:28.000 --> 00:34:31.000 these [inaudible], to follow the same rules that C++ syntax dictates. 00:34:31.000 --> 00:34:34.000 There's an awful lot of stuff going on there. 00:34:34.000 --> 00:34:37.000 To expect you to get all this right when you're worrying about your PQ is just 00:34:37.000 --> 00:34:37.000 too much. 00:34:37.000 --> 00:34:40.000 It really is. 00:34:40.000 --> 00:34:41.000 Imagine it's the day before it's due. 00:34:41.000 --> 00:34:43.000 You've got the PQ working beautifully, and 00:34:43.000 --> 00:34:45.000 it doesn't copy 00:34:45.000 --> 00:34:49.000 right. What does that tell you? You've written your copy function wrong, but you totally 00:34:49.000 --> 00:34:50.000 understand and made your point, 00:34:50.000 --> 00:34:52.000 which is how to build a priority queue. 00:34:52.000 --> 00:34:54.000 This is a chunk list. This is a heap. 00:34:54.000 --> 00:34:55.000 This is an unsorted 00:34:55.000 --> 00:34:58.000 vector. That's what's actually important, not building stuff like this. 00:34:58.000 --> 00:35:00.000 When you're in the professional world, 00:35:00.000 --> 00:35:03.000 you do need to do some extra work to make your objects copy 00:35:03.000 --> 00:35:07.000 correctly. So you should look into these functions a little bit. 00:35:07.000 --> 00:35:08.000 Again, to stress, 00:35:08.000 --> 00:35:11.000 the stuff you've learned in here, the actual here's how you build these data 00:35:11.000 --> 00:35:14.000 structures, is more important than these global syntactic nuances that you've got to be 00:35:14.000 --> 00:35:18.000 aware of. 00:35:18.000 --> 00:35:20.000 One more thing. This is pretty cool. 00:35:20.000 --> 00:35:22.000 I have this 00:35:22.000 --> 00:35:23.000 code snippet right here. 00:35:23.000 --> 00:35:24.000 I make a string, 00:35:24.000 --> 00:35:25.000 and I say, 00:35:25.000 --> 00:35:30.000 my string is equal to this is, and then I tack onto it, a string. 00:35:30.000 --> 00:35:32.000 I'm going to iterate over this entire string, 00:35:32.000 --> 00:35:35.000 and every step, I'm going to print out the current character. So 00:35:35.000 --> 00:35:37.000 this is just print out the string 00:35:37.000 --> 00:35:39.000 one letter at a time. Ifm going to 00:35:39.000 --> 00:35:42.000 highlight a few things. 00:35:42.000 --> 00:35:45.000 Why is it legal to [inaudible] equals a string with something else? 00:35:45.000 --> 00:35:48.000 Why string but not priority queue? Why are we allow to do this? 00:35:48.000 --> 00:35:50.000 It's a string. It's an 00:35:50.000 --> 00:35:54.000 object, and we just code plus equals on it. 00:35:54.000 --> 00:35:56.000 Why does it let you do less than, less than? 00:35:56.000 --> 00:35:59.000 What does that mean? Why do streams let you do that but nothing else? Why can 00:35:59.000 --> 00:36:03.000 I read a string with brackets even though it's really an object? 00:36:03.000 --> 00:36:07.000 At a high level, we all know what it means to add something to a string. It 00:36:07.000 --> 00:36:11.000 means take something and stick it on. You know what this less than, less than. It means put into 00:36:11.000 --> 00:36:14.000 a stream. 00:36:14.000 --> 00:36:18.000 [Inaudible] C++, I want to define these operators for my classes. 00:36:18.000 --> 00:36:21.000 It's a technique known as operator overloading. 00:36:21.000 --> 00:36:25.000 Basically, all you do is write functions that are called operator and 00:36:25.000 --> 00:36:28.000 whatever the name of your operator is. So operator equals, operator brackets, operator 00:36:28.000 --> 00:36:29.000 less than, less than. 00:36:29.000 --> 00:36:30.000 Operator plus, plus. 00:36:30.000 --> 00:36:34.000 It's just a syntax convenience. You can write code that looks more 00:36:34.000 --> 00:36:34.000 intuitive 00:36:34.000 --> 00:36:37.000 that does something complex behind the scenes. For 00:36:37.000 --> 00:36:41.000 example, if I write my vector bracket I, it's not like, oh, it's a bracket. It's much 00:36:41.000 --> 00:36:43.000 faster. It really means, call the function called 00:36:43.000 --> 00:36:45.000 operator brackets. 00:36:45.000 --> 00:36:49.000 Again, it's a convenience and nothing else. If you treat it as anything more than a 00:36:49.000 --> 00:36:51.000 convenience, you can kind of hurt yourself with it. 00:36:51.000 --> 00:36:54.000 You can overload basically every operator in C++. You can 00:36:54.000 --> 00:36:58.000 overload things like bit wise [inaudible] with assignment. You can overload the 00:36:58.000 --> 00:37:01.000 exore operator. You can overload parenthesis, and, comma, 00:37:01.000 --> 00:37:03.000 all these operators that most people never use. 00:37:03.000 --> 00:37:06.000 The ones that you see most frequently, though, are these 00:37:06.000 --> 00:37:09.000 ones. Overloading operator less than, less than for stream insertion. 00:37:09.000 --> 00:37:12.000 You can actually make it so that you can make a vector class than 00:37:12.000 --> 00:37:15.000 can print itself out to the screen. It's kind 00:37:15.000 --> 00:37:17.000 of useful. The assignment operator, operator equals, 00:37:17.000 --> 00:37:20.000 the less than operator for comparing things and the parentheses operator. 00:37:20.000 --> 00:37:23.000 You can actually overload parentheses. It's pretty cool stuff. It's 00:37:23.000 --> 00:37:27.000 actually for something called functors, which is really awesome. If you do play around with 00:37:27.000 --> 00:37:30.000 C++, this is definitely something to keep in mind because it will make your 00:37:30.000 --> 00:37:33.000 life a lot more enjoyable. 00:37:33.000 --> 00:37:36.000 I think more than any other language features, C++, except possibly 00:37:36.000 --> 00:37:40.000 multiple inherence, this is the most widely-criticized 00:37:40.000 --> 00:37:41.000 feature of the language. 00:37:41.000 --> 00:37:44.000 The reason is that you can make things that make no sense legal. 00:37:44.000 --> 00:37:47.000 Like, defining the modular operator for two 00:37:47.000 --> 00:37:50.000 PQ. My PQ, my other PQ. Anybody think 00:37:50.000 --> 00:37:54.000 of a sensible interpretation of what it means to mod one PQ by 00:37:54.000 --> 00:37:57.000 another? If you do, please send me an email or 00:37:57.000 --> 00:37:59.000 shout it out right now. I can't think of one. 00:37:59.000 --> 00:38:01.000 But you can make it legal. 00:38:01.000 --> 00:38:04.000 I don't know why you would, but you can. 00:38:04.000 --> 00:38:05.000 The point of this is, if you think 00:38:05.000 --> 00:38:07.000 about it, call it the philosophy. Let 00:38:07.000 --> 00:38:11.000 the programmer make the choice, even if it lets them choose wrong. 00:38:11.000 --> 00:38:14.000 You can do this. You probably shouldn't do it, but 00:38:14.000 --> 00:38:16.000 by giving you the opportunity to do so, 00:38:16.000 --> 00:38:19.000 it means that when you really do need to write a class that has a module 00:38:19.000 --> 00:38:21.000 that's defined, you can do it. 00:38:21.000 --> 00:38:22.000 It's flexibility. It 00:38:22.000 --> 00:38:23.000 means that you have to 00:38:23.000 --> 00:38:30.000 make sure that what you're doing makes sense, but it's flexibility. You've 00:38:30.000 --> 00:38:32.000 all just finished Pathfinder, right? 00:38:32.000 --> 00:38:37.000 Did anybody templatize the [inaudible] PQ, by any chance? Anyone? You guys 00:38:37.000 --> 00:38:39.000 are smart. 00:38:39.000 --> 00:38:44.000 Here's the thing. Let's say I wrote something that says, A equals B. 00:38:44.000 --> 00:38:47.000 What does this mean? It says assign B 00:38:47.000 --> 00:38:49.000 A. What if I write this in a template function? 00:38:49.000 --> 00:38:53.000 I have a template of some unknown type. I'll just say A equals B. 00:38:53.000 --> 00:38:54.000 What's it mean? 00:38:54.000 --> 00:38:58.000 Well, if it's an int, it means take the int and copy it. If it's a floating point 00:38:58.000 --> 00:39:01.000 number, it says take the floating point number and copy it. If 00:39:01.000 --> 00:39:04.000 it's a string, it says make a string deep copy. 00:39:04.000 --> 00:39:08.000 The point is that every, single time you use this same syntax, A equals B, 00:39:08.000 --> 00:39:11.000 but the result is different, and it's always the correct result. 00:39:11.000 --> 00:39:15.000 This is what you can get with operator [inaudible], the ability to take code 00:39:15.000 --> 00:39:19.000 and make it look right for every, single class so that in templates, you can just 00:39:19.000 --> 00:39:23.000 call the function, and you're guaranteed it will work. 00:39:23.000 --> 00:39:26.000 That's a quick tour of some of the language features. I know this 00:39:26.000 --> 00:39:30.000 might seem like an awful lot. I've been going very quickly through it, 00:39:30.000 --> 00:39:33.000 but want to conclude by saying so what? 00:39:33.000 --> 00:39:37.000 I just harangued you with a lot of language features, a lot of syntax, a lot of 00:39:37.000 --> 00:39:37.000 libraries. 00:39:37.000 --> 00:39:39.000 What's the point? 00:39:39.000 --> 00:39:41.000 The point to take out of this is that 00:39:41.000 --> 00:39:43.000 C++ is big, 00:39:43.000 --> 00:39:46.000 but it's also a very powerful language, and it's a very expressive language. I 00:39:46.000 --> 00:39:48.000 think it's a very beautiful language. 00:39:48.000 --> 00:39:51.000 The features that you've learned in this class will go anywhere you want them to. 00:39:51.000 --> 00:39:54.000 If you want to take your coding skills 00:39:54.000 --> 00:39:55.000 and apply 00:39:55.000 --> 00:39:57.000 them to C++, you can, 00:39:57.000 --> 00:39:58.000 and you have this flexibility. 00:39:58.000 --> 00:40:00.000 You really have this gift. 00:40:00.000 --> 00:40:03.000 What you've learned in here is something most people never learn. It's how to make 00:40:03.000 --> 00:40:05.000 a computer solve a problem for you. 00:40:05.000 --> 00:40:07.000 That's a skill that's going to follow you for the rest of your life, no matter where 00:40:07.000 --> 00:40:09.000 you take it. 00:40:09.000 --> 00:40:12.000 If you're interested in C++, I have a huge number of references here, if you 00:40:12.000 --> 00:40:13.000 want to go see them. 00:40:13.000 --> 00:40:16.000 The point is that if you want to solve a problem with a computer, you need three things. 00:40:16.000 --> 00:40:19.000 First, 00:40:19.000 --> 00:40:20.000 programming skills. 00:40:20.000 --> 00:40:21.000 You all have that. 00:40:21.000 --> 00:40:23.000 You need a good idea. 00:40:23.000 --> 00:40:26.000 I don't think I have any good ideas for programming. If I did, I'd probably do them myself, 00:40:26.000 --> 00:40:29.000 but if you have a good idea, and you want to make $1 billion with it, the 00:40:29.000 --> 00:40:32.000 last thing you need is a programming language. 00:40:32.000 --> 00:40:35.000 Hopefully this quick tour of C++ has showed you. This 00:40:35.000 --> 00:40:38.000 is what this language is. It's a tool for solving real problems 00:40:38.000 --> 00:40:40.000 that trusts you 00:40:40.000 --> 00:40:41.000 and that means that overall, you'll 00:40:41.000 --> 00:40:43.000 have fun doing it. 00:40:43.000 --> 00:40:45.000 So if you want to go and run with this, if you want to say, I'm a good programmer. 00:40:45.000 --> 00:40:46.000 I can do this and 00:40:46.000 --> 00:40:49.000 learn C++. I think you will love it. I think you will enjoy it. I think it will 00:40:49.000 --> 00:40:53.000 be some of the most fun you will have sitting in front of a computer. 00:40:53.000 --> 00:40:56.000 So have fun with this stuff. That's the whole point. If you're in this class, I hope 00:40:56.000 --> 00:41:00.000 you enjoy it. I hope you said, yeah, I can make a computer solve something. I can do graph 00:41:00.000 --> 00:41:01.000 algorithms. I can do graph [inaudible]. 00:41:01.000 --> 00:41:04.000 I can make data structures. I can make a computer program that plays Boggle 00:41:04.000 --> 00:41:08.000 better than I ever could or anyone I know ever can. 00:41:08.000 --> 00:41:10.000 Have fun. That's the whole point of this. 00:41:10.000 --> 00:41:14.000 If you want to do it in C++, come talk to me. I will give you some references. 00:41:14.000 --> 00:41:17.000 Enjoy. Good luck on the final, and I will probably see you around on Friday for the final. 00:41:17.000 --> 00:41:18.000 Enjoy.