All language subtitles for C-Tutorial-for-Beginners-Full-Course_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,370 --> 00:00:03,580 Hey, welcome to draft Academy. My name is\n 2 00:00:03,580 --> 00:00:09,730 you guys everything you need to know to get\n 3 00:00:09,730 --> 00:00:14,150 popular programming languages around. And\n 4 00:00:14,150 --> 00:00:18,710 language, it's actually a language that is\n 5 00:00:18,710 --> 00:00:23,760 In fact, c++ is essentially just like the\n 6 00:00:23,760 --> 00:00:27,580 So if you're already familiar with the C programming\n 7 00:00:27,579 --> 00:00:34,509 picking up c++. But even if you're not c++\n 8 00:00:34,509 --> 00:00:39,428 And in this course, I'm going to teach you\n 9 00:00:39,429 --> 00:00:42,780 gonna start off just with the basics, we're\n 10 00:00:42,780 --> 00:00:46,570 we'll install c++, we'll get you guys set\n 11 00:00:46,570 --> 00:00:50,500 how to write your first program, then we're\n 12 00:00:50,500 --> 00:00:54,609 we'll start looking at things like variables.\n 13 00:00:54,609 --> 00:00:58,179 a couple of different programs and some little\n 14 00:00:58,179 --> 00:01:01,809 into the thick of it, we're going to learn\n 15 00:01:01,808 --> 00:01:05,799 things like loops, and if statements and classes\n 16 00:01:05,799 --> 00:01:11,719 going to cover all of the core concepts, not\n 17 00:01:11,719 --> 00:01:15,700 programming in general. So the knowledge you\n 18 00:01:15,700 --> 00:01:20,750 to carry over to potentially other programming\n 19 00:01:20,750 --> 00:01:25,611 able to bring you guys tutorials on c++, it's\n 20 00:01:25,611 --> 00:01:29,520 in. And it's a good first language to learn\n 21 00:01:29,519 --> 00:01:33,709 stick around for this course, you can kind\n 22 00:01:33,709 --> 00:01:42,239 And hopefully you guys can learn something\n 23 00:01:42,239 --> 00:01:47,810 I'm going to show you guys how to get everything\n 24 00:01:47,810 --> 00:01:51,820 to start working with c++, and started writing\n 25 00:01:51,819 --> 00:01:56,250 actually have to do a little bit of setup,\n 26 00:01:56,250 --> 00:01:59,650 our computer. The first thing we're going\n 27 00:01:59,650 --> 00:02:04,620 just going to use this text editor in order\n 28 00:02:04,620 --> 00:02:08,489 is going to work. Generally you don't want\n 29 00:02:08,489 --> 00:02:11,890 Google Docs, you're gonna want to use just\n 30 00:02:11,889 --> 00:02:17,379 like Notepad, I'm going to show you guys a\n 31 00:02:17,379 --> 00:02:22,049 for integrated development environment. And\n 32 00:02:22,049 --> 00:02:27,579 just a an environment that's really awesome\n 33 00:02:27,579 --> 00:02:32,939 going to need in addition to a text editor,\n 34 00:02:32,939 --> 00:02:38,650 specifically a c++ compiler. And this is a\n 35 00:02:38,650 --> 00:02:44,030 that we write, and it will translate it or\n 36 00:02:44,030 --> 00:02:47,620 is going to be able to understand. So as long\n 37 00:02:47,620 --> 00:02:52,550 c++ compiler, then we're ready to start programming\n 38 00:02:52,550 --> 00:02:56,620 to get all that set up. First thing we're\n 39 00:02:56,620 --> 00:03:03,310 I'm over here on this website called codeblocks.\n 40 00:03:03,310 --> 00:03:07,400 is what's called an ID. So it's an integrated\n 41 00:03:07,400 --> 00:03:14,039 just a special environment, special text editor\n 42 00:03:14,039 --> 00:03:17,929 is going to be exactly what we need. I'm just\n 43 00:03:17,930 --> 00:03:22,569 see there's a few options one says download\n 44 00:03:22,568 --> 00:03:27,748 we're going to click download the binary release.\n 45 00:03:27,748 --> 00:03:32,668 you can see there's a link over here for Windows\n 46 00:03:32,669 --> 00:03:36,860 links for Linux and Mac, let's click on this\n 47 00:03:36,860 --> 00:03:40,780 there's a bunch of these different options.\n 48 00:03:40,780 --> 00:03:48,028 this one over here that says codeblocks 1601\n 49 00:03:48,028 --> 00:03:53,620 this is it's going to include not only the\n 50 00:03:53,620 --> 00:03:59,879 to include that c++ compiler that I was talking\n 51 00:03:59,878 --> 00:04:04,979 in this one download for code blocks. So this\n 52 00:04:04,979 --> 00:04:07,718 So let's go ahead and download this, I'm just\n 53 00:04:07,718 --> 00:04:12,269 link for SourceForge. And this should start\n 54 00:04:12,270 --> 00:04:15,430 codeblocks has finished downloading, let's\n 55 00:04:15,430 --> 00:04:20,918 to head over to my downloads folder. And we\n 56 00:04:20,918 --> 00:04:27,628 it says codeblocks 1601 m i n GW setup. Let's\n 57 00:04:27,629 --> 00:04:32,729 installer window. So let's click through this\n 58 00:04:32,728 --> 00:04:38,128 the default options. And they should start\n 59 00:04:38,129 --> 00:04:42,220 once code blocks has finished downloading,\n 60 00:04:42,220 --> 00:04:47,250 to start writing in c++. And you can see over\n 61 00:04:47,250 --> 00:04:51,029 next tutorial we're going to talk about how\n 62 00:04:51,029 --> 00:04:59,119 get started writing c++. In this tutorial,\n 63 00:04:59,120 --> 00:05:05,370 set up. To start working with and start writing\n 64 00:05:05,370 --> 00:05:09,000 we're actually going to need two different\n 65 00:05:09,000 --> 00:05:15,000 is a text editor where we can write our c++\n 66 00:05:15,000 --> 00:05:19,810 any text editor that you want. So a lot of\n 67 00:05:19,810 --> 00:05:23,949 or maybe a different text editor. In our case,\n 68 00:05:23,949 --> 00:05:29,710 ID, which stands for integrated development\n 69 00:05:29,709 --> 00:05:34,519 codeblocks. That is specially designed for\n 70 00:05:34,519 --> 00:05:38,240 guys how to download that, we're also going\n 71 00:05:38,240 --> 00:05:44,699 be a c++ compiler. And basically, this is\n 72 00:05:44,699 --> 00:05:49,520 we write, and it translates it into a language\n 73 00:05:49,519 --> 00:05:54,000 we want to run our programs, we want to, you\n 74 00:05:54,000 --> 00:06:00,199 we can use this compiler to translate the\n 75 00:06:00,199 --> 00:06:03,970 first thing I want to do is show you guys\n 76 00:06:03,970 --> 00:06:08,530 that if you're on Mac, you might already have\n 77 00:06:08,529 --> 00:06:13,008 search bar. And we're just going to type in\n 78 00:06:13,009 --> 00:06:18,020 And this should open up the terminal. This\n 79 00:06:18,019 --> 00:06:23,839 we can use to interact with the computer using\n 80 00:06:23,839 --> 00:06:28,750 to see if we already have the c++ compiler\n 81 00:06:28,750 --> 00:06:36,709 hyphen, V. And just click enter. If you have\n 82 00:06:36,709 --> 00:06:41,149 be using installed and all this stuff should\n 83 00:06:41,149 --> 00:06:44,889 everything. If this doesn't come up. In other\n 84 00:06:44,889 --> 00:06:53,568 have it, all you need to do to get this is\n 85 00:06:53,569 --> 00:06:58,900 and this is going to go off and install everything\n 86 00:06:58,899 --> 00:07:03,568 Enter. And I already have these installed.\n 87 00:07:03,569 --> 00:07:07,718 can see I already have them installed. But\n 88 00:07:07,718 --> 00:07:11,908 then this will basically just prompt you to\n 89 00:07:11,908 --> 00:07:17,329 running, then you can just check to make sure\n 90 00:07:17,329 --> 00:07:23,219 hyphen, V. And make sure that you have it.\n 91 00:07:23,220 --> 00:07:29,210 and we've run this Xcode, select Install command.\n 92 00:07:29,209 --> 00:07:33,318 So like I said, we're going to be using a\n 93 00:07:33,319 --> 00:07:37,910 really, you can use any text editor that you\n 94 00:07:37,910 --> 00:07:43,010 browser, and I'm over here on this website\n 95 00:07:43,009 --> 00:07:47,560 we can download this program code blocks,\n 96 00:07:47,560 --> 00:07:51,019 there's a couple options, you want to click\n 97 00:07:51,019 --> 00:07:56,109 release. So I'm going to click this. And you'll\n 98 00:07:56,110 --> 00:08:01,158 click on Mac OSX. And this will bring us down\n 99 00:08:01,158 --> 00:08:06,089 contains the codeblocks application. Over\n 100 00:08:06,089 --> 00:08:09,968 I'm just gonna click this. And this should\n 101 00:08:09,968 --> 00:08:14,829 file for us. When codeblocks is done downloading,\n 102 00:08:14,829 --> 00:08:20,718 folder, and we'll see what we got. So we just\n 103 00:08:20,718 --> 00:08:24,411 click it. And you'll see over here we get\n 104 00:08:24,411 --> 00:08:29,529 do is take this and drag it over to your Applications\n 105 00:08:29,529 --> 00:08:33,949 application we want to use, then you have\n 106 00:08:33,950 --> 00:08:38,278 c++. So in the next tutorial, we're going\n 107 00:08:38,278 --> 00:08:42,659 going to set up our first c++ file, and then\n 108 00:08:42,659 --> 00:08:50,360 set up and ready to go. In this tutorial,\n 109 00:08:50,360 --> 00:08:56,370 c++ project up and running in code blocks.\n 110 00:08:56,370 --> 00:09:00,070 And this is sort of like the welcome screen\n 111 00:09:00,070 --> 00:09:05,600 over here, there's a couple options. One says\n 112 00:09:05,600 --> 00:09:09,470 we're going to do. So before we're gonna start\n 113 00:09:09,470 --> 00:09:16,000 how to get a c++ project up and running and\n 114 00:09:16,000 --> 00:09:21,539 Create new project. And this should open up\n 115 00:09:21,539 --> 00:09:25,899 there's all these different options. And these\n 116 00:09:25,899 --> 00:09:30,360 applications that we can create. We're going\n 117 00:09:30,360 --> 00:09:36,000 come over here and click console application.\n 118 00:09:36,000 --> 00:09:40,309 to click Next. And over here, you'll see we\n 119 00:09:40,309 --> 00:09:44,319 we want to click c plus plus. So I'm going\n 120 00:09:44,320 --> 00:09:49,120 this project a title. So I'm just going to\n 121 00:09:49,120 --> 00:09:53,549 storing it inside of my desktop if you want\n 122 00:09:53,549 --> 00:09:58,349 can put it wherever you want. Let's click\n 123 00:09:58,350 --> 00:10:01,490 a bunch of options. You can just leave these\n 124 00:10:01,490 --> 00:10:07,730 Once we click finish, then our c++ projects\n 125 00:10:07,730 --> 00:10:12,578 our little Tree Viewer, you'll see that we\n 126 00:10:12,578 --> 00:10:18,719 of the sources folder, we have this file main\n 127 00:10:18,720 --> 00:10:22,460 stands for c++. So I'm just going to right\n 128 00:10:22,460 --> 00:10:28,278 And you'll see over here we have a bunch of\n 129 00:10:28,278 --> 00:10:33,029 file. So this is essentially just like the\n 130 00:10:33,029 --> 00:10:37,569 mean, this is what we call like a Hello World\n 131 00:10:37,570 --> 00:10:43,150 printing out hello world onto the screen.\n 132 00:10:43,149 --> 00:10:47,509 this stuff up here is, really, let's just\n 133 00:10:47,509 --> 00:10:52,840 actually going to print something out for\n 134 00:10:52,840 --> 00:10:56,470 actually going to come up here in my editor,\n 135 00:10:56,470 --> 00:11:01,370 option, when I click this, a window should\n 136 00:11:01,370 --> 00:11:06,000 like, Hello World, you'll see down here, this\n 137 00:11:06,000 --> 00:11:11,899 hello world. So let's just go over some basic\n 138 00:11:11,899 --> 00:11:17,799 to run a program in c++, we're going to build\n 139 00:11:17,799 --> 00:11:22,669 program. Building the program basically means\n 140 00:11:22,669 --> 00:11:27,069 and we're converting it down into a language\n 141 00:11:27,070 --> 00:11:31,010 thing we always have to do is build the file,\n 142 00:11:31,009 --> 00:11:35,328 basically means we're telling our computer\n 143 00:11:35,328 --> 00:11:39,448 wrote in our program. And there's a bunch\n 144 00:11:39,448 --> 00:11:44,319 blocks, you can click this little cog wheel\n 145 00:11:44,320 --> 00:11:48,810 then you can click this play button over here,\n 146 00:11:48,809 --> 00:11:51,778 of times, if you just wrote some new code,\n 147 00:11:51,778 --> 00:11:55,889 click this build and run option. And for the\n 148 00:11:55,889 --> 00:11:59,759 going to be whenever I say we're running the\n 149 00:11:59,759 --> 00:12:04,539 and we'll build it and run it at the same\n 150 00:12:04,539 --> 00:12:09,659 c++ file. In next tutorial, we're going to\n 151 00:12:09,659 --> 00:12:13,939 going to look at writing some of our own instructions,\n 152 00:12:13,940 --> 00:12:18,240 kind of dive a little bit deeper into you\n 153 00:12:18,240 --> 00:12:22,959 now, we have everything set up. So we have\n 154 00:12:22,958 --> 00:12:32,799 c++ file called main dot cpp, and we're ready\n 155 00:12:32,799 --> 00:12:37,289 going to talk to you guys about the basics\n 156 00:12:37,289 --> 00:12:41,659 to talk generally about what programs are\n 157 00:12:41,659 --> 00:12:45,689 to write a little program, which is going\n 158 00:12:45,690 --> 00:12:50,920 is going to be pretty fun. Down here, I just\n 159 00:12:50,919 --> 00:12:56,958 created my c++ project, in the last tutorial,\n 160 00:12:56,958 --> 00:13:01,919 was kind of given to us. And this is, you\n 161 00:13:01,919 --> 00:13:05,698 So I'm going to walk you guys through essentially\n 162 00:13:05,698 --> 00:13:09,469 a couple different things, and then we'll\n 163 00:13:09,470 --> 00:13:15,410 these two lines of code. This is like hashtag\n 164 00:13:15,409 --> 00:13:22,179 named scape STD. Essentially, what this does\n 165 00:13:22,179 --> 00:13:27,229 for our c++ file. As a beginner, like, you\n 166 00:13:27,230 --> 00:13:31,500 this stuff is or what it's doing. We're going\n 167 00:13:31,500 --> 00:13:34,958 the course. But for now, just know that you\n 168 00:13:34,958 --> 00:13:39,869 our programs. Down here we have this line,\n 169 00:13:39,870 --> 00:13:45,980 close parentheses. This is actually what's\n 170 00:13:45,980 --> 00:13:50,079 too much about what a function is, I'm just\n 171 00:13:50,078 --> 00:13:55,179 of familiar with hearing them. But essentially,\n 172 00:13:55,179 --> 00:14:01,909 to put the code inside of our c++ programs.\n 173 00:14:01,909 --> 00:14:07,659 function because any lines of code that we\n 174 00:14:07,659 --> 00:14:12,120 of code that we put in between these open\n 175 00:14:12,120 --> 00:14:17,659 to get executed when we run our program. So\n 176 00:14:17,659 --> 00:14:21,818 return zero. And again, don't worry too much\n 177 00:14:21,818 --> 00:14:27,620 to have this in this main function. Over here,\n 178 00:14:27,620 --> 00:14:36,120 this says c out. And then it says hello world,\n 179 00:14:36,120 --> 00:14:41,659 of code in our program. So again, any lines\n 180 00:14:41,659 --> 00:14:46,659 brackets for this main function is going to\n 181 00:14:46,659 --> 00:14:50,379 I was to come up here and run my program,\n 182 00:14:50,379 --> 00:14:56,828 run option right here, you'll see when the\n 183 00:14:56,828 --> 00:15:00,939 you'll see this little window that opened\n 184 00:15:00,940 --> 00:15:06,360 And the console is basically just a little\n 185 00:15:06,360 --> 00:15:12,310 we run our c++ code, this console window is\n 186 00:15:12,309 --> 00:15:17,049 c++ that we want to print things out onto\n 187 00:15:17,049 --> 00:15:21,609 referring to the console, I'm just referring\n 188 00:15:21,610 --> 00:15:26,539 and start talking about programming. So again,\n 189 00:15:26,539 --> 00:15:30,208 is going to get executed. And here, we just\n 190 00:15:30,208 --> 00:15:35,119 do is I can copy this and down below here,\n 191 00:15:35,120 --> 00:15:39,778 like my name, Mike. And now when I run this\n 192 00:15:39,778 --> 00:15:44,620 both of these things. So here on the first\n 193 00:15:44,620 --> 00:15:49,629 over here on the second line, it prints out\n 194 00:15:49,629 --> 00:15:54,049 how we could print something out to the console.\n 195 00:15:54,049 --> 00:15:59,299 stands for console out. And then over here,\n 196 00:15:59,299 --> 00:16:05,958 end L and this stands for end line. And basically,\n 197 00:16:05,958 --> 00:16:09,849 we're going to print out text. So you'll notice\n 198 00:16:09,850 --> 00:16:14,720 on the next line, we printed out Mike. So\n 199 00:16:14,720 --> 00:16:18,920 going to show you guys how we can write a\n 200 00:16:18,919 --> 00:16:22,519 out onto the screen. So I'm actually going\n 201 00:16:22,519 --> 00:16:27,689 I'm just going to copy this guy here a couple\n 202 00:16:27,690 --> 00:16:31,160 I'm going to print out a triangle onto the\n 203 00:16:31,159 --> 00:16:35,469 slash, and then we'll do a space and a forward\n 204 00:16:35,470 --> 00:16:39,899 And you'll see we're kind of drawing this\n 205 00:16:39,899 --> 00:16:43,399 to use vertical bars, and we're going to go\n 206 00:16:43,399 --> 00:16:48,278 going like this. And down here, why don't\n 207 00:16:48,278 --> 00:16:55,100 the last vertical bar, you'll see over here,\n 208 00:16:55,100 --> 00:16:59,800 And each of these instructions is telling\n 209 00:16:59,799 --> 00:17:06,139 line onto the console. So now when I run my\n 210 00:17:06,140 --> 00:17:11,490 out this little triangle. This is a very basic\n 211 00:17:11,490 --> 00:17:16,160 four simple instructions, we were able to\n 212 00:17:16,160 --> 00:17:21,320 So let's talk about this. Essentially, what's\n 213 00:17:21,319 --> 00:17:25,649 c++ is going and it's looking inside of our\n 214 00:17:25,650 --> 00:17:29,900 do is it's going to look for this main function\n 215 00:17:29,900 --> 00:17:34,110 block of code. And that's basically just what\n 216 00:17:34,109 --> 00:17:38,279 block of code called main and inside of these\n 217 00:17:38,279 --> 00:17:43,289 to execute all of the instructions inside\n 218 00:17:43,289 --> 00:17:48,480 a program, all we're doing is we're just telling\n 219 00:17:48,480 --> 00:17:54,200 giving the computer a bunch of instructions\n 220 00:17:54,200 --> 00:17:58,558 for example, in real life, like you were using\n 221 00:17:58,558 --> 00:18:03,990 a program, a recipe has a list of instructions.\n 222 00:18:03,990 --> 00:18:08,720 then you end up with like something delicious.\n 223 00:18:08,720 --> 00:18:13,900 is just a collection of instructions that\n 224 00:18:13,900 --> 00:18:17,450 the computer simple instructions like this.\n 225 00:18:17,450 --> 00:18:23,610 out a shape. But as we go through this course,\n 226 00:18:23,609 --> 00:18:27,329 and we learn how to use them together in unison\n 227 00:18:27,329 --> 00:18:33,149 tell the computer to do a bunch of complex\n 228 00:18:33,150 --> 00:18:38,060 you guys about is the order that these instructions\n 229 00:18:38,059 --> 00:18:41,849 the recipe, and you would start with the first\n 230 00:18:41,849 --> 00:18:46,288 instruction, the computer is going to execute\n 231 00:18:46,288 --> 00:18:51,140 to start with this instruction. And basically\n 232 00:18:51,140 --> 00:18:57,310 telling c++ that we want to print this line\n 233 00:18:57,309 --> 00:19:01,089 to do this. And then once it's done with that,\n 234 00:19:01,089 --> 00:19:05,269 it's going to print this out to the screen\n 235 00:19:05,269 --> 00:19:09,308 that. So actually, let me show you guys if\n 236 00:19:09,308 --> 00:19:14,220 put it up here. Now you'll see when we run\n 237 00:19:14,220 --> 00:19:18,839 a funky looking shape. So instead of this\n 238 00:19:18,839 --> 00:19:24,970 going to print it out on the top. And that's\n 239 00:19:24,970 --> 00:19:30,700 So again, all a program is it's just a set\n 240 00:19:30,700 --> 00:19:35,788 That's it, it's very simple, the more complex\n 241 00:19:35,788 --> 00:19:40,000 and the more ways that we're able to combine\n 242 00:19:40,000 --> 00:19:43,798 more complex Our programs are going to be.\n 243 00:19:43,798 --> 00:19:47,980 to be teaching you guys all sorts of more\n 244 00:19:47,980 --> 00:19:51,150 different ways to do different things and\n 245 00:19:51,150 --> 00:19:58,930 applications. And you'll end up learning a\n 246 00:19:58,930 --> 00:20:04,240 going to talk to you guys about using variables\n 247 00:20:04,240 --> 00:20:10,549 programs in c++, we're going to be dealing\n 248 00:20:10,549 --> 00:20:13,960 And a lot of times when we're dealing with\n 249 00:20:13,960 --> 00:20:19,990 of hard to keep track of. and a variable is\n 250 00:20:19,990 --> 00:20:24,440 different pieces of information or different\n 251 00:20:24,440 --> 00:20:30,730 it a lot easier for us to manage and maintain\n 252 00:20:30,730 --> 00:20:35,390 guys an example. And we'll show you guys basically\n 253 00:20:35,390 --> 00:20:41,030 them in c++. So down here, I have a very basic\n 254 00:20:41,029 --> 00:20:45,589 down here, I'm basically just printing out\n 255 00:20:45,589 --> 00:20:50,949 was a man named George, he was 70 years old,\n 256 00:20:50,950 --> 00:20:56,569 being 70. So this is basically like my little\n 257 00:20:56,569 --> 00:21:01,928 And this is a valid program in c++, it basically\n 258 00:21:01,929 --> 00:21:08,370 of our information. So you know, this is a\n 259 00:21:08,369 --> 00:21:13,379 But let's say that I'm looking at my story.\n 260 00:21:13,380 --> 00:21:17,360 the character's name, right. So maybe I don't\n 261 00:21:17,359 --> 00:21:21,689 it to a different name. So what I could do\n 262 00:21:21,690 --> 00:21:26,380 it in each line of code. So I could come here\n 263 00:21:26,380 --> 00:21:29,240 Let's say we want to change the character's\n 264 00:21:29,240 --> 00:21:33,589 john. I'll keep looking through the story\n 265 00:21:33,589 --> 00:21:38,199 it to john. And there we go. We've changed\n 266 00:21:38,200 --> 00:21:42,340 it. Let's say maybe now I'm thinking to myself,\n 267 00:21:42,339 --> 00:21:47,359 bit younger, instead of 70. Why don't we make\n 268 00:21:47,359 --> 00:21:52,240 go in and manually change the value of 70\n 269 00:21:52,240 --> 00:21:59,079 say he was 70, which changes to 35. And we'll\n 270 00:21:59,079 --> 00:22:04,211 change that to 35 as well. So now we've officially\n 271 00:22:04,211 --> 00:22:09,220 name, and we've changed the character's age.\n 272 00:22:09,220 --> 00:22:15,829 those changes, I had to manually go through\n 273 00:22:15,829 --> 00:22:20,319 where the characters name showed up or the\n 274 00:22:20,319 --> 00:22:25,500 instead of having a story that was only four\n 275 00:22:25,500 --> 00:22:30,159 of lines. And we mentioned the character's\n 276 00:22:30,159 --> 00:22:36,390 age hundreds of times, well, all of a sudden,\n 277 00:22:36,390 --> 00:22:40,390 manage those pieces of information. So it's\n 278 00:22:40,390 --> 00:22:45,110 name and the character's age. Right, if I\n 279 00:22:45,109 --> 00:22:49,859 and we mentioned the character's name 100\n 280 00:22:49,859 --> 00:22:53,168 update that name would be a very tedious task,\n 281 00:22:53,169 --> 00:22:58,009 just do it manually. This is where something\n 282 00:22:58,009 --> 00:23:02,379 our programs, we're going to have different\n 283 00:23:02,380 --> 00:23:06,659 that we want to keep track of, and we want\n 284 00:23:06,659 --> 00:23:11,570 we can take those pieces of information, and\n 285 00:23:11,569 --> 00:23:16,019 variables. And variable. Like I said, it's\n 286 00:23:16,019 --> 00:23:21,039 of data. And we'll make it a lot easier for\n 287 00:23:21,039 --> 00:23:25,670 our programs. So I'm gonna show you guys how\n 288 00:23:25,670 --> 00:23:30,778 the characters name and the character's age.\n 289 00:23:30,778 --> 00:23:37,160 like this. So over here, I'm going to create\n 290 00:23:37,160 --> 00:23:42,930 in c++, we actually have to tell c++ a couple\n 291 00:23:42,930 --> 00:23:49,120 is what type of information we want to store\n 292 00:23:49,119 --> 00:23:53,178 I'm going to talk to you guys all about the\n 293 00:23:53,179 --> 00:23:57,960 c++. But for now, I'm just gonna show you\n 294 00:23:57,960 --> 00:24:03,789 data that we can store inside of a variable\n 295 00:24:03,789 --> 00:24:08,369 it's a string of characters. So it's like\n 296 00:24:08,369 --> 00:24:12,788 saying There once was a man named john, this\n 297 00:24:12,788 --> 00:24:15,730 program, a lot of times we're going to be\n 298 00:24:15,730 --> 00:24:21,899 a string variable. In other words, I'm going\n 299 00:24:21,898 --> 00:24:25,959 value. So I'm just going to say string. And\n 300 00:24:25,960 --> 00:24:31,850 c++. The next thing we have to do is give\n 301 00:24:31,849 --> 00:24:37,250 So what we want to do is give this a descriptive\n 302 00:24:37,250 --> 00:24:43,450 inside of the variable. So I'm just going\n 303 00:24:43,450 --> 00:24:48,370 And what I can do now is I can give this a\n 304 00:24:48,369 --> 00:24:53,449 to and now we can type in the character's\n 305 00:24:53,450 --> 00:24:59,298 Alright, so once we've created this character\n 306 00:24:59,298 --> 00:25:04,420 this string value is now stored inside of\n 307 00:25:04,420 --> 00:25:09,399 we're going to do is create another variable\n 308 00:25:09,398 --> 00:25:16,009 to storing data in the form of a string, we\n 309 00:25:16,009 --> 00:25:20,420 number. So what I can do is I can store it\n 310 00:25:20,420 --> 00:25:25,929 an integer is basically just a whole number.\n 311 00:25:25,929 --> 00:25:31,860 this character age. Now I want to show you\n 312 00:25:31,859 --> 00:25:37,558 what we did is we said string character name,\n 313 00:25:37,558 --> 00:25:43,168 But what I could also do is put a semicolon\n 314 00:25:43,169 --> 00:25:48,210 we're writing lines of code in c++, every\n 315 00:25:48,210 --> 00:25:52,798 want to put in this semi colon. I'm not sure\n 316 00:25:52,798 --> 00:25:57,658 the semicolon basically tells c that we're\n 317 00:25:57,659 --> 00:26:02,039 one line of code from another. So you need\n 318 00:26:02,038 --> 00:26:05,829 But with a variable, what I could do is I\n 319 00:26:05,829 --> 00:26:10,059 same thing for string. And then I could go\n 320 00:26:10,059 --> 00:26:15,539 value. So I could say like, character age\n 321 00:26:15,539 --> 00:26:19,970 in a number. So we said that john was going\n 322 00:26:19,970 --> 00:26:24,610 we use numbers, we don't have to surround\n 323 00:26:24,609 --> 00:26:28,479 out the number. So now we have two variables,\n 324 00:26:28,480 --> 00:26:34,019 can create them. And what we can do is we\n 325 00:26:34,019 --> 00:26:39,990 And you'll see how this makes it a lot easier\n 326 00:26:39,990 --> 00:26:44,730 want to do is we want to replace every instance\n 327 00:26:44,730 --> 00:26:50,169 age with the variable. So instead of just\n 328 00:26:50,169 --> 00:26:55,620 this variable. And the way that we need to\n 329 00:26:55,619 --> 00:27:01,678 variable. So over here, I'm printing out this\n 330 00:27:01,679 --> 00:27:06,500 plain text, right. But let's say instead of\n 331 00:27:06,500 --> 00:27:12,609 I want to instead print out the value that\n 332 00:27:12,609 --> 00:27:18,019 what I can do is I can just get rid of john.\n 333 00:27:18,019 --> 00:27:23,160 And what this is basically going to tell c++\n 334 00:27:23,160 --> 00:27:29,269 going to type out here, so I'm just going\n 335 00:27:29,269 --> 00:27:34,829 telling c++ that we want to take this value,\n 336 00:27:34,829 --> 00:27:41,298 of this line of text. So when I go ahead and\n 337 00:27:41,298 --> 00:27:46,950 still printing out there once was a man named\n 338 00:27:46,950 --> 00:27:53,048 john, all I did was include this variable\n 339 00:27:53,048 --> 00:27:58,769 we want to put the variable right in there.\n 340 00:27:58,769 --> 00:28:02,579 of one of these print statements. So over\n 341 00:28:02,579 --> 00:28:08,538 just going to say less than less than character\n 342 00:28:08,538 --> 00:28:13,059 character name. In other words, it's going\n 343 00:28:13,059 --> 00:28:18,079 name variable. at this position, we can do\n 344 00:28:18,079 --> 00:28:21,278 the characters age, I'm going to get rid of\n 345 00:28:21,278 --> 00:28:27,109 than, and now, character age. And so the value\n 346 00:28:27,109 --> 00:28:32,139 to get placed right in there. And we have\n 347 00:28:32,140 --> 00:28:38,030 age. So over here, I'm going to get rid of\n 348 00:28:38,029 --> 00:28:42,710 So you'll see over here, we want to insert\n 349 00:28:42,710 --> 00:28:47,240 right in between all of this text. So I want\n 350 00:28:47,240 --> 00:28:52,048 make two quotation marks. And essentially\n 351 00:28:52,048 --> 00:28:56,859 going to be its own string of text. And this\n 352 00:28:56,859 --> 00:29:03,269 I can make to less than signs, I can type\n 353 00:29:03,269 --> 00:29:07,700 going to make two more or less than signs.\n 354 00:29:07,700 --> 00:29:13,630 all of these together. So it's gonna say,\n 355 00:29:13,630 --> 00:29:19,880 inside of the character age variable, then\n 356 00:29:19,880 --> 00:29:23,789 every instance of the characters age, and\n 357 00:29:23,788 --> 00:29:29,070 those variables. Let's run our program and\n 358 00:29:29,070 --> 00:29:34,379 have the same exact story as we did before,\n 359 00:29:34,380 --> 00:29:40,720 old john 35. So without having to manually\n 360 00:29:40,720 --> 00:29:46,558 values. And now what's cool about variables\n 361 00:29:46,558 --> 00:29:51,389 or update the character's age, all I have\n 362 00:29:51,390 --> 00:29:55,710 if I wanted to change the character's name\n 363 00:29:55,710 --> 00:30:02,740 50 years old, I only have to modify the values\n 364 00:30:02,740 --> 00:30:07,649 automatically update down in our story. So\n 365 00:30:07,648 --> 00:30:13,109 using the name Tom. And it's saying that he's\n 366 00:30:13,109 --> 00:30:18,389 way that we can use these variables. Another\n 367 00:30:18,390 --> 00:30:23,710 do is modify the value. So let's say that\n 368 00:30:23,710 --> 00:30:29,528 the character's name. So halfway through,\n 369 00:30:29,528 --> 00:30:34,569 all I have to do is say, character name. And\n 370 00:30:34,569 --> 00:30:38,308 So I could give this the value of Mike. And\n 371 00:30:38,308 --> 00:30:43,720 at the end of this line of code. And now you'll\n 372 00:30:43,720 --> 00:30:48,630 name is going to change. So it says There\n 373 00:30:48,630 --> 00:30:54,570 using the name, Mike. So not only was I able\n 374 00:30:54,569 --> 00:31:00,970 values, but I can actually modify those variables\n 375 00:31:00,970 --> 00:31:05,798 pretty awesome. Now, this is just sort of\n 376 00:31:05,798 --> 00:31:11,470 are containers, they allow us to maintain\n 377 00:31:11,470 --> 00:31:16,409 in our programs a lot better. And they also\n 378 00:31:16,409 --> 00:31:21,289 a value once so I can assign a value once\n 379 00:31:21,288 --> 00:31:26,429 it in different places down here. I can also\n 380 00:31:26,429 --> 00:31:32,690 my programs. So in this tutorial, we talked\n 381 00:31:32,690 --> 00:31:36,460 as integers, which are whole numbers. In the\n 382 00:31:36,460 --> 00:31:40,889 all of the different types of information\n 383 00:31:40,888 --> 00:31:48,949 we can create in our programs. In this tutorial,\n 384 00:31:48,950 --> 00:31:56,528 data types in c++. a data type basically just\n 385 00:31:56,528 --> 00:32:01,929 that we can use and work with inside of our\n 386 00:32:01,929 --> 00:32:06,400 of information, we can store like text, different\n 387 00:32:06,400 --> 00:32:10,380 values, all sorts of stuff. And I'm gonna\n 388 00:32:10,380 --> 00:32:14,909 those are and how we can use them. So the\n 389 00:32:14,909 --> 00:32:19,610 just going to be to create a bunch of different\n 390 00:32:19,609 --> 00:32:25,918 data that we can work with in c++, we can\n 391 00:32:25,919 --> 00:32:30,028 just going to create a couple of different\n 392 00:32:30,028 --> 00:32:34,019 how this is going to work. So the first data\n 393 00:32:34,019 --> 00:32:40,410 a character. And a character basically allows\n 394 00:32:40,410 --> 00:32:45,070 way we can create a character variable is\n 395 00:32:45,069 --> 00:32:49,888 this a name. So let's just call it like grade\n 396 00:32:49,888 --> 00:32:55,029 we're going to use these single quotation\n 397 00:32:55,029 --> 00:32:59,250 that I would want inside of here. So you know,\n 398 00:32:59,250 --> 00:33:03,640 of, you could store in here, and then we're\n 399 00:33:03,640 --> 00:33:09,480 basically like the character data type. And\n 400 00:33:09,480 --> 00:33:12,630 there's going to be a lot of situations where\n 401 00:33:12,630 --> 00:33:18,970 one. And what we can actually do is use something\n 402 00:33:18,970 --> 00:33:23,069 just a string of characters. So it's, instead\n 403 00:33:23,069 --> 00:33:26,710 a bunch of different characters. So this would\n 404 00:33:26,710 --> 00:33:31,399 we would see in a program. So I could just\n 405 00:33:31,398 --> 00:33:37,509 phrase. And when I create a string, I can\n 406 00:33:37,509 --> 00:33:43,000 say, like, draft Academy or something. And\n 407 00:33:43,000 --> 00:33:47,569 of just one character, a bunch of different\n 408 00:33:47,569 --> 00:33:52,240 where you might want to use either like a\n 409 00:33:52,240 --> 00:33:57,440 think strings are probably a little bit more\n 410 00:33:57,440 --> 00:34:04,080 plain text, we can also store and work with\n 411 00:34:04,079 --> 00:34:08,989 types of numbers are two basic types of numbers.\n 412 00:34:08,989 --> 00:34:13,059 numbers. Some people will also call those\n 413 00:34:13,059 --> 00:34:17,960 like a counting number. So think like 12345,\n 414 00:34:17,960 --> 00:34:21,490 numbers, there's no decimal points, right?\n 415 00:34:21,490 --> 00:34:29,230 0.5, or 1.267, or 10. Point 11. You know,\n 416 00:34:29,230 --> 00:34:34,420 after it. When we work with these different\n 417 00:34:34,420 --> 00:34:38,740 between them. So the first type a number we\n 418 00:34:38,740 --> 00:34:43,940 say int, and this could be like an age or\n 419 00:34:43,940 --> 00:34:47,869 we can just type out the number so I could\n 420 00:34:47,869 --> 00:34:51,679 any quotation marks. I don't need anything\n 421 00:34:51,679 --> 00:34:57,329 out the number. In addition to positive numbers.\n 422 00:34:57,329 --> 00:35:02,960 we're using an integer, you can't have a decimal\n 423 00:35:02,960 --> 00:35:08,720 these are just going to be solid whole numbers.\n 424 00:35:08,719 --> 00:35:14,710 two basic options. So there's two data types\n 425 00:35:14,710 --> 00:35:19,769 first is called float. And this basically\n 426 00:35:19,769 --> 00:35:25,030 The second one is called double. Now you'll\n 427 00:35:25,030 --> 00:35:30,380 data types, the main difference is just how\n 428 00:35:30,380 --> 00:35:35,789 can store more decimal points than a float.\n 429 00:35:35,789 --> 00:35:39,489 as far as like how many decimal points you\n 430 00:35:39,489 --> 00:35:44,049 use a double. And I would say for the most\n 431 00:35:44,050 --> 00:35:49,390 doubles, floats will be used more in specific\n 432 00:35:49,389 --> 00:35:53,199 learning this language, really just worry\n 433 00:35:53,199 --> 00:36:00,489 GPA. And I can set this equal to like 4.5,\n 434 00:36:00,489 --> 00:36:05,489 decimal number that I wanted. Keep in mind,\n 435 00:36:05,489 --> 00:36:11,119 have to be like a different number decimal.\n 436 00:36:11,119 --> 00:36:15,539 no problem. So ants are going to be what we're\n 437 00:36:15,539 --> 00:36:20,759 part doubles are going to be what we're going\n 438 00:36:20,760 --> 00:36:25,710 text and numbers. And just with those two\n 439 00:36:25,710 --> 00:36:30,369 and strings and an instant doubles. You can\n 440 00:36:30,369 --> 00:36:35,719 in your programs. But c++ is awesome. So they're\n 441 00:36:35,719 --> 00:36:43,099 which is called a Boolean. And a Boolean is\n 442 00:36:43,099 --> 00:36:48,460 A Boolean is actually what we would call a\n 443 00:36:48,460 --> 00:36:52,019 programs, there's actually going to be a lot\n 444 00:36:52,019 --> 00:36:58,039 to represent true or false data. And a Boolean\n 445 00:36:58,039 --> 00:37:04,610 Right. So I could say B o L stands for Boolean,\n 446 00:37:04,610 --> 00:37:09,811 right, so this variable is male is going to\n 447 00:37:09,811 --> 00:37:13,350 And this will basically tell us whether or\n 448 00:37:13,349 --> 00:37:18,110 say true, because I am a male, right. So you'll\n 449 00:37:18,110 --> 00:37:23,130 different things like, we could say something\n 450 00:37:23,130 --> 00:37:27,800 And that allows us to represent a certain\n 451 00:37:27,800 --> 00:37:31,650 over here. And that's going to be the opposite.\n 452 00:37:31,650 --> 00:37:37,710 these true false values. And we can use Boolean\n 453 00:37:37,710 --> 00:37:42,740 are the basic data types. Now there's a couple\n 454 00:37:42,739 --> 00:37:48,509 But I think 99% of the time, as a beginner,\n 455 00:37:48,510 --> 00:37:53,650 don't concern yourself with anything that\n 456 00:37:53,650 --> 00:37:58,349 are just decimal numbers, and which are whole\n 457 00:37:58,349 --> 00:38:03,219 chars, which are just single characters. That's\n 458 00:38:03,219 --> 00:38:06,549 we go forward in the course, we're going to\n 459 00:38:06,550 --> 00:38:10,870 information. Now, I want to point out one\n 460 00:38:10,869 --> 00:38:18,150 a little print statement here. And you know,\n 461 00:38:18,150 --> 00:38:23,920 to, I could print out any one of these variables,\n 462 00:38:23,920 --> 00:38:29,030 And this is going to go ahead and print that\n 463 00:38:29,030 --> 00:38:34,590 just printing out a, but we don't have to\n 464 00:38:34,590 --> 00:38:39,331 So if I wanted, I could just type in a string\n 465 00:38:39,331 --> 00:38:43,380 a variable. And this is what we would call\n 466 00:38:43,380 --> 00:38:48,519 of a variable, I could also you know, type\n 467 00:38:48,519 --> 00:38:53,949 like 4.5. Or I could type out an integer.\n 468 00:38:53,949 --> 00:38:59,329 don't have to put these things inside of variables,\n 469 00:38:59,329 --> 00:39:04,319 up like that. And this is what we would call\n 470 00:39:04,320 --> 00:39:07,750 to want to store information in variables\n 471 00:39:07,750 --> 00:39:13,021 when you do that, you have to declare the\n 472 00:39:13,021 --> 00:39:20,850 of data you want to work with. In this tutorial,\n 473 00:39:20,849 --> 00:39:26,659 and outs of working with strings in c++. And\n 474 00:39:26,659 --> 00:39:30,869 common types of data that you're going to\n 475 00:39:30,869 --> 00:39:35,589 strings are basically just plain text. So\n 476 00:39:35,590 --> 00:39:41,200 or work with in our program is going to be\n 477 00:39:41,199 --> 00:39:46,289 see I have this little program set up basically\n 478 00:39:46,289 --> 00:39:50,289 I can create a string is just by using an\n 479 00:39:50,289 --> 00:39:53,960 So I can basically type out whatever I want.\n 480 00:39:53,960 --> 00:39:59,331 You'll see now I'm printing out draft Academy\n 481 00:39:59,331 --> 00:40:05,220 see that we Drop Academy and Hello. First\n 482 00:40:05,219 --> 00:40:10,209 to do with this see our line of code over\n 483 00:40:10,210 --> 00:40:14,809 right here. And basically when we put end\n 484 00:40:14,809 --> 00:40:19,369 print a new line after we print whatever is\n 485 00:40:19,369 --> 00:40:24,809 I just said, See our draft Academy. Now, what\n 486 00:40:24,809 --> 00:40:31,420 on the same line as draft Academy, because\n 487 00:40:31,420 --> 00:40:36,280 line. If I wanted to, though, I could actually\n 488 00:40:36,280 --> 00:40:42,080 by saying a backslash n. So backslash n basically\n 489 00:40:42,079 --> 00:40:46,349 So this inside of a string represents the\n 490 00:40:46,349 --> 00:40:51,179 program, you'll see that Hello gets printed\n 491 00:40:51,179 --> 00:40:57,440 that backslash n inside of our string in order\n 492 00:40:57,440 --> 00:41:01,240 is doing. And if I wanted, I could put this\n 493 00:41:01,239 --> 00:41:06,129 put them on a new line. So in addition to\n 494 00:41:06,130 --> 00:41:11,559 here, I could also store a string inside of\n 495 00:41:11,559 --> 00:41:15,699 variable, I can just say string, we'll give\n 496 00:41:15,699 --> 00:41:20,969 and I could set it equal to whatever I want.\n 497 00:41:20,969 --> 00:41:26,709 then I can do exactly what I did down here.\n 498 00:41:26,710 --> 00:41:31,720 now it'll be printing out draft Academy onto\n 499 00:41:31,719 --> 00:41:35,579 to just printing out strings, and kind of\n 500 00:41:35,579 --> 00:41:42,130 of variables, we can also use what's called\n 501 00:41:42,130 --> 00:41:45,890 that we're going to get into more later in\n 502 00:41:45,889 --> 00:41:49,909 But for now, just know that a function is\n 503 00:41:49,909 --> 00:41:56,149 we can call, which will perform a specific\n 504 00:41:56,150 --> 00:42:01,260 of things. And there's a lot of functions\n 505 00:42:01,260 --> 00:42:05,699 called string functions. So these functions\n 506 00:42:05,699 --> 00:42:10,179 give us information about the strings. So\n 507 00:42:10,179 --> 00:42:14,009 first string function that I want to show\n 508 00:42:14,010 --> 00:42:16,940 have to do to use this is I can just come\n 509 00:42:16,940 --> 00:42:21,320 print out the result of using these functions.\n 510 00:42:21,320 --> 00:42:26,460 to say phrase dot length. And I can make an\n 511 00:42:26,460 --> 00:42:30,170 when we're calling a function and see, we're\n 512 00:42:30,170 --> 00:42:33,880 to type the name of the function. So this\n 513 00:42:33,880 --> 00:42:39,340 make an open and close parentheses like that.\n 514 00:42:39,340 --> 00:42:44,700 see we're getting 15. So this is basically\n 515 00:42:44,699 --> 00:42:49,909 of this phrase, strings, how many characters\n 516 00:42:49,909 --> 00:42:54,141 to, I could actually access individual characters\n 517 00:42:54,141 --> 00:42:59,650 to access just this G. So I wanted to print\n 518 00:42:59,650 --> 00:43:04,519 can make an open and closed square brackets\n 519 00:43:04,519 --> 00:43:09,471 put zero and zero is going to refer to this\n 520 00:43:09,471 --> 00:43:15,309 I run my program, you'll see we're just printing\n 521 00:43:15,309 --> 00:43:22,280 this R, for example, I could say two, and\n 522 00:43:22,280 --> 00:43:26,829 I run my program, we're printing out our as\n 523 00:43:26,829 --> 00:43:32,190 on yet, whenever we're indexing a string,\n 524 00:43:32,190 --> 00:43:37,079 index positions to each one of these characters\n 525 00:43:37,079 --> 00:43:43,940 position zero, I is an index position one,\n 526 00:43:43,940 --> 00:43:51,070 etc. So whenever c++ is indexing a string,\n 527 00:43:51,070 --> 00:43:57,870 start counting basically 01234. Even though\n 528 00:43:57,869 --> 00:44:03,049 it's technically at index position zero. So\n 529 00:44:03,050 --> 00:44:08,060 we're referring to like a specific character,\n 530 00:44:08,059 --> 00:44:12,170 is going to start at zero. Another thing I\n 531 00:44:12,170 --> 00:44:17,059 a specific character in a string. So I could\n 532 00:44:17,059 --> 00:44:21,590 character inside of this string. So we could\n 533 00:44:21,590 --> 00:44:26,210 a new value. So I can assign this the value\n 534 00:44:26,210 --> 00:44:32,429 these single quotes, so I could say like,\n 535 00:44:32,429 --> 00:44:37,980 FFP, it's going to say, Be IRA FFV because\n 536 00:44:37,980 --> 00:44:43,170 in this string. So now when we print this\n 537 00:44:43,170 --> 00:44:48,320 of draft Academy, so that can be kind of handy\n 538 00:44:48,320 --> 00:44:52,800 of a string. We could also find out information\n 539 00:44:52,800 --> 00:44:56,660 we can find out the length of the string But\n 540 00:44:56,659 --> 00:45:02,319 not a specific string or a specific character\n 541 00:45:02,320 --> 00:45:07,530 dot find. And I can make an open and close\n 542 00:45:07,530 --> 00:45:12,460 open and close parentheses, I'm going to give\n 543 00:45:12,460 --> 00:45:17,349 of information. So I'm going to give it some\n 544 00:45:17,349 --> 00:45:23,179 And these are called parameter. So anytime\n 545 00:45:23,179 --> 00:45:27,440 we call it passing parameters. Or you also\n 546 00:45:27,440 --> 00:45:32,090 arguments, or passing parameters, basically,\n 547 00:45:32,090 --> 00:45:35,970 function. So this fine function, I need to\n 548 00:45:35,969 --> 00:45:41,790 thing I can do is give it a string or a character\n 549 00:45:41,791 --> 00:45:48,570 it to find Academy. So basically, I want to\n 550 00:45:48,570 --> 00:45:54,280 of this phrase string up here. The next argument,\n 551 00:45:54,280 --> 00:45:59,100 to be an integer. And it's going to be the\n 552 00:45:59,099 --> 00:46:02,871 I wanted to just check to see if it was in\n 553 00:46:02,871 --> 00:46:08,001 to check to see if Academy occurred after\n 554 00:46:08,001 --> 00:46:13,730 just say zero. So now, this is actually going\n 555 00:46:13,730 --> 00:46:19,309 at what index position inside of this string\n 556 00:46:19,309 --> 00:46:24,190 program, you'll see over here, it's giving\n 557 00:46:24,190 --> 00:46:31,590 starts at index position 012345678. So Academy\n 558 00:46:31,590 --> 00:46:35,780 why it gave that back to us. So I could do\n 559 00:46:35,780 --> 00:46:40,970 or something. And now this will tell me where\n 560 00:46:40,969 --> 00:46:44,789 starts at index position four. So that can\n 561 00:46:44,789 --> 00:46:49,670 way to find the figure out of different things,\n 562 00:46:49,670 --> 00:46:53,391 you're working with. There's one more string\n 563 00:46:53,391 --> 00:46:59,280 is called substring. So it's just phrase.su.\n 564 00:46:59,280 --> 00:47:04,240 parameter. So we're going to give this two\n 565 00:47:04,239 --> 00:47:08,939 information we're going to give this is a\n 566 00:47:08,940 --> 00:47:14,369 take, you know just part of this string, so\n 567 00:47:14,369 --> 00:47:20,869 the characters after this a or I can specify\n 568 00:47:20,869 --> 00:47:25,219 zero from index position one all the way to\n 569 00:47:25,219 --> 00:47:29,489 like just a subsection of this string. So\n 570 00:47:29,489 --> 00:47:34,099 a starting index, so I could say like eight.\n 571 00:47:34,099 --> 00:47:38,989 a new string at index position eight, then\n 572 00:47:38,989 --> 00:47:44,259 going to tell substring, how many characters\n 573 00:47:44,260 --> 00:47:47,662 is basically going to start at index position\n 574 00:47:47,661 --> 00:47:53,359 a, and it's going to grab three characters.\n 575 00:47:53,360 --> 00:48:00,789 a. So now when I print this out, you'll see\n 576 00:48:00,789 --> 00:48:04,369 what we do. So this is the starting index,\n 577 00:48:04,369 --> 00:48:09,480 things we could do is we could actually take\n 578 00:48:09,480 --> 00:48:16,260 So I could say like, string, phrase sub, just\n 579 00:48:16,260 --> 00:48:22,090 and I could say phrase sub is equal to, and\n 580 00:48:22,090 --> 00:48:29,100 substring. And now if we print it out phrase\n 581 00:48:29,099 --> 00:48:36,079 storing the value of the substring in another\n 582 00:48:36,079 --> 00:48:39,279 that's really the basics of working with strings.\n 583 00:48:39,280 --> 00:48:42,920 that I left out, you know, I could spend an\n 584 00:48:42,920 --> 00:48:46,539 things we could do with strings. But I think\n 585 00:48:46,539 --> 00:48:50,590 you all the basic things that you can do,\n 586 00:48:50,590 --> 00:48:55,030 about grabbing individual characters, we talked\n 587 00:48:55,030 --> 00:49:03,940 that should be a good introduction into working\n 588 00:49:03,940 --> 00:49:08,650 to talk to you guys about working with numbers\n 589 00:49:08,650 --> 00:49:12,780 and C, one of the most common types of data\n 590 00:49:12,780 --> 00:49:17,170 to be numbers. So these can be things like\n 591 00:49:17,170 --> 00:49:21,420 I'm gonna give you guys a full overview of\n 592 00:49:21,420 --> 00:49:26,420 the basics, we'll look at how we can use different\n 593 00:49:26,420 --> 00:49:30,789 mathematical operations with our numbers.\n 594 00:49:30,789 --> 00:49:34,630 Now, down here, I'm just going to talk to\n 595 00:49:34,630 --> 00:49:40,190 two types of numbers and see that we deal\n 596 00:49:40,190 --> 00:49:45,059 whole numbers are basically referred to as\n 597 00:49:45,059 --> 00:49:50,440 to as two things either floats or doubles.\n 598 00:49:50,440 --> 00:49:56,030 know about that as a beginner is that doubles\n 599 00:49:56,030 --> 00:50:00,341 So the double you can store you know, potentially\n 600 00:50:00,340 --> 00:50:04,679 there's more differences. But if you want\n 601 00:50:04,679 --> 00:50:08,419 it up. But the basics of using numbers as\n 602 00:50:08,420 --> 00:50:12,840 for example, print out the number 14, you\n 603 00:50:12,840 --> 00:50:17,039 it in and we can print it out, we can work\n 604 00:50:17,039 --> 00:50:21,519 we could use negative numbers, if I wanted,\n 605 00:50:21,519 --> 00:50:26,239 are very simple, you just kind of type out\n 606 00:50:26,239 --> 00:50:30,809 math. So for example, I could say like five\n 607 00:50:30,809 --> 00:50:35,309 five and seven, this is actually going to\n 608 00:50:35,309 --> 00:50:40,509 print out the result of five plus seven. So\n 609 00:50:40,510 --> 00:50:45,150 use addition, we can also use subtraction,\n 610 00:50:45,150 --> 00:50:49,710 this forward slash, and we can use multiplication,\n 611 00:50:49,710 --> 00:50:55,480 was to multiply these two numbers, now you'll\n 612 00:50:55,480 --> 00:51:00,510 four basic math, you know operations. So that's\n 613 00:51:00,510 --> 00:51:04,620 thing I want to show you guys, which is called\n 614 00:51:04,619 --> 00:51:10,601 will basically give us the remainder of dividing\n 615 00:51:10,601 --> 00:51:15,420 I made this percent sign, and actually this\n 616 00:51:15,420 --> 00:51:19,789 we would read this 10 mod three, what this\n 617 00:51:19,789 --> 00:51:24,009 by three, and then it's going to give us the\n 618 00:51:24,010 --> 00:51:28,810 give us the remainder, so 10 divided by three\n 619 00:51:28,809 --> 00:51:33,710 So now we just we should just get one. And\n 620 00:51:33,710 --> 00:51:39,079 that modules operator can come in handy, you\n 621 00:51:39,079 --> 00:51:45,940 C. So C is going to adhere to like the normal\n 622 00:51:45,940 --> 00:51:51,079 Please Excuse My Dear Aunt Sally, basically\n 623 00:51:51,079 --> 00:51:59,690 to come before addition and subtraction. So\n 624 00:51:59,690 --> 00:52:06,480 times 10, this is going to do five times 10\n 625 00:52:06,480 --> 00:52:11,480 we get 54. But if I wanted to do the addition,\n 626 00:52:11,480 --> 00:52:19,030 this. So now it's going to do five plus four,\n 627 00:52:19,030 --> 00:52:22,660 you can see we do so if you need to separate\n 628 00:52:22,659 --> 00:52:27,539 just following basic math order of operations\n 629 00:52:27,539 --> 00:52:31,869 that. So in addition to doing all that stuff,\n 630 00:52:31,869 --> 00:52:36,150 numbers inside of variables. So I can make\n 631 00:52:36,150 --> 00:52:41,389 number. And we'll just make this five. I could\n 632 00:52:41,389 --> 00:52:47,089 de nom for decimal number. And this would\n 633 00:52:47,090 --> 00:52:51,300 these numbers inside of variables. If I wanted,\n 634 00:52:51,300 --> 00:52:55,100 like we did down here, I want to show you\n 635 00:52:55,099 --> 00:53:00,210 is incrementing, a number that's stored in\n 636 00:53:00,210 --> 00:53:05,289 I could say plus plus. And what this is going\n 637 00:53:05,289 --> 00:53:09,389 So now when we print out w num instead of\n 638 00:53:09,389 --> 00:53:13,969 we're adding one to it. So you can see we\n 639 00:53:13,969 --> 00:53:18,509 in handy a lot. There's a lot of situations\n 640 00:53:18,510 --> 00:53:24,100 also do like minus minus, and that will subtract\n 641 00:53:24,099 --> 00:53:27,980 equals, and we could say like 80. And so what\n 642 00:53:27,980 --> 00:53:34,231 w nom and it's going to add 80 to it. So now\n 643 00:53:34,231 --> 00:53:41,000 do plus equals multiplication equals minus\n 644 00:53:41,000 --> 00:53:45,110 and all of that will it's just basically shorthand\n 645 00:53:45,110 --> 00:53:49,510 So now that we kind of looked at all the different\n 646 00:53:49,510 --> 00:53:54,070 and integers work together. So here's a little\n 647 00:53:54,070 --> 00:54:02,760 I added 5.5 plus nine, so I'm adding a decimal\n 648 00:54:02,760 --> 00:54:07,010 right, so let's see what happens over here,\n 649 00:54:07,010 --> 00:54:12,390 number back. So anytime we're doing math between\n 650 00:54:12,389 --> 00:54:17,059 and an integer, a whole number, we're always\n 651 00:54:17,059 --> 00:54:22,161 always going to give us the decimal back.\n 652 00:54:22,161 --> 00:54:29,470 math with two integers, so for example, let\n 653 00:54:29,469 --> 00:54:34,189 by three, and these are both integers. Keep\n 654 00:54:34,190 --> 00:54:40,210 number back. So we're going to get like three\n 655 00:54:40,210 --> 00:54:44,360 But here's the thing. This isn't actually\n 656 00:54:44,360 --> 00:54:50,120 with a remainder of one. But because we did\n 657 00:54:50,119 --> 00:54:56,579 get an integer value back. If I was to make\n 658 00:54:56,579 --> 00:55:01,400 made both of them a decimal, a decimal number.\n 659 00:55:01,400 --> 00:55:06,151 full answer. So it's going to be three with\n 660 00:55:06,150 --> 00:55:11,199 see if we do math between just two integers,\n 661 00:55:11,199 --> 00:55:15,579 if that's not like fully the correct answer.\n 662 00:55:15,579 --> 00:55:18,539 to want to do that in other circumstances\n 663 00:55:18,539 --> 00:55:22,851 that's kind of how integers and decimal numbers\n 664 00:55:22,851 --> 00:55:29,250 to do is show you guys how we can use different\n 665 00:55:29,250 --> 00:55:34,420 math, there's all sorts of different, like,\n 666 00:55:34,420 --> 00:55:39,050 root, you can take a number to a power, we\n 667 00:55:39,050 --> 00:55:43,250 these things called functions, which can do\n 668 00:55:43,250 --> 00:55:48,840 just a collection of code that we can call\n 669 00:55:48,840 --> 00:55:52,430 going to talk more about functions later.\n 670 00:55:52,429 --> 00:55:56,989 math functions that we can use. In order to\n 671 00:55:56,989 --> 00:56:01,899 to do something called importing them. And\n 672 00:56:01,900 --> 00:56:08,450 basically going we're telling c++ that we\n 673 00:56:08,449 --> 00:56:12,009 So up here, you can see we're using this include\n 674 00:56:12,010 --> 00:56:16,960 iostream, I'm going to add another line here,\n 675 00:56:16,960 --> 00:56:22,369 just going to copy this guy up here. And we\n 676 00:56:22,369 --> 00:56:26,449 sign. And in here, I just want to type in\n 677 00:56:26,449 --> 00:56:31,980 to do is it's going to tell our c++ program\n 678 00:56:31,980 --> 00:56:35,409 kind of all you need to know at this point,\n 679 00:56:35,409 --> 00:56:40,869 in order to follow along with what I'm going\n 680 00:56:40,869 --> 00:56:45,639 a bunch of different math functions, essentially\n 681 00:56:45,639 --> 00:56:52,489 say like POW. And what this will do is it'll\n 682 00:56:52,489 --> 00:56:57,269 two numbers, like I could pass a two, and\n 683 00:56:57,269 --> 00:57:01,840 is it'll take two raised to the power of five,\n 684 00:57:01,840 --> 00:57:08,340 when I run my program, you'll see we're getting\n 685 00:57:08,340 --> 00:57:12,559 And you can kind of do that with any number.\n 686 00:57:12,559 --> 00:57:19,570 third power, so three cubed, and now we should\n 687 00:57:19,570 --> 00:57:25,760 can be pretty useful. There's another one\n 688 00:57:25,760 --> 00:57:30,650 So we can say like square root 36. And now\n 689 00:57:30,650 --> 00:57:35,300 36 back, which is going to be six. So that\n 690 00:57:35,300 --> 00:57:41,570 functions, we you can put a decimal numbers\n 691 00:57:41,570 --> 00:57:46,010 numbers and also decimal numbers. There's\n 692 00:57:46,010 --> 00:57:53,010 going to round a number. So if I put like\n 693 00:57:53,010 --> 00:57:57,200 number. So you see, we just get four and this\n 694 00:57:57,199 --> 00:58:03,889 change this to 4.6, now we should get five\n 695 00:58:03,889 --> 00:58:08,900 which will similarly like round decimal numbers,\n 696 00:58:08,900 --> 00:58:13,680 automatically just round the number up. So\n 697 00:58:13,679 --> 00:58:18,929 the number up to the next highest whole number.\n 698 00:58:18,929 --> 00:58:25,339 the opposite, which is floor. So if I just\n 699 00:58:25,340 --> 00:58:30,470 it's supposed to round up, but now it's going\n 700 00:58:30,469 --> 00:58:34,810 or that floor function. So those can be pretty\n 701 00:58:34,811 --> 00:58:40,570 you guys, which is called f max. And f Max\n 702 00:58:40,570 --> 00:58:45,980 in like a three and a 10. And this will tell\n 703 00:58:45,980 --> 00:58:49,490 back to us the bigger of the two numbers.\n 704 00:58:49,489 --> 00:58:55,369 it's giving us a 10 back because 10 was the\n 705 00:58:55,369 --> 00:58:59,639 in C, you're going to have two numbers, you\n 706 00:58:59,639 --> 00:59:03,940 can be really useful to tell us. And you could\n 707 00:59:03,940 --> 00:59:07,951 So this will tell us what the smallest number\n 708 00:59:07,951 --> 00:59:13,530 get three over here. So those are some basic\n 709 00:59:13,530 --> 00:59:19,350 just go online and search c++ math functions,\n 710 00:59:19,349 --> 00:59:25,019 that you can use. There's things to do like\n 711 00:59:25,019 --> 00:59:29,750 stuff you can do, you can use like exponentials\n 712 00:59:29,750 --> 00:59:34,000 useful. But that's kind of the basics of how\n 713 00:59:34,000 --> 00:59:40,159 are extremely useful. And that's kind of been\n 714 00:59:40,159 --> 00:59:46,339 you can do with them. In this tutorial, I'm\n 715 00:59:46,340 --> 00:59:51,170 a user in c++. A lot of times in our programs,\n 716 00:59:51,170 --> 00:59:55,769 types of information. But one of the most\n 717 00:59:55,769 --> 01:00:00,320 be information that the user inputs. So a\n 718 01:00:00,320 --> 01:00:04,940 allow the user to input information. And then\n 719 01:00:04,940 --> 01:00:09,539 in order to do different things. So in this\n 720 01:00:09,539 --> 01:00:14,489 of how that's done, we'll talk about how to\n 721 01:00:14,489 --> 01:00:17,979 know, you'll kind of learn everything you\n 722 01:00:17,980 --> 01:00:23,730 getting information from the user, the first\n 723 01:00:23,730 --> 01:00:27,599 somewhere. So whenever I'm asking the user\n 724 01:00:27,599 --> 01:00:31,679 give me that information, and I don't put\n 725 01:00:31,679 --> 01:00:35,320 so we usually what we want to do is create\n 726 01:00:35,320 --> 01:00:39,230 a little program that will allow the user\n 727 01:00:39,231 --> 01:00:43,920 a integer just called age. And I'm not going\n 728 01:00:43,920 --> 01:00:48,630 a semicolon there, we're essentially declaring\n 729 01:00:48,630 --> 01:00:52,640 want to use this integer, but we're not giving\n 730 01:00:52,639 --> 01:00:57,480 this variable a value. The next thing I want\n 731 01:00:57,480 --> 01:01:01,449 in something right. So if I don't give them\n 732 01:01:01,449 --> 01:01:05,449 I want, then they're not going to know what\n 733 01:01:05,449 --> 01:01:13,730 C out. And I'll just print out a little prompt,\n 734 01:01:13,730 --> 01:01:18,559 basically just prompting them to enter in\n 735 01:01:18,559 --> 01:01:22,960 the variable, and once we've prompted them\n 736 01:01:22,960 --> 01:01:27,769 do is we can actually get the information\n 737 01:01:27,769 --> 01:01:31,809 is actually the opposite of the way that we\n 738 01:01:31,809 --> 01:01:37,090 c out, I'm just gonna say C n, and I'm gonna\n 739 01:01:37,090 --> 01:01:42,480 C out, we use these lesson signs, when we\n 740 01:01:42,480 --> 01:01:47,019 that's really important. So over here, I'm\n 741 01:01:47,019 --> 01:01:51,610 that I want to store what they enter inside\n 742 01:01:51,610 --> 01:01:56,519 I want to store whatever they input into this\n 743 01:01:56,519 --> 01:02:00,750 going to enter in an integer number, and I'm\n 744 01:02:00,750 --> 01:02:06,099 of this integer that we created. Now, what\n 745 01:02:06,099 --> 01:02:13,179 So we'll print out a little message to them,\n 746 01:02:13,179 --> 01:02:22,509 say like age, or we can say like, years. Old.\n 747 01:02:22,510 --> 01:02:26,660 to enter in their name, we're taking whatever\n 748 01:02:26,659 --> 01:02:32,299 this age variable, we can do that using the\n 749 01:02:32,300 --> 01:02:36,950 out You are the age years old. So let's go\n 750 01:02:36,949 --> 01:02:41,559 we did. So I'm going to build and run. And\n 751 01:02:41,559 --> 01:02:45,929 we can just put like 30. And now when I click\n 752 01:02:45,929 --> 01:02:50,849 we entered in 30, it's going to store it inside\n 753 01:02:50,849 --> 01:02:55,900 the prompt. So when I click enter, you'll\n 754 01:02:55,900 --> 01:03:00,829 awesome. So we can do that and we can get\n 755 01:03:00,829 --> 01:03:07,079 if I made this a double, it would be the same\n 756 01:03:07,079 --> 01:03:12,469 I can enter in like 4.5. So maybe someone's\n 757 01:03:12,469 --> 01:03:16,609 entering in 4.5. So it's gonna work the same\n 758 01:03:16,610 --> 01:03:23,430 for characters. So if I made this a sharp,\n 759 01:03:23,429 --> 01:03:28,009 to get a character from them as well. So now\n 760 01:03:28,010 --> 01:03:33,970 in like a G, for example, whatever, obviously,\n 761 01:03:33,969 --> 01:03:39,169 So it's able to take in that character, and\n 762 01:03:39,170 --> 01:03:43,590 that's how we can get characters in numbers.\n 763 01:03:43,590 --> 01:03:47,320 actually going to do something different.\n 764 01:03:47,320 --> 01:03:52,630 not going to use this C in command. So I'm\n 765 01:03:52,630 --> 01:03:56,200 So instead of entering in the age, why don't\n 766 01:03:56,199 --> 01:04:01,239 here, I'm going to make a string, and I'm\n 767 01:04:01,239 --> 01:04:07,659 C and I'm going to use another command, which\n 768 01:04:07,659 --> 01:04:12,170 allow us to get an entire line of text. So\n 769 01:04:12,170 --> 01:04:16,590 one character, we're going to get like the\n 770 01:04:16,590 --> 01:04:21,530 we need to pass this a couple of different\n 771 01:04:21,530 --> 01:04:26,470 And c n is basically just that little like\n 772 01:04:26,469 --> 01:04:31,029 stuff into that command prompt, that's basically\n 773 01:04:31,030 --> 01:04:34,450 in the name of the variable where we want\n 774 01:04:34,449 --> 01:04:40,409 I'm just going to store inside of name. So\n 775 01:04:40,409 --> 01:04:47,980 So I could say hello. And it's going to be\n 776 01:04:47,980 --> 01:04:52,469 from the user. So we're basically get the\n 777 01:04:52,469 --> 01:04:58,209 here I can say like john smith, and now when\n 778 01:04:58,210 --> 01:05:02,780 So that's how we can get strings of text.\n 779 01:05:02,780 --> 01:05:06,519 to get like an integer and store it inside\n 780 01:05:06,519 --> 01:05:12,440 a char and store it inside of a char variable,\n 781 01:05:12,440 --> 01:05:17,300 get like a string of text, then I can use\n 782 01:05:17,300 --> 01:05:20,910 to be useful. So that's kind of an overview\n 783 01:05:20,909 --> 01:05:24,789 you can get as many values as you want. And\n 784 01:05:24,789 --> 01:05:28,969 this whole line, paste it a bunch of times\n 785 01:05:28,969 --> 01:05:36,209 different pieces of information and use them.\n 786 01:05:36,210 --> 01:05:41,820 how to build a basic calculator in c++. Essentially,\n 787 01:05:41,820 --> 01:05:46,470 user can enter in two numbers. And then we'll\n 788 01:05:46,469 --> 01:05:49,779 the answer. So this is going to be kind of\n 789 01:05:49,780 --> 01:05:54,870 more about getting input from users. So down\n 790 01:05:54,869 --> 01:05:59,769 we do anything is create two variables, where\n 791 01:05:59,769 --> 01:06:03,869 to add together. So I'm going to create an\n 792 01:06:03,869 --> 01:06:08,529 one. And I'm not going to give this a value\n 793 01:06:08,530 --> 01:06:13,769 give this variable a value, I'm going to create\n 794 01:06:13,769 --> 01:06:17,750 actually, let me show you guys something cool,\n 795 01:06:17,750 --> 01:06:22,130 like this. And they're the same data type,\n 796 01:06:22,130 --> 01:06:27,170 So I could say num, one, comma, num, two.\n 797 01:06:27,170 --> 01:06:31,470 useful. So for example, I could do like as\n 798 01:06:31,469 --> 01:06:36,759 going to have two numbers, though. So now\n 799 01:06:36,760 --> 01:06:40,520 the next thing we want to do is prompt the\n 800 01:06:40,519 --> 01:06:44,690 to say C out. And the first thing we'll do\n 801 01:06:44,690 --> 01:06:51,630 say enter first number. And now we want to\n 802 01:06:51,630 --> 01:06:56,740 So I'm going to say cn, and over here, I'm\n 803 01:06:56,739 --> 01:07:01,209 to store the number that they enter inside\n 804 01:07:01,210 --> 01:07:05,000 just copy this. And we're going to do the\n 805 01:07:05,000 --> 01:07:12,630 say enter second number. And now instead of\n 806 01:07:12,630 --> 01:07:17,099 this point in our program, we should have\n 807 01:07:17,099 --> 01:07:21,239 both of those numbers from the user, the last\n 808 01:07:21,239 --> 01:07:28,909 answer. So we can actually just say, C out.\n 809 01:07:28,909 --> 01:07:34,139 two together. So we should be printing out\n 810 01:07:34,139 --> 01:07:39,059 So let's go ahead and run this program. And\n 811 01:07:39,059 --> 01:07:44,599 and run. And actually Whoops, I put the wrong\n 812 01:07:44,599 --> 01:07:49,110 probably a really common mistake with C and\n 813 01:07:49,110 --> 01:07:53,970 to less than signs. So that's something that\n 814 01:07:53,969 --> 01:07:58,489 me up. So when we're using C and we're using\n 815 01:07:58,489 --> 01:08:02,690 C out we're using these two less than sign.\n 816 01:08:02,690 --> 01:08:08,149 kind of highlight a common mistake for beginners\n 817 01:08:08,150 --> 01:08:12,849 programmed in c++ a lot before. Alright, so\n 818 01:08:12,849 --> 01:08:18,939 first number, so enter in a five, enter second\n 819 01:08:18,939 --> 01:08:23,659 enter, it should add both these numbers together.\n 820 01:08:23,659 --> 01:08:28,300 cool. Another thing we could do is instead\n 821 01:08:28,300 --> 01:08:33,039 doubles. And that's as easy as just changing\n 822 01:08:33,039 --> 01:08:37,550 run the program, we can work with double.\n 823 01:08:37,550 --> 01:08:42,279 enter in like a 9.8. And now we'll be able\n 824 01:08:42,279 --> 01:08:46,639 of cool. And really, that's a basic calculator.\n 825 01:08:46,640 --> 01:08:52,029 up here, we're using C out. And with C out\n 826 01:08:52,029 --> 01:08:56,660 then we're using cn with the greater than\n 827 01:08:56,659 --> 01:09:01,568 the use the input from the user. And it's\n 828 01:09:01,569 --> 01:09:07,010 doing that twice. And because we store these\n 829 01:09:07,010 --> 01:09:12,500 to add them together and print out the answer.\n 830 01:09:12,500 --> 01:09:15,770 Actually, later in the course, I'm going to\n 831 01:09:15,770 --> 01:09:20,230 calculator that will be able to add, subtract,\n 832 01:09:20,229 --> 01:09:23,349 to decide in order to build something like\n 833 01:09:23,350 --> 01:09:30,990 stuff. So stick around, and we'll learn how\n 834 01:09:30,990 --> 01:09:36,210 In this tutorial, I'm gonna show you guys\n 835 01:09:36,210 --> 01:09:40,439 So a Mad Libs is basically a little game where\n 836 01:09:40,439 --> 01:09:45,829 be like nouns, verbs, adjectives, and then\n 837 01:09:45,829 --> 01:09:50,079 into a story. And generally since you entered\n 838 01:09:50,079 --> 01:09:54,939 funny. So let me show you guys over here in\n 839 01:09:54,939 --> 01:09:58,169 you know, essentially there's this story and\n 840 01:09:58,170 --> 01:10:02,440 words that the person entered into the story.\n 841 01:10:02,439 --> 01:10:08,659 in our c++ program. Down here, I have my little\n 842 01:10:08,659 --> 01:10:14,599 it says Roses are red, violets are blue. I\n 843 01:10:14,600 --> 01:10:19,200 a classic poem. But I think this could be\n 844 01:10:19,199 --> 01:10:24,470 So let's say instead of saying Roses are red,\n 845 01:10:24,470 --> 01:10:32,050 instead of saying violets are blue, we'll\n 846 01:10:32,050 --> 01:10:38,310 of saying, I love you, let's say I love celebrity,\n 847 01:10:38,310 --> 01:10:42,690 So basically, we're going to ask the user\n 848 01:10:42,689 --> 01:10:47,389 store them in variables, and then we can print\n 849 01:10:47,390 --> 01:10:50,751 started, this should be kind of cool. The\n 850 01:10:50,751 --> 01:10:55,329 variables for all these things. So I'm just\n 851 01:10:55,329 --> 01:11:02,979 for the color for the plural noun and for\n 852 01:11:02,979 --> 01:11:06,609 told c++ that we're going to use all these\n 853 01:11:06,609 --> 01:11:12,229 And we're actually going to let the user give\n 854 01:11:12,229 --> 01:11:15,349 The first thing we want to do when we want\n 855 01:11:15,350 --> 01:11:21,370 say C out and we're gonna print out a prompt,\n 856 01:11:21,369 --> 01:11:25,479 So we're gonna have them enter in a color,\n 857 01:11:25,479 --> 01:11:30,649 they input, so I'm just going to say, Get\n 858 01:11:30,649 --> 01:11:36,609 N. And that's basically just standing for\n 859 01:11:36,609 --> 01:11:41,469 input text into the console, so it's gonna\n 860 01:11:41,470 --> 01:11:46,050 then we're gonna store it inside of this color\n 861 01:11:46,050 --> 01:11:49,880 that they enter. And I'm actually just going\n 862 01:11:49,880 --> 01:11:57,650 for all the other values. So we're gonna say\n 863 01:11:57,649 --> 01:12:04,259 inside of the plural noun variable. And then\n 864 01:12:04,260 --> 01:12:09,940 for the celebrity. So we'll store that in\n 865 01:12:09,939 --> 01:12:14,710 declaring the very most, we're printing out\n 866 01:12:14,710 --> 01:12:20,829 from the user using this get line function.\n 867 01:12:20,829 --> 01:12:25,500 of the program. So instead of saying roses,\n 868 01:12:25,500 --> 01:12:32,560 color that they entered into the story, same\n 869 01:12:32,560 --> 01:12:39,440 to say, plural noun, and you can see how that\n 870 01:12:39,439 --> 01:12:45,229 then I love celebrity, we're going to actually\n 871 01:12:45,229 --> 01:12:50,549 so now our program should be set up, everything's\n 872 01:12:50,550 --> 01:12:55,270 variables, and we're printing them out, down\n 873 01:12:55,270 --> 01:13:00,910 and we should be able to play our madlibs\n 874 01:13:00,909 --> 01:13:07,630 Enter a plural noun, let's do microwaves.\n 875 01:13:07,630 --> 01:13:13,060 Hanks. So now when I click enter, all of the\n 876 01:13:13,060 --> 01:13:20,400 So it says roses are magenta, microwaves are\n 877 01:13:20,399 --> 01:13:24,609 worked, and we are ready to go. So that's\n 878 01:13:24,609 --> 01:13:28,639 it's it's as easy as getting different inputs\n 879 01:13:28,640 --> 01:13:33,130 the story. But this is a very simple madlibs.\n 880 01:13:33,130 --> 01:13:37,730 could ask the user for like 20 different words\n 881 01:13:37,729 --> 01:13:44,129 And it's going to work out the same way. So\n 882 01:13:44,130 --> 01:13:53,289 game. In this tutorial, I want to talk to\n 883 01:13:53,289 --> 01:13:57,380 of times when we're writing programs in c++,\n 884 01:13:57,380 --> 01:14:02,340 of data. And one way that we can keep track\n 885 01:14:02,340 --> 01:14:07,770 called a variable. But the one thing about\n 886 01:14:07,770 --> 01:14:12,681 one value inside of a variable. So if I create\n 887 01:14:12,680 --> 01:14:16,839 store one character in there. If I create\n 888 01:14:16,840 --> 01:14:21,960 integer in there. A lot of times though, in\n 889 01:14:21,960 --> 01:14:28,289 of data. And that's where arrays can come\n 890 01:14:28,289 --> 01:14:35,220 a variable. But unlike a variable arrays can\n 891 01:14:35,220 --> 01:14:40,690 hold like a list of you know, 1000s, or millions\n 892 01:14:40,689 --> 01:14:44,899 could put, you know, pieces of information\n 893 01:14:44,899 --> 01:14:50,149 inside of the same array. So I'm going to\n 894 01:14:50,149 --> 01:14:55,129 how we can work with them. You create an array,\n 895 01:14:55,130 --> 01:15:01,319 the first thing we have to do is tell c++\n 896 01:15:01,319 --> 01:15:05,609 of the array. So I'm just gonna make an array\n 897 01:15:05,609 --> 01:15:09,449 just like a variable, we're going to give\n 898 01:15:09,449 --> 01:15:14,359 right, and this would be an array of lucky\n 899 01:15:14,359 --> 01:15:19,349 from a variable. When we're creating an array,\n 900 01:15:19,350 --> 01:15:24,460 brackets after the name. So after lucky nums,\n 901 01:15:24,460 --> 01:15:29,190 bracket. And that basically tells c++, okay,\n 902 01:15:29,190 --> 01:15:34,309 to be able to store multiple pieces of information\n 903 01:15:34,310 --> 01:15:39,170 to say equals, and one, the easiest way to\n 904 01:15:39,170 --> 01:15:43,850 default information right off the bat. And\n 905 01:15:43,850 --> 01:15:48,140 and inside of here, I can just start typing\n 906 01:15:48,140 --> 01:15:53,800 So let's say I want to store like a list of\n 907 01:15:53,800 --> 01:16:02,079 right, so I'm storing all of these numbers\n 908 01:16:02,079 --> 01:16:06,269 a variable where we can only store one number,\n 909 01:16:06,270 --> 01:16:10,520 we will refer to these as elements in the\n 910 01:16:10,520 --> 01:16:15,980 the list. And then we would delineate the\n 911 01:16:15,979 --> 01:16:20,639 the second element, 815 16, excetera. So these\n 912 01:16:20,640 --> 01:16:25,539 array. Now down here, I'm going to show you\n 913 01:16:25,539 --> 01:16:31,529 So I'm just gonna say C out. And let's say\n 914 01:16:31,529 --> 01:16:35,439 elements, let's say I wanted to access like\n 915 01:16:35,439 --> 01:16:39,559 because what good is the array, if we can't\n 916 01:16:39,560 --> 01:16:45,950 I can just say, Lucky nums. And I can make\n 917 01:16:45,949 --> 01:16:51,729 of this open and close square bracket, I can\n 918 01:16:51,729 --> 01:16:57,019 that I want to access. So if I want to access\n 919 01:16:57,020 --> 01:17:02,881 to put an index in here, that's going to be\n 920 01:17:02,881 --> 01:17:07,170 see we're printing out four, we're printing\n 921 01:17:07,170 --> 01:17:12,880 wanted to get access to this 15, it's going\n 922 01:17:12,880 --> 01:17:19,210 two inside of this array. So now whenever\n 923 01:17:19,210 --> 01:17:25,029 caught on by now when we index these arrays,\n 924 01:17:25,029 --> 01:17:32,369 say that four is an index position. 08 is\n 925 01:17:32,369 --> 01:17:38,599 three excetera. So we would always say that\n 926 01:17:38,600 --> 01:17:44,800 an index position zero. And if you're familiar\n 927 01:17:44,800 --> 01:17:49,640 the same exact thing. So that's how we can\n 928 01:17:49,640 --> 01:17:56,190 we can also modify an element in the array.\n 929 01:17:56,189 --> 01:18:00,239 say I wanted to change the first element,\n 930 01:18:00,239 --> 01:18:05,800 this a different value. So I could set this\n 931 01:18:05,800 --> 01:18:11,270 I print out lucky numbers, zero, I'm actually\n 932 01:18:11,270 --> 01:18:16,900 whoops, I'm actually going to be printing\n 933 01:18:16,899 --> 01:18:22,589 one of the indexes inside of that array. Another\n 934 01:18:22,590 --> 01:18:27,690 give them a size. So normally, if I just create\n 935 01:18:27,689 --> 01:18:34,049 and an empty square brackets, the array is\n 936 01:18:34,050 --> 01:18:38,470 that I declare over here. But a lot of times\n 937 01:18:38,470 --> 01:18:43,020 not know what all the elements should be.\n 938 01:18:43,020 --> 01:18:49,150 I could say, like 20. And essentially what\n 939 01:18:49,149 --> 01:18:54,129 want to be able to store 20 elements inside\n 940 01:18:54,130 --> 01:19:02,390 don't have 20 elements, yet I only have elements\n 941 01:19:02,390 --> 01:19:06,530 add more elements into here. So I could say\n 942 01:19:06,529 --> 01:19:11,909 And I could give this a value. So I could\n 943 01:19:11,909 --> 01:19:17,539 now down here, if we printed out lucky numbers\n 944 01:19:17,539 --> 01:19:21,979 can see, another thing you can do is just\n 945 01:19:21,979 --> 01:19:29,269 can get rid of all of these. And I can just\n 946 01:19:29,270 --> 01:19:34,720 I can give all these different values. So\n 947 01:19:34,720 --> 01:19:39,840 And now I can you know essentially just assign\n 948 01:19:39,840 --> 01:19:44,789 I said, a lot of times you might not know\n 949 01:19:44,789 --> 01:19:50,519 you declare it and so you can just basically\n 950 01:19:50,520 --> 01:19:54,740 in there and then you can just you know, fill\n 951 01:19:54,739 --> 01:20:00,979 the basics of arrays and arrays are very simple.\n 952 01:20:00,979 --> 01:20:09,319 pieces of information. In this tutorial, I\n 953 01:20:09,319 --> 01:20:16,439 in c++. A function is basically just a little\n 954 01:20:16,439 --> 01:20:22,309 task. So a lot of times in c++, when you're\n 955 01:20:22,310 --> 01:20:26,920 designed to do a certain thing. So you might\n 956 01:20:26,920 --> 01:20:32,720 supposed to do something. And a function is\n 957 01:20:32,720 --> 01:20:36,420 code, and then you can reuse it throughout\n 958 01:20:36,420 --> 01:20:42,020 you guys how we can create a function in this\n 959 01:20:42,020 --> 01:20:46,190 see I have this little block of code here,\n 960 01:20:46,189 --> 01:20:50,319 parentheses. And then there's these open and\n 961 01:20:50,319 --> 01:20:56,819 function. This is a little block of code.\n 962 01:20:56,819 --> 01:21:03,189 task. And the purpose of this main function\n 963 01:21:03,189 --> 01:21:08,919 we run our program. So any code that we put\n 964 01:21:08,920 --> 01:21:12,960 executed when our program runs, I'm gonna\n 965 01:21:12,960 --> 01:21:19,010 So up here above this main function, I'm going\n 966 01:21:19,010 --> 01:21:24,500 this function will be performing is it's going\n 967 01:21:24,500 --> 01:21:30,630 a function in c++, we need to give c++ a couple\n 968 01:21:30,630 --> 01:21:36,310 information we need to give is called a return\n 969 01:21:36,310 --> 01:21:40,450 a lot of times the functions will go off,\n 970 01:21:40,449 --> 01:21:45,000 they'll return a value back to the caller.\n 971 01:21:45,000 --> 01:21:49,289 returns and return types in the next video.\n 972 01:21:49,289 --> 01:21:53,141 kind of just follow along. And I'm just going\n 973 01:21:53,141 --> 01:21:57,109 put void here, it basically means that this\n 974 01:21:57,109 --> 01:22:01,449 So this is kind of like the most basic type\n 975 01:22:01,449 --> 01:22:06,289 need to give this function a name. Remember,\n 976 01:22:06,289 --> 01:22:10,380 a task. So generally, when we're naming a\n 977 01:22:10,380 --> 01:22:14,329 according to the task that is performing or\n 978 01:22:14,329 --> 01:22:20,000 So I'm just going to call mine Say hi, because\n 979 01:22:20,000 --> 01:22:24,460 Now I'm going to make an open and closed parentheses.\n 980 01:22:24,460 --> 01:22:30,730 and closed curly bracket. Any code that I\n 981 01:22:30,729 --> 01:22:36,169 is going to be considered inside of the function.\n 982 01:22:36,170 --> 01:22:42,810 C out, and we'll just print out like Hello,\n 983 01:22:42,810 --> 01:22:47,940 this is a very simple function, I just have\n 984 01:22:47,939 --> 01:22:51,710 lines as I want. This is a simple function.\n 985 01:22:51,710 --> 01:22:55,369 100 lines, if I wanted to, you can put as\n 986 01:22:55,369 --> 01:23:01,059 want. Now, let's run our program. And we'll\n 987 01:23:01,060 --> 01:23:09,080 and run my program. And you'll see over here,\n 988 01:23:09,079 --> 01:23:13,750 isn't actually getting printed out when we\n 989 01:23:13,750 --> 01:23:17,939 we want to execute the code that's inside\n 990 01:23:17,939 --> 01:23:23,349 want to execute a function, we have to do\n 991 01:23:23,350 --> 01:23:27,970 this code inside of here to be executed, I\n 992 01:23:27,970 --> 01:23:31,930 code inside this main function gets executed\n 993 01:23:31,930 --> 01:23:37,409 is going to get executed. So inside of here,\n 994 01:23:37,409 --> 01:23:43,189 type out say hi. And I can type an open close\n 995 01:23:43,189 --> 01:23:50,300 this out, this tells c++ that I want to execute\n 996 01:23:50,301 --> 01:23:55,630 hi function. So when c++ sees this, it's going\n 997 01:23:55,630 --> 01:23:59,449 to execute all the code inside of there, and\n 998 01:23:59,449 --> 01:24:04,059 go ahead and run our program. And we'll see\n 999 01:24:04,060 --> 01:24:08,770 we're printing out Hello, user. And real quick,\n 1000 01:24:08,770 --> 01:24:14,760 flow of the so if I said like C out over here,\n 1001 01:24:14,760 --> 01:24:21,460 over here, and I said bottom. When I run my\n 1002 01:24:21,460 --> 01:24:26,619 top, hello, user and then bottom. And actually,\n 1003 01:24:26,619 --> 01:24:32,399 put new lines in there. But the point is that\n 1004 01:24:32,399 --> 01:24:36,960 execute this line of code, it's going to see\n 1005 01:24:36,960 --> 01:24:40,869 And it's actually going to leave this main\n 1006 01:24:40,869 --> 01:24:45,890 Say hi function, it'll execute all of the\n 1007 01:24:45,890 --> 01:24:50,690 of code to execute inside of the say, Hi function\n 1008 01:24:50,689 --> 01:24:56,210 and execute this line. So that's basically\n 1009 01:24:56,210 --> 01:25:00,000 is a very basic function, but we can make\n 1010 01:25:00,000 --> 01:25:05,270 With these functions, you can actually give\n 1011 01:25:05,270 --> 01:25:10,480 Say hi function, I can give this a piece of\n 1012 01:25:10,479 --> 01:25:16,000 that piece of information to, you know, performance\n 1013 01:25:16,000 --> 01:25:20,630 these are called parameters. And if I want\n 1014 01:25:20,630 --> 01:25:25,440 be given a piece of information, I can just\n 1015 01:25:25,439 --> 01:25:30,500 it should take. So, in our case, instead of\n 1016 01:25:30,500 --> 01:25:36,670 hello to someone specific. So up here, I could\n 1017 01:25:36,670 --> 01:25:42,359 going to accept one parameter a name. And\n 1018 01:25:42,359 --> 01:25:48,829 we can just say hello name. Now, whenever\n 1019 01:25:48,829 --> 01:25:54,100 it's specifying that it needs to take a parameter,\n 1020 01:25:54,100 --> 01:25:59,440 it a value. So in here, I can just pass it\n 1021 01:25:59,439 --> 01:26:06,609 Hello, Mike, because the value Mike is going\n 1022 01:26:06,609 --> 01:26:11,529 Alright, let's go ahead and run our program.\n 1023 01:26:11,529 --> 01:26:16,960 Mike. So that's kind of cool. And you can\n 1024 01:26:16,960 --> 01:26:20,560 and you can also take multiple parameters.\n 1025 01:26:20,560 --> 01:26:27,270 like age, so now the caller is going to have\n 1026 01:26:27,270 --> 01:26:34,830 we can say hello name, will say like you are.\n 1027 01:26:34,829 --> 01:26:40,559 So we'll say like age. So now we're passing\n 1028 01:26:40,560 --> 01:26:45,560 function. And down here, when I call the function,\n 1029 01:26:45,560 --> 01:26:51,060 So now I could just say, like, Mike, and let's\n 1030 01:26:51,060 --> 01:26:55,580 function, it's going to be able to take in\n 1031 01:26:55,579 --> 01:26:59,789 them to perform the task differently. And\n 1032 01:26:59,789 --> 01:27:05,210 call this as many times as I want. In other\n 1033 01:27:05,210 --> 01:27:09,890 up here. So I can come down here, I can copy\n 1034 01:27:09,890 --> 01:27:19,329 we'll say like, Tom is going to be 45. And\n 1035 01:27:19,329 --> 01:27:24,529 now, I'm actually going to run this code three\n 1036 01:27:24,529 --> 01:27:31,380 I'm just going to put a and line so that gets\n 1037 01:27:31,380 --> 01:27:37,630 the program. And you'll see it says hello,\n 1038 01:27:37,630 --> 01:27:42,440 functions are great, because we can reuse\n 1039 01:27:42,439 --> 01:27:48,139 So basically, like I wrote this function one\n 1040 01:27:48,140 --> 01:27:52,369 I want inside of my program. So anytime you\n 1041 01:27:52,369 --> 01:27:56,059 that's a good candidate for a function. Alright,\n 1042 01:27:56,060 --> 01:28:01,520 you'll notice that I'm creating this function\n 1043 01:28:01,520 --> 01:28:05,970 if I was to take this and move it down here,\n 1044 01:28:05,970 --> 01:28:10,070 function. Now when I run my program, we're\n 1045 01:28:10,069 --> 01:28:16,359 a little red block here. This is the problem,\n 1046 01:28:16,359 --> 01:28:21,960 function, it doesn't actually know about it.\n 1047 01:28:21,960 --> 01:28:27,090 executed. So c++ is trying to execute the\n 1048 01:28:27,090 --> 01:28:33,279 that is because we created it down here. So\n 1049 01:28:33,279 --> 01:28:38,829 called a function stub. So up here, we're\n 1050 01:28:38,829 --> 01:28:43,911 signature, and we're going to tell c++ about\n 1051 01:28:43,911 --> 01:28:48,390 a variable, like if I created an int, and\n 1052 01:28:48,390 --> 01:28:52,329 this a value right away, I could then come\n 1053 01:28:52,329 --> 01:28:56,590 or something. This is basically what we're\n 1054 01:28:56,590 --> 01:29:01,449 just declare the function and then somewhere\n 1055 01:29:01,449 --> 01:29:09,510 over here, I'm just gonna say, void, say hi.\n 1056 01:29:09,510 --> 01:29:17,630 int age. So now, when I create this little\n 1057 01:29:17,630 --> 01:29:23,230 I'm basically declaring the function and I\n 1058 01:29:23,229 --> 01:29:26,031 is going to be able to call it because it's\n 1059 01:29:26,032 --> 01:29:30,420 when I run my program, now, we're able to\n 1060 01:29:30,420 --> 01:29:35,220 how we can do that with functions. And really,\n 1061 01:29:35,220 --> 01:29:41,070 In fact, a good program will have lots and\n 1062 01:29:41,069 --> 01:29:44,549 I'm going to show you guys how we can actually\n 1063 01:29:44,550 --> 01:29:54,699 the return keyword. In this tutorial, I want\n 1064 01:29:54,699 --> 01:30:00,090 So when I'm talking about returns, I'm talking\n 1065 01:30:00,090 --> 01:30:04,750 can write functions which are basically like\n 1066 01:30:04,750 --> 01:30:09,130 that performs a specific task. And with those\n 1067 01:30:09,130 --> 01:30:12,720 pass them information. So I can give them\n 1068 01:30:12,720 --> 01:30:19,119 information that they can use to perform their\n 1069 01:30:19,119 --> 01:30:25,029 information functions can actually give us\n 1070 01:30:25,029 --> 01:30:29,069 not only can I give it parameters, but that\n 1071 01:30:29,069 --> 01:30:34,049 Now I'm going to show you guys how we can\n 1072 01:30:34,050 --> 01:30:39,489 in c++. So why don't we create a function\n 1073 01:30:39,489 --> 01:30:43,969 that's going to cube a number. So when I cube\n 1074 01:30:43,970 --> 01:30:48,570 power. So if I was to say like, two cubed,\n 1075 01:30:48,569 --> 01:30:53,439 power, or it's just going to be two times\n 1076 01:30:53,439 --> 01:30:58,969 number does. So why don't we create a c++\n 1077 01:30:58,970 --> 01:31:03,760 when we create a function in c++, the first\n 1078 01:31:03,760 --> 01:31:11,989 called a return type. And a return type basically\n 1079 01:31:11,989 --> 01:31:15,899 type, this function is going to return. Now\n 1080 01:31:15,899 --> 01:31:20,259 along with the course, we just put void here.\n 1081 01:31:20,260 --> 01:31:24,760 wasn't going to return any information. In\n 1082 01:31:24,760 --> 01:31:30,610 to return some information. So you can put\n 1083 01:31:30,609 --> 01:31:35,979 put like int, double, you put character, you\n 1084 01:31:35,979 --> 01:31:41,459 can go here. In our case, we're going to cube\n 1085 01:31:41,460 --> 01:31:43,810 And I'm going to say double. And now we need\n 1086 01:31:43,810 --> 01:31:48,900 call it cube. And we're going to take one\n 1087 01:31:48,899 --> 01:31:54,800 we take a double, and we'll just call it num.\n 1088 01:31:54,801 --> 01:32:00,090 to do is cube the number and then return the\n 1089 01:32:00,090 --> 01:32:05,699 to create a double, I'm going to call it result.\n 1090 01:32:05,699 --> 01:32:12,489 value of num, so I'm just gonna set it equal\n 1091 01:32:12,489 --> 01:32:19,859 me cubing num. So now result has inside of\n 1092 01:32:19,859 --> 01:32:26,139 okay, down here, I want to return the value\n 1093 01:32:26,140 --> 01:32:32,960 just say return result. And now this is going\n 1094 01:32:32,960 --> 01:32:38,140 stored inside result back to the caller. Now\n 1095 01:32:38,140 --> 01:32:43,950 call this function so I could say cube and\n 1096 01:32:43,949 --> 01:32:50,970 Right? Now, actually, what's going to happen\n 1097 01:32:50,970 --> 01:32:57,270 it's actually going to get a value back. So\n 1098 01:32:57,270 --> 01:33:05,990 answer is equal to cube 5.0. And now the value\n 1099 01:33:05,989 --> 01:33:10,380 is going to get stored inside of this answer\n 1100 01:33:10,380 --> 01:33:16,600 C out, and I'm just gonna print out answer.\n 1101 01:33:16,600 --> 01:33:22,539 see is, we're going to be printing out the\n 1102 01:33:22,539 --> 01:33:29,899 here, we get 125. So five times five is 2525,\n 1103 01:33:29,899 --> 01:33:35,639 number. And you can see here, this is getting\n 1104 01:33:35,640 --> 01:33:39,750 that gets returned from this function inside\n 1105 01:33:39,750 --> 01:33:47,479 cut out the middleman and I could just print\n 1106 01:33:47,479 --> 01:33:53,329 boy down here. And now it's going to do the\n 1107 01:33:53,329 --> 01:33:58,269 And actually up here, if we wanted, instead\n 1108 01:33:58,270 --> 01:34:05,230 of this result variable, I could instead just\n 1109 01:34:05,229 --> 01:34:10,069 cut out the middleman. And we'll just return\n 1110 01:34:10,069 --> 01:34:15,989 So there's also one more thing I want to talk\n 1111 01:34:15,989 --> 01:34:22,399 this returned keyword right here. This is\n 1112 01:34:22,399 --> 01:34:26,750 whenever we type out this return keyword,\n 1113 01:34:26,750 --> 01:34:32,340 executing the code inside of this function.\n 1114 01:34:32,340 --> 01:34:38,930 I just printed out like hello. When I run\n 1115 01:34:38,930 --> 01:34:44,360 printing out Hello, even though we're executing\n 1116 01:34:44,359 --> 01:34:49,899 all that code, it's never printing out Hello.\n 1117 01:34:49,899 --> 01:34:54,529 keyword, it's going to break us out of the\n 1118 01:34:54,529 --> 01:34:59,769 never going to get executed because it's never\n 1119 01:34:59,770 --> 01:35:04,360 is is going to break out and we'll head back\n 1120 01:35:04,359 --> 01:35:09,939 what this is doing. And that's sort of the\n 1121 01:35:09,939 --> 01:35:14,059 you didn't want to return a double, you could\n 1122 01:35:14,060 --> 01:35:18,780 you can even return something like an array.\n 1123 01:35:18,779 --> 01:35:27,050 And then that value will get stored over here.\n 1124 01:35:27,050 --> 01:35:33,340 guys about if statements in c++, an if statement\n 1125 01:35:33,340 --> 01:35:39,510 our code, which will allow our program to\n 1126 01:35:39,510 --> 01:35:44,260 situation occurs, we can do one thing. And\n 1127 01:35:44,260 --> 01:35:48,680 thing, essentially, we're able to check different\n 1128 01:35:48,680 --> 01:35:53,810 true, we can do certain things. And when those\n 1129 01:35:53,810 --> 01:35:57,360 So I'm going to show you guys exactly how\n 1130 01:35:57,359 --> 01:36:01,449 I'm just going to create a couple of different\n 1131 01:36:01,449 --> 01:36:06,529 is create a variable, it's going to be a boolean\n 1132 01:36:06,529 --> 01:36:13,000 a true or a false value, so I'm going to create\n 1133 01:36:13,000 --> 01:36:19,310 give this a value initially of true. So we're\n 1134 01:36:19,310 --> 01:36:23,320 storing whether or not someone is male, and\n 1135 01:36:23,319 --> 01:36:27,500 to show you guys how we can use an if statement.\n 1136 01:36:27,500 --> 01:36:33,010 to respond to different situations. So what\n 1137 01:36:33,010 --> 01:36:38,360 write an if statement that will respond to\n 1138 01:36:38,359 --> 01:36:43,299 the situation where the user is not a male.\n 1139 01:36:43,300 --> 01:36:46,921 I'm going to make an open and close parentheses,\n 1140 01:36:46,921 --> 01:36:54,390 curly bracket. Now, inside of this open and\n 1141 01:36:54,390 --> 01:36:59,530 So I can actually check a condition. And if\n 1142 01:36:59,529 --> 01:37:04,590 and close parentheses is true, then we're\n 1143 01:37:04,590 --> 01:37:08,750 If it's false, then we're going to move on.\n 1144 01:37:08,750 --> 01:37:14,680 true or a false value. And that's basically\n 1145 01:37:14,680 --> 01:37:20,550 So I'm gonna come down here, I'll say if and\n 1146 01:37:20,550 --> 01:37:26,050 what this is saying is if the value stored\n 1147 01:37:26,050 --> 01:37:31,539 if the value in here is true, then we're going\n 1148 01:37:31,539 --> 01:37:38,359 curly brackets. So I could say, like C out,\n 1149 01:37:38,359 --> 01:37:45,429 a male. And now when I run my program, you\n 1150 01:37:45,430 --> 01:37:51,390 And you'll see over here, it says you are\n 1151 01:37:51,390 --> 01:37:56,989 male was true. So the value that was inside\n 1152 01:37:56,988 --> 01:38:02,389 parentheses, which was true, and we executed\n 1153 01:38:02,390 --> 01:38:06,170 see that this code isn't going to get executed,\n 1154 01:38:06,170 --> 01:38:13,850 out. So because the value inside of this parentheses,\n 1155 01:38:13,850 --> 01:38:19,260 not going to execute this code. But let's\n 1156 01:38:19,260 --> 01:38:24,909 wanted to handle that situation, I can use\n 1157 01:38:24,909 --> 01:38:30,939 type out else just like that. And we're gonna\n 1158 01:38:30,939 --> 01:38:35,649 inside of this open and close curly bracket,\n 1159 01:38:35,649 --> 01:38:43,049 when this is false. So I'm going to show you\n 1160 01:38:43,050 --> 01:38:49,190 right, so I'm responding to this situation.\n 1161 01:38:49,189 --> 01:38:54,279 I run my program, it's going to be able to\n 1162 01:38:54,279 --> 01:39:00,429 are not male. Essentially, what's happening\n 1163 01:39:00,430 --> 01:39:07,280 respond to this variable. So if this variable\n 1164 01:39:07,279 --> 01:39:12,579 not true, it can also handle that. And so\n 1165 01:39:12,579 --> 01:39:16,750 specified a condition in our case, it was\n 1166 01:39:16,750 --> 01:39:21,829 of this is male variable. So that's kind of\n 1167 01:39:21,829 --> 01:39:26,729 I want to show you guys how we can make these\n 1168 01:39:26,729 --> 01:39:32,650 But let's say I added in another Boolean,\n 1169 01:39:32,650 --> 01:39:36,619 I'm going to set this equal to true and actually,\n 1170 01:39:36,619 --> 01:39:42,988 So now in addition to izmail, I also have\n 1171 01:39:42,988 --> 01:39:49,488 to see if the person was both male. And if\n 1172 01:39:49,488 --> 01:39:57,439 is I can use something called the AND operator\n 1173 01:39:57,439 --> 01:40:04,599 what's happening now is c++ is saying If the\n 1174 01:40:04,600 --> 01:40:10,650 we're going to print this out. So I'll just\n 1175 01:40:10,649 --> 01:40:15,479 line of code down here, and any of the code\n 1176 01:40:15,479 --> 01:40:20,839 is only going to get executed when is male\n 1177 01:40:20,840 --> 01:40:26,300 this and operator is allowing me to check\n 1178 01:40:26,300 --> 01:40:31,610 have to be true, in order for this line to\n 1179 01:40:31,609 --> 01:40:37,439 true and is tall is also true. So now, when\n 1180 01:40:37,439 --> 01:40:43,799 you are a tall male. Here's the thing, though,\n 1181 01:40:43,800 --> 01:40:48,550 his tall to false, this whole condition is\n 1182 01:40:48,550 --> 01:40:52,470 going to go down here to this else block.\n 1183 01:40:52,470 --> 01:40:57,449 not male, or not tall, but we'll just leave\n 1184 01:40:57,449 --> 01:41:01,840 Alright, so now it says you are not male,\n 1185 01:41:01,840 --> 01:41:06,869 should be different. But the point is that\n 1186 01:41:06,869 --> 01:41:11,819 values up here was false. And that's how we\n 1187 01:41:11,819 --> 01:41:17,738 operator called the OR operator. And that\n 1188 01:41:17,738 --> 01:41:24,469 conditions has to be true, in order for the\n 1189 01:41:24,470 --> 01:41:30,320 tall is set to false, and his male is set\n 1190 01:41:30,319 --> 01:41:36,119 it's still gonna say you are a tall male,\n 1191 01:41:36,119 --> 01:41:42,180 and run this program. Now, you'll see it says\n 1192 01:41:42,180 --> 01:41:48,020 that was inside this initial if block. And\n 1193 01:41:48,020 --> 01:41:52,850 both of these to false now, because we're\n 1194 01:41:52,850 --> 01:41:58,430 you are not male. So you'll see down here\n 1195 01:41:58,430 --> 01:42:03,990 how we can use and and how we can use or with\n 1196 01:42:03,989 --> 01:42:09,289 in both of them have to be true for the whole\n 1197 01:42:09,289 --> 01:42:12,710 one of the conditions has to be true for the\n 1198 01:42:12,710 --> 01:42:16,250 be true as well. And it'll be true. But if\n 1199 01:42:16,250 --> 01:42:21,460 be false. All right, let's make this even\n 1200 01:42:21,460 --> 01:42:26,489 another thing we can do, I'm going to bring\n 1201 01:42:26,489 --> 01:42:32,719 and is tall. But let's say that we wanted\n 1202 01:42:32,720 --> 01:42:38,039 weren't tall. So if they were like a short\n 1203 01:42:38,039 --> 01:42:44,170 So I can use another keyword. In c++, it's\n 1204 01:42:44,170 --> 01:42:47,510 and close parentheses and open and close curly\n 1205 01:42:47,510 --> 01:42:56,119 down to a new line. So else if is basically\n 1206 01:42:56,119 --> 01:43:00,829 then we're going to come down here, and we're\n 1207 01:43:00,829 --> 01:43:04,069 condition appears false, instead of just going\n 1208 01:43:04,069 --> 01:43:09,809 we're going to check another separate condition.\n 1209 01:43:09,810 --> 01:43:16,100 male, and they're not tall, so they're not\n 1210 01:43:16,100 --> 01:43:22,730 so I'm saying elsif is male, and is tall.\n 1211 01:43:22,729 --> 01:43:27,059 not tall. And here, I want to introduce you\n 1212 01:43:27,060 --> 01:43:32,039 negation operator, it's basically an exclamation\n 1213 01:43:32,039 --> 01:43:38,359 point before a condition like is tall, it's\n 1214 01:43:38,359 --> 01:43:42,859 So if is tall is true, and we put this negation\n 1215 01:43:42,859 --> 01:43:50,849 to false, and vice versa. So essentially,\n 1216 01:43:50,850 --> 01:43:57,180 is not tall. That's basically what this is\n 1217 01:43:57,180 --> 01:44:03,489 out, you are a short male, right? Because\n 1218 01:44:03,488 --> 01:44:09,169 is true, that means they're male, and they're\n 1219 01:44:09,170 --> 01:44:14,980 one more that we can check. So I'm going to\n 1220 01:44:14,979 --> 01:44:20,980 more possible scenario with these two variables\n 1221 01:44:20,980 --> 01:44:27,899 not male. So I can say not, is male, and is\n 1222 01:44:27,899 --> 01:44:31,670 could be like a tall female or something.\n 1223 01:44:31,670 --> 01:44:40,739 and say C out, and I'll just say you are tall,\n 1224 01:44:40,738 --> 01:44:45,879 printing that out onto the screen. So now\n 1225 01:44:45,880 --> 01:44:51,159 covered. So over here in this if else block\n 1226 01:44:51,159 --> 01:44:54,770 down here in this else block, we would want\n 1227 01:44:54,770 --> 01:45:00,819 are not male and not tall. So that's just\n 1228 01:45:00,819 --> 01:45:06,979 right, so we're able to respond to every possible\n 1229 01:45:06,979 --> 01:45:11,979 So let's try this out, I'm going to set both\n 1230 01:45:11,979 --> 01:45:16,189 to run my program. So they're both equal to\n 1231 01:45:16,189 --> 01:45:21,679 to that situation, who see it says you are\n 1232 01:45:21,680 --> 01:45:28,130 to that, let's set his male equal to false.\n 1233 01:45:28,130 --> 01:45:31,690 our program, once again, is going to be able\n 1234 01:45:31,689 --> 01:45:36,679 tall, but not male. So the program is smart\n 1235 01:45:36,680 --> 01:45:41,250 depending on the value of these variables.\n 1236 01:45:41,250 --> 01:45:47,449 to true and is tall to false. And again, it's\n 1237 01:45:47,449 --> 01:45:53,420 you are a short male. And then finally, we'll\n 1238 01:45:53,420 --> 01:46:01,130 answer which is going to be you're not male,\n 1239 01:46:01,130 --> 01:46:05,300 figure this out just by using all this stuff.\n 1240 01:46:05,300 --> 01:46:10,570 time, we have this if statement, and it's\n 1241 01:46:10,569 --> 01:46:15,659 Now, these are both conditions, right? So\n 1242 01:46:15,659 --> 01:46:21,229 essentially, it's a true or false value, right?\n 1243 01:46:21,229 --> 01:46:25,939 of these are true, then we'll execute the\n 1244 01:46:25,939 --> 01:46:28,710 we'll come down here and we'll check this\n 1245 01:46:28,710 --> 01:46:32,829 that. And so we get down here, and we figured\n 1246 01:46:32,829 --> 01:46:37,659 tall. So that's the basics of if statements.\n 1247 01:46:37,659 --> 01:46:41,050 of if statements, I talk to you guys about\n 1248 01:46:41,050 --> 01:46:44,619 there's one more thing I want to talk to you\n 1249 01:46:44,619 --> 01:46:50,989 called comparisons. And down here, we're using\n 1250 01:46:50,989 --> 01:46:54,840 conditions right, so I'm using these, and\n 1251 01:46:54,840 --> 01:46:59,301 right. But we can also use something called\n 1252 01:46:59,301 --> 01:47:03,250 check to see if different values relate to\n 1253 01:47:03,250 --> 01:47:07,159 to see if like a number is greater than another\n 1254 01:47:07,159 --> 01:47:11,989 comparisons as our conditions. And that's\n 1255 01:47:11,989 --> 01:47:19,149 next tutorial. And I'll talk to you guys more\n 1256 01:47:19,149 --> 01:47:23,379 I'm going to talk to you guys some more about\n 1257 01:47:23,380 --> 01:47:28,380 to be looking at using comparisons inside\n 1258 01:47:28,380 --> 01:47:34,551 be kind of cool. In this tutorial, I want\n 1259 01:47:34,551 --> 01:47:39,989 a function, and it's going to basically tell\n 1260 01:47:39,988 --> 01:47:44,889 will take as parameters, two numbers, and\n 1261 01:47:44,890 --> 01:47:49,660 is the largest. And this is a great example\n 1262 01:47:49,659 --> 01:47:54,239 So over here, I have my main function. And\n 1263 01:47:54,239 --> 01:47:57,488 And let's just say it's going to return an\n 1264 01:47:57,488 --> 01:48:03,189 max. And we'll make an open and close parentheses\n 1265 01:48:03,189 --> 01:48:06,609 of this function, we're going to take two\n 1266 01:48:06,609 --> 01:48:11,969 and we'll get another integer. So essentially,\n 1267 01:48:11,970 --> 01:48:17,990 as input. And the goal will be to figure out\n 1268 01:48:17,989 --> 01:48:23,130 return that back to the caller. First thing\n 1269 01:48:23,130 --> 01:48:28,859 result. And I'm not going to give this value\n 1270 01:48:28,859 --> 01:48:36,109 this function, we're going to return results.\n 1271 01:48:36,109 --> 01:48:40,500 whichever of these is bigger inside of this\n 1272 01:48:40,500 --> 01:48:45,680 interesting. Now, we need to figure out which\n 1273 01:48:45,680 --> 01:48:50,930 do that. So I'm just going to say F, open\n 1274 01:48:50,930 --> 01:48:56,230 curly bracket. Now, inside of this parentheses,\n 1275 01:48:56,229 --> 01:49:00,859 we need to put a true or false value, right?\n 1276 01:49:00,859 --> 01:49:05,630 down here. If the value is false, then we'll\n 1277 01:49:05,630 --> 01:49:09,430 the last tutorial, when we were learning about\n 1278 01:49:09,430 --> 01:49:13,570 and a Boolean is a true or false value. So\n 1279 01:49:13,569 --> 01:49:18,069 in there, and it's true, or its false. And\n 1280 01:49:18,069 --> 01:49:22,259 But in a lot of cases, we're not going to\n 1281 01:49:22,260 --> 01:49:26,659 us. So it's not going to be as easy as just\n 1282 01:49:26,659 --> 01:49:31,238 only information that we have are these two\n 1283 01:49:31,238 --> 01:49:38,569 or a false value using just those two numbers?\n 1284 01:49:38,569 --> 01:49:42,529 So if I want to figure out which of these\n 1285 01:49:42,529 --> 01:49:49,359 right so over here inside of this if condition\n 1286 01:49:49,359 --> 01:49:56,199 than num two, if num one is greater than num\n 1287 01:49:56,199 --> 01:50:01,550 num one. And the reason I'm doing that is\n 1288 01:50:01,550 --> 01:50:08,010 if this comparison is true, the num one is\n 1289 01:50:08,010 --> 01:50:12,460 num, one greater than num two, it's actually\n 1290 01:50:12,460 --> 01:50:18,529 false value. Right? num. One is either greater\n 1291 01:50:18,529 --> 01:50:23,649 is going to be a boolean value, right? Once\n 1292 01:50:23,649 --> 01:50:27,569 out if it's true or not, it's going to be\n 1293 01:50:27,569 --> 01:50:32,939 check to see if num one is greater than num\n 1294 01:50:32,939 --> 01:50:41,439 num one. And we can just say else, and we'll\n 1295 01:50:41,439 --> 01:50:45,699 reason we're saying this down here is because\n 1296 01:50:45,699 --> 01:50:50,988 bigger than num two, then we know that num\n 1297 01:50:50,988 --> 01:50:54,759 certain circumstances, the numbers might be\n 1298 01:50:54,760 --> 01:50:59,310 So down here, we're going to return the result.\n 1299 01:50:59,310 --> 01:51:04,880 I'm just gonna come down here. And why don't\n 1300 01:51:04,880 --> 01:51:10,920 say get max. And we'll throw like a two and\n 1301 01:51:10,920 --> 01:51:15,181 a five. And now when we run this program,\n 1302 01:51:15,180 --> 01:51:21,529 I'm gonna run the program. And Yep, over here,\n 1303 01:51:21,529 --> 01:51:27,340 So this is basically how we can use comparisons\n 1304 01:51:27,340 --> 01:51:32,340 Technically, this comparison is going to get\n 1305 01:51:32,340 --> 01:51:37,529 to get resolved down to a true or false, like\n 1306 01:51:37,529 --> 01:51:41,759 And that's kind of interesting. So that's\n 1307 01:51:41,760 --> 01:51:46,591 greater than we could also use less than,\n 1308 01:51:46,591 --> 01:51:53,760 use greater than or equal to, we can use equal\n 1309 01:51:53,760 --> 01:51:58,610 we use the equal sign down here, we're using\n 1310 01:51:58,609 --> 01:52:04,359 result the value stored inside num one. When\n 1311 01:52:04,359 --> 01:52:09,369 operator. So I'm comparing the value of num\n 1312 01:52:09,369 --> 01:52:12,229 that's either going to be true or false, right?\n 1313 01:52:12,229 --> 01:52:18,179 or they're not. And then the last one we can\n 1314 01:52:18,180 --> 01:52:21,869 what you think it does. This whole thing is\n 1315 01:52:21,869 --> 01:52:27,859 num, two. So those are sort of the basics.\n 1316 01:52:27,859 --> 01:52:34,269 So this get max function takes two integers.\n 1317 01:52:34,270 --> 01:52:39,900 int, num, three. Now all the sudden, instead\n 1318 01:52:39,899 --> 01:52:44,239 figure out which is bigger among the three\n 1319 01:52:44,239 --> 01:52:48,670 statement a lot more complicated. So why don't\n 1320 01:52:48,670 --> 01:52:54,980 how we can do this. So inside of this comparison,\n 1321 01:52:54,979 --> 01:53:00,859 than num two, just like we did last time.\n 1322 01:53:00,859 --> 01:53:06,420 is bigger than num three. If no one's bigger\n 1323 01:53:06,420 --> 01:53:11,180 then we know it's the biggest. So let's start\n 1324 01:53:11,180 --> 01:53:14,920 instead of just saying greater than I'm gonna\n 1325 01:53:14,920 --> 01:53:18,920 is that chance where they're all the same\n 1326 01:53:18,920 --> 01:53:24,680 So we can say if num one is greater than or\n 1327 01:53:24,680 --> 01:53:29,090 this and operator and this is going to allow\n 1328 01:53:29,090 --> 01:53:35,360 num one is greater than or equal to num three.\n 1329 01:53:35,359 --> 01:53:39,719 to num two and is greater than or equal to\n 1330 01:53:39,720 --> 01:53:45,720 biggest. So I'm going to set result equal\n 1331 01:53:45,720 --> 01:53:51,930 another condition. So I'm gonna say else if\n 1332 01:53:51,930 --> 01:53:59,220 two is greater than or equal to num one. And\n 1333 01:53:59,220 --> 01:54:04,510 And if this is the case, in other words, we're\n 1334 01:54:04,510 --> 01:54:09,710 of here is false. So this condition is false.\n 1335 01:54:09,710 --> 01:54:13,930 But if this condition is true down here, then\n 1336 01:54:13,930 --> 01:54:20,590 say result is equal to num two. Now all we\n 1337 01:54:20,590 --> 01:54:27,720 we can just say result is equal to num three.\n 1338 01:54:27,720 --> 01:54:32,560 num one's not the biggest. If this condition\n 1339 01:54:32,560 --> 01:54:38,580 biggest. So if num one's not the biggest and\n 1340 01:54:38,579 --> 01:54:43,649 must be the biggest. So we're going to default\n 1341 01:54:43,649 --> 01:54:47,479 else block that we need. And you see I'm using\n 1342 01:54:47,479 --> 01:54:52,339 am I using this and operator, I'm also using\n 1343 01:54:52,340 --> 01:54:56,800 these guys are called. So let's go ahead and\n 1344 01:54:56,800 --> 01:55:01,800 of saying two parameters, we need to pass\n 1345 01:55:01,800 --> 01:55:08,119 and we should get 10 back, which we do, if\n 1346 01:55:08,119 --> 01:55:13,789 So for example, I could test out, we'll make\n 1347 01:55:13,789 --> 01:55:18,369 we'll see if it works. And it does. And we'll\n 1348 01:55:18,369 --> 01:55:26,130 if it works. And it does cool. And then also\n 1349 01:55:26,130 --> 01:55:31,529 them were the same. So let's try this were\n 1350 01:55:31,529 --> 01:55:36,488 And we're on the program. And yeah, so it's\n 1351 01:55:36,488 --> 01:55:40,009 is our max function. And hopefully this gives\n 1352 01:55:40,010 --> 01:55:45,800 comparisons. Now we can compare all different\n 1353 01:55:45,800 --> 01:55:50,420 we can compare integers, we can also compare\n 1354 01:55:50,420 --> 01:56:01,630 characters. So you can compare all those guys\n 1355 01:56:01,630 --> 01:56:05,609 this tutorial, I'm going to show you guys\n 1356 01:56:05,609 --> 01:56:09,319 c++. Now, if you've been following along with\n 1357 01:56:09,319 --> 01:56:13,960 of the course, we created a very simple calculator.\n 1358 01:56:13,960 --> 01:56:19,149 take in two numbers as input, and added them\n 1359 01:56:19,149 --> 01:56:23,349 this tutorial, now we've learned a little\n 1360 01:56:23,350 --> 01:56:28,620 to build a more complex calculator. So this\n 1361 01:56:28,619 --> 01:56:33,199 in two numbers, but it's also going to allow\n 1362 01:56:33,199 --> 01:56:37,359 to perform. So they can specify that they\n 1363 01:56:37,359 --> 01:56:42,469 divide them, multiply them, whatever. So it's\n 1364 01:56:42,469 --> 01:56:47,859 So down here, inside of my main function,\n 1365 01:56:47,859 --> 01:56:52,009 And the first thing I'm going to do is create\n 1366 01:56:52,010 --> 01:56:55,409 variables. And why don't we just create these\n 1367 01:56:55,409 --> 01:56:59,569 if you wanted. We'll just call them num one\n 1368 01:56:59,569 --> 01:57:04,340 the two numbers that we want to perform the\n 1369 01:57:04,340 --> 01:57:09,480 going to want to create a character. And I'm\n 1370 01:57:09,479 --> 01:57:12,559 going to throw the two numbers here. And we're\n 1371 01:57:12,560 --> 01:57:17,820 either going to be plus or minus division,\n 1372 01:57:17,819 --> 01:57:22,090 created those two variables, we want to start\n 1373 01:57:22,090 --> 01:57:25,890 user. The first thing that we want to do is\n 1374 01:57:25,890 --> 01:57:33,340 C out. And I'll basically just print out enter\n 1375 01:57:33,340 --> 01:57:37,480 in the first number. And then down here, we're\n 1376 01:57:37,479 --> 01:57:43,679 these, these two greater than signs. And we\n 1377 01:57:43,680 --> 01:57:48,180 one, just like that. Okay, cool. So now that\n 1378 01:57:48,180 --> 01:57:54,630 copy this code, and then down here, we can\n 1379 01:57:54,630 --> 01:58:00,279 going to ask them for the operator. So I'll\n 1380 01:58:00,279 --> 01:58:05,420 the operator inside of that Opie variable\n 1381 01:58:05,420 --> 01:58:09,920 to enter in the second number, and we'll store\n 1382 01:58:09,920 --> 01:58:13,539 doing is I'm prompting the user for all of\n 1383 01:58:13,539 --> 01:58:16,189 to get that first number, we're going to get\n 1384 01:58:16,189 --> 01:58:21,238 second number. So they'd give me like five\n 1385 01:58:21,238 --> 01:58:26,250 like that. Alright, so now that we have all\n 1386 01:58:26,250 --> 01:58:31,121 that we need to do, which is we need to figure\n 1387 01:58:31,121 --> 01:58:35,840 here, we have the operator. So ideally, they\n 1388 01:58:35,840 --> 01:58:40,329 sign, whatever, but we don't know what exactly\n 1389 01:58:40,329 --> 01:58:44,039 what what they were going to enter in. So\n 1390 01:58:44,039 --> 01:58:47,600 perfect scenario for an if statement. So I'm\n 1391 01:58:47,600 --> 01:58:54,360 you guys how we can check this. So I'm just\n 1392 01:58:54,359 --> 01:58:58,988 in here. So basically, what we want to do\n 1393 01:58:58,988 --> 01:59:04,259 So the first thing I'm gonna do is just check\n 1394 01:59:04,260 --> 01:59:09,369 sign. Right? So if the operator is equal to\n 1395 01:59:09,369 --> 01:59:13,920 to print out the result of adding the two\n 1396 01:59:13,920 --> 01:59:19,659 here, and I'm going to create an integer called\n 1397 01:59:19,659 --> 01:59:26,609 equal to num, one plus num, two. And we know\n 1398 01:59:26,609 --> 01:59:32,949 is true, then we're going to execute this\n 1399 01:59:32,949 --> 01:59:37,670 I basically just want to check to see if it's\n 1400 01:59:37,670 --> 01:59:42,520 to a minus sign, and if it is equal to a minus\n 1401 01:59:42,520 --> 01:59:48,110 there. But we can subtract the two numbers.\n 1402 01:59:48,109 --> 01:59:52,609 so we can do the same thing for multiplication\n 1403 01:59:52,609 --> 02:00:01,829 copy this else if, and I'll paste it down\n 1404 02:00:01,829 --> 02:00:06,939 forward slash, that means division. And then\n 1405 02:00:06,939 --> 02:00:13,210 multiplication. So use this Asterix, and then\n 1406 02:00:13,210 --> 02:00:17,609 So now we're basically covering all of the\n 1407 02:00:17,609 --> 02:00:22,269 we got that covered minus sign, division sign\n 1408 02:00:22,270 --> 02:00:27,521 all of those standard scenarios, but there's\n 1409 02:00:27,520 --> 02:00:31,619 an invalid operator. So instead of entering\n 1410 02:00:31,619 --> 02:00:35,420 like, you know, random character, in which\n 1411 02:00:35,420 --> 02:00:41,510 here. And this LS block is going to get executed\n 1412 02:00:41,510 --> 02:00:45,390 So if none of the conditions are true, then\n 1413 02:00:45,390 --> 02:00:49,910 So I'm just going to go ahead and print that\n 1414 02:00:49,909 --> 02:00:57,510 print out invalid operator. Alright, so basically,\n 1415 02:00:57,510 --> 02:01:01,840 a value stored inside of result. So down here,\n 1416 02:01:01,840 --> 02:01:10,130 just say C out, and we'll print out result.\n 1417 02:01:10,130 --> 02:01:14,510 I'm going to go ahead and run the program.\n 1418 02:01:14,510 --> 02:01:19,539 we insert a five? Enter operator, let's enter\n 1419 02:01:19,539 --> 02:01:25,560 do 30. So now when I click enter, hopefully\n 1420 02:01:25,560 --> 02:01:29,300 be able to figure out which operation I was\n 1421 02:01:29,300 --> 02:01:34,409 it correctly. So you see down here, we printed\n 1422 02:01:34,409 --> 02:01:42,300 So why don't we try a couple other ones. Let's\n 1423 02:01:42,300 --> 02:01:46,301 we get 10. Yes, it looks like that's working.\n 1424 02:01:46,301 --> 02:01:51,110 check to see if we enter an invalid operator.\n 1425 02:01:51,109 --> 02:01:56,130 the operator, let's make it like a capital\n 1426 02:01:56,130 --> 02:02:00,219 And you'll see down here it prints out invalid\n 1427 02:02:00,219 --> 02:02:04,460 other little printout here. And actually,\n 1428 02:02:04,460 --> 02:02:09,329 we didn't give result in initial value. Alright,\n 1429 02:02:09,329 --> 02:02:14,409 you guys can see how we can combine getting\n 1430 02:02:14,409 --> 02:02:21,479 if statements to basically figure out what\n 1431 02:02:21,479 --> 02:02:28,949 And this tutorial, I'm going to talk to you\n 1432 02:02:28,949 --> 02:02:34,738 Now a switch statement is basically a special\n 1433 02:02:34,738 --> 02:02:40,859 one particular value against a bunch of other\n 1434 02:02:40,859 --> 02:02:44,939 when we're trying to compare different things.\n 1435 02:02:44,939 --> 02:02:49,250 statements are. And we'll do an example which\n 1436 02:02:49,250 --> 02:02:54,920 So in my program, In this tutorial, I actually\n 1437 02:02:54,920 --> 02:03:00,380 going to be able to convert a number into\n 1438 02:03:00,380 --> 02:03:06,420 passed in a zero to this function, I'd want\n 1439 02:03:06,420 --> 02:03:11,680 the user passed in a one, I'd want to be able\n 1440 02:03:11,680 --> 02:03:16,420 to be able to convert an integer number to\n 1441 02:03:16,420 --> 02:03:21,710 gonna show you guys how we can do this inside\n 1442 02:03:21,710 --> 02:03:26,890 my function, and we're basically just going\n 1443 02:03:26,890 --> 02:03:33,800 to call it get day of a week, just like that.\n 1444 02:03:33,800 --> 02:03:38,289 And this is going to take one parameter, which\n 1445 02:03:38,289 --> 02:03:43,649 call it day num. So this is going to be the\n 1446 02:03:43,649 --> 02:03:49,639 through six, basically. Alright, so inside\n 1447 02:03:49,640 --> 02:03:53,630 out how we can do this. So depending on the\n 1448 02:03:53,630 --> 02:03:59,569 on the day num, that they give us, we want\n 1449 02:03:59,569 --> 02:04:04,488 the first thing I'll do is I'm going to create\n 1450 02:04:04,488 --> 02:04:08,569 and I'm just going to call it day name. So\n 1451 02:04:08,569 --> 02:04:13,889 the name of the day that they requested. And\n 1452 02:04:13,890 --> 02:04:19,239 we're going to return it. So I'm just going\n 1453 02:04:19,238 --> 02:04:23,879 we're going to end up returning. So our goal\n 1454 02:04:23,880 --> 02:04:29,340 this day name variable with the correct day\n 1455 02:04:29,340 --> 02:04:33,860 mean, one way that we can build this function\n 1456 02:04:33,859 --> 02:04:40,779 like, if day num is equal to zero, and if\n 1457 02:04:40,779 --> 02:04:46,899 name is equal to Sunday, right? That works.\n 1458 02:04:46,899 --> 02:04:53,609 day of the week. So I can say like, else if\n 1459 02:04:53,609 --> 02:04:58,759 is equal to something else. So day num is\n 1460 02:04:58,760 --> 02:05:04,550 same exact thing. So we Ad name is equal to\n 1461 02:05:04,550 --> 02:05:08,440 single day of the week. Here's the problem,\n 1462 02:05:08,439 --> 02:05:13,689 times, right? Potentially eight times, if\n 1463 02:05:13,689 --> 02:05:18,059 I'm going to have to create eight of these\n 1464 02:05:18,060 --> 02:05:23,770 this out. And that is extremely inefficient.\n 1465 02:05:23,770 --> 02:05:28,910 for us to use something called a switch statement.\n 1466 02:05:28,909 --> 02:05:34,789 we're doing over here with these if else statements,\n 1467 02:05:34,789 --> 02:05:39,359 I want you guys to notice is in every single\n 1468 02:05:39,359 --> 02:05:44,639 every single one of these, if conditions,\n 1469 02:05:44,640 --> 02:05:49,670 num is equal to a different value. So in here,\n 1470 02:05:49,670 --> 02:05:53,840 we're saying Dana equal to one and the next\n 1471 02:05:53,840 --> 02:05:58,860 equal to three, all of those conditions are\n 1472 02:05:58,859 --> 02:06:04,119 else. And when you have a situation like that,\n 1473 02:06:04,119 --> 02:06:07,519 So I'm going to show you guys how we can use\n 1474 02:06:07,520 --> 02:06:12,280 So I'm just going to write out switch and\n 1475 02:06:12,279 --> 02:06:16,539 close curly brackets. So so far, it looks\n 1476 02:06:16,539 --> 02:06:20,469 opening, close parentheses, I'm going to put\n 1477 02:06:20,469 --> 02:06:25,439 the value in here that we want to compare\n 1478 02:06:25,439 --> 02:06:33,198 it's going to be daenam. Right, I'm comparing\n 1479 02:06:33,198 --> 02:06:37,779 is the value that I want to compare to all\n 1480 02:06:37,779 --> 02:06:42,880 statement, I can write cases. And basically\n 1481 02:06:42,880 --> 02:06:48,829 value in here. So I can say zero and a colon.\n 1482 02:06:48,829 --> 02:06:54,550 what I want to happen. So I could say day\n 1483 02:06:54,550 --> 02:07:00,449 what this is doing is it's saying in the case,\n 1484 02:07:00,448 --> 02:07:05,619 set day name equal to Sunday. And then right\n 1485 02:07:05,619 --> 02:07:09,880 I'll explain what break does in a second.\n 1486 02:07:09,880 --> 02:07:18,909 for every single number. So I could say like,\n 1487 02:07:18,909 --> 02:07:25,529 to one, I'm going to set day name equal to\n 1488 02:07:25,529 --> 02:07:32,590 say break. And then I can keep doing this\n 1489 02:07:32,590 --> 02:07:37,260 is doing down here, this break statement is\n 1490 02:07:37,260 --> 02:07:42,900 statement. So if I don't put this break statement\n 1491 02:07:42,899 --> 02:07:47,979 through all these cases. So even if daenam\n 1492 02:07:47,979 --> 02:07:51,849 Sunday, it's still going to keep going and\n 1493 02:07:51,850 --> 02:07:56,390 I say break right here. And generally, it's\n 1494 02:07:56,390 --> 02:08:00,770 be able to check for more than one condition,\n 1495 02:08:00,770 --> 02:08:05,560 num is equal to zero, we're going to do all\n 1496 02:08:05,560 --> 02:08:08,870 to make one of these for each day of the week.\n 1497 02:08:08,869 --> 02:08:12,909 we'll meet back here, and I'll kind of show\n 1498 02:08:12,909 --> 02:08:17,139 and made one of these little case blocks for\n 1499 02:08:17,140 --> 02:08:24,079 here we have zero through six. And they're\n 1500 02:08:24,079 --> 02:08:29,680 So in case three, day name is Wednesday, etc,\n 1501 02:08:29,680 --> 02:08:33,480 Now there's one more thing that we have to\n 1502 02:08:33,479 --> 02:08:38,639 there's always the chance that the user enters\n 1503 02:08:38,640 --> 02:08:43,270 words, if the user doesn't enter zero through\n 1504 02:08:43,270 --> 02:08:47,260 In other words, I want to be able to handle\n 1505 02:08:47,260 --> 02:08:50,969 isn't in here. And inside of a switch statement,\n 1506 02:08:50,969 --> 02:08:56,359 default. So we can just say default, a colon,\n 1507 02:08:56,359 --> 02:09:02,189 get executed, if none of the cases up here\n 1508 02:09:02,189 --> 02:09:07,599 any of these numbers up here, then this code\n 1509 02:09:07,600 --> 02:09:14,829 So down here, I could just say, day name is\n 1510 02:09:14,829 --> 02:09:18,869 we have our switch statement set up. And you\n 1511 02:09:18,869 --> 02:09:23,180 like an if statement. So this is a lot clearer\n 1512 02:09:23,180 --> 02:09:28,110 LSF like 1000 times, we don't need all those\n 1513 02:09:28,109 --> 02:09:32,869 it's just really clear, it's really easy to\n 1514 02:09:32,869 --> 02:09:38,569 see if our get day the week function is working.\n 1515 02:09:38,569 --> 02:09:42,639 going to print out the value. So I'll say\n 1516 02:09:42,640 --> 02:09:50,800 day of week and we need to pass this an integer.\n 1517 02:09:50,800 --> 02:09:57,690 we should get printed out here Monday. Or\n 1518 02:09:57,689 --> 02:10:01,559 so Sunday would be the first day of the week.\n 1519 02:10:01,560 --> 02:10:06,510 So I'm going to put one here instead of zero.\n 1520 02:10:06,510 --> 02:10:13,001 All right, let's try one more, we'll try six.\n 1521 02:10:13,001 --> 02:10:17,900 see if it works. Cool. So Saturday worked\n 1522 02:10:17,899 --> 02:10:22,469 which is where we pass in an invalid number.\n 1523 02:10:22,469 --> 02:10:27,960 be able to see that this isn't going to work.\n 1524 02:10:27,960 --> 02:10:32,890 So this is a pretty cool function. And it's\n 1525 02:10:32,890 --> 02:10:36,780 case statements. In order to make this a lot\n 1526 02:10:36,779 --> 02:10:40,738 easily done this with an if statement, nothing\n 1527 02:10:40,738 --> 02:10:45,250 lot easier to use something like a switch\n 1528 02:10:45,250 --> 02:10:54,039 in the language. In this tutorial, I'm going\n 1529 02:10:54,039 --> 02:10:59,869 c++. Now a while loop is basically just a\n 1530 02:10:59,869 --> 02:11:07,079 through a block of code, while a certain condition\n 1531 02:11:07,079 --> 02:11:12,000 into something called loops. And loops are\n 1532 02:11:12,000 --> 02:11:16,939 in our programs, specifically in c++, where\n 1533 02:11:16,939 --> 02:11:21,169 code and do things a bunch of times. So I'm\n 1534 02:11:21,170 --> 02:11:25,710 type of loop, which is a while loop. And we'll\n 1535 02:11:25,710 --> 02:11:29,439 Alright, so down here, the first thing I'm\n 1536 02:11:29,439 --> 02:11:33,019 is I'm actually just going to create an integer.\n 1537 02:11:33,020 --> 02:11:37,210 going to set it equal to one. So this isn't\n 1538 02:11:37,210 --> 02:11:41,690 loops. We're just going to use this in our\n 1539 02:11:41,690 --> 02:11:46,500 to create a while loop, I can basically just\n 1540 02:11:46,500 --> 02:11:52,020 and an open and closed, curly bracket, and\n 1541 02:11:52,020 --> 02:11:57,420 main outline for a while loop. Now here's\n 1542 02:11:57,420 --> 02:12:02,170 of these parentheses, I'm going to specify\n 1543 02:12:02,170 --> 02:12:07,069 about if statements in c++, this is essentially\n 1544 02:12:07,069 --> 02:12:14,509 a condition just like we would an if statement.\n 1545 02:12:14,510 --> 02:12:20,840 going to loop over and continually execute\n 1546 02:12:20,840 --> 02:12:23,779 brackets, as you'll see in a second, we're\n 1547 02:12:23,779 --> 02:12:29,460 curly brackets. And as long as the condition\n 1548 02:12:29,460 --> 02:12:33,409 through that code. And every single time we\n 1549 02:12:33,409 --> 02:12:37,840 this condition. So let me just show you guys\n 1550 02:12:37,840 --> 02:12:42,560 going on. So up here in these parentheses,\n 1551 02:12:42,560 --> 02:12:50,060 what I want to do is I'm going to say while\n 1552 02:12:50,060 --> 02:12:54,650 is now my condition, while index is less than\n 1553 02:12:54,649 --> 02:12:59,769 code inside of this loop. So I'm going to\n 1554 02:12:59,770 --> 02:13:05,060 So down here, what I want to do is I basically\n 1555 02:13:05,060 --> 02:13:11,500 just going to say, C out index. And then I'm\n 1556 02:13:11,500 --> 02:13:16,149 line. And then down here, I'm going to increment\n 1557 02:13:16,149 --> 02:13:22,159 plus. So you remember index plus, plus just\n 1558 02:13:22,159 --> 02:13:26,210 what I'm doing is I'm specifying my condition,\n 1559 02:13:26,210 --> 02:13:32,010 I want to execute all of this code. So I'm\n 1560 02:13:32,010 --> 02:13:35,420 sort of see already what this is going to\n 1561 02:13:35,420 --> 02:13:40,779 we're going to take a look at what's happening.\n 1562 02:13:40,779 --> 02:13:48,859 we basically got 12345. Here's what's happening\n 1563 02:13:48,859 --> 02:13:54,380 index, I set it equal to one and I basically\n 1564 02:13:54,380 --> 02:13:59,369 equal to five, I want to keep looping over\n 1565 02:13:59,369 --> 02:14:03,170 the first time we went through, we checked\n 1566 02:14:03,170 --> 02:14:08,039 is less than or equal to five. Since that\n 1567 02:14:08,039 --> 02:14:13,819 one on the first iteration of the loop, we\n 1568 02:14:13,819 --> 02:14:18,960 and then we incremented index, so index was\n 1569 02:14:18,960 --> 02:14:24,010 back up here and we check this condition again.\n 1570 02:14:24,010 --> 02:14:29,760 equal to five. In this case, index is equal\n 1571 02:14:29,760 --> 02:14:33,869 or equal to five. So we're going to execute\n 1572 02:14:33,869 --> 02:14:39,090 printed out two, and then we incremented to\n 1573 02:14:39,090 --> 02:14:44,159 checked the condition again, every single\n 1574 02:14:44,159 --> 02:14:49,019 condition. So before we execute the loop,\n 1575 02:14:49,020 --> 02:14:54,460 check it again and execute the code again.\n 1576 02:14:54,460 --> 02:14:59,020 was equal to six. So we came up here to check\n 1577 02:14:59,020 --> 02:15:03,590 equal to five. So Then we just came down,\n 1578 02:15:03,590 --> 02:15:09,701 was happy. So that's essentially what we did.\n 1579 02:15:09,701 --> 02:15:14,469 a condition, as long as that condition is\n 1580 02:15:14,469 --> 02:15:18,750 much just keep looping through all the code\n 1581 02:15:18,750 --> 02:15:22,529 where using loops is gonna come in handy.\n 1582 02:15:22,529 --> 02:15:26,340 to build a little game where we can use a\n 1583 02:15:26,341 --> 02:15:29,510 to talk to you guys about a couple more things\n 1584 02:15:29,510 --> 02:15:35,409 to watch out for when you're using these loops\n 1585 02:15:35,409 --> 02:15:42,569 loop is a situation where this condition up\n 1586 02:15:42,569 --> 02:15:47,269 like the condition that you specify up here\n 1587 02:15:47,270 --> 02:15:51,810 will just continually loop through. So for\n 1588 02:15:51,810 --> 02:15:56,860 of code right here, where we're incrementing\n 1589 02:15:56,859 --> 02:16:02,219 one. And so this condition up here is never\n 1590 02:16:02,220 --> 02:16:06,600 you'll see over here that we're just continually\n 1591 02:16:06,600 --> 02:16:10,380 flashing, really what's happening is we're\n 1592 02:16:10,380 --> 02:16:14,319 that while loop, and it's never going to stop\n 1593 02:16:14,319 --> 02:16:19,099 never going to stop, right because that condition\n 1594 02:16:19,100 --> 02:16:23,980 want to make sure that any conditions that\n 1595 02:16:23,979 --> 02:16:27,709 point are going to become false. Now, there\n 1596 02:16:27,710 --> 02:16:32,870 to want a while loop. But I would say for\n 1597 02:16:32,870 --> 02:16:36,380 be necessary. And they can actually be dangerous,\n 1598 02:16:36,379 --> 02:16:40,759 you're like creating variables or allocating\n 1599 02:16:40,760 --> 02:16:45,719 program or even crashing your computer if\n 1600 02:16:45,718 --> 02:16:51,049 tip about infinite loops. There's one more\n 1601 02:16:51,049 --> 02:16:54,558 And it's a different type of while loops,\n 1602 02:16:54,558 --> 02:16:58,840 But before I show you that, I just want to\n 1603 02:16:58,840 --> 02:17:06,549 int index equal to six, when I run my program,\n 1604 02:17:06,549 --> 02:17:11,388 going to execute. And that's because before\n 1605 02:17:11,388 --> 02:17:17,179 this condition first. So before I'm allowed\n 1606 02:17:17,179 --> 02:17:20,909 up here in these parentheses. So I check to\n 1607 02:17:20,909 --> 02:17:24,718 since index is starting out at six. We're\n 1608 02:17:24,718 --> 02:17:30,218 So if I ran my program, you guys will see\n 1609 02:17:30,218 --> 02:17:34,260 do anything. But there's another type of loop,\n 1610 02:17:34,261 --> 02:17:38,000 to show you guys how we can make one, I'm\n 1611 02:17:38,000 --> 02:17:43,019 it down here. And I need to include a semi\n 1612 02:17:43,019 --> 02:17:47,530 to be I'm just gonna say do and this is what's\n 1613 02:17:47,530 --> 02:17:52,340 essentially just a normal while loop, but\n 1614 02:17:52,340 --> 02:17:57,540 condition, and then executing the code, we're\n 1615 02:17:57,540 --> 02:18:01,980 going to check the condition. So it's just\n 1616 02:18:01,979 --> 02:18:07,789 even though index is equal to six, I'm still\n 1617 02:18:07,790 --> 02:18:11,189 then we're going to check the condition and\n 1618 02:18:11,189 --> 02:18:15,250 me show you guys what happens when I run this.\n 1619 02:18:15,250 --> 02:18:20,659 out that six. That's because with the do while\n 1620 02:18:20,659 --> 02:18:25,429 you check the condition. And there's a bunch\n 1621 02:18:25,429 --> 02:18:29,829 while loops or do while loops. And to be honest\n 1622 02:18:29,829 --> 02:18:36,269 do while loop you can do with a normal while\n 1623 02:18:36,269 --> 02:18:41,130 But in a lot of circumstances, they are useful.\n 1624 02:18:41,129 --> 02:18:44,659 B I mean, that's a basic overview of loops.\n 1625 02:18:44,659 --> 02:18:49,129 we can talk about in a future tutorial called\n 1626 02:18:49,129 --> 02:18:56,739 with these wild loops, you can kind of see\n 1627 02:18:56,739 --> 02:19:01,369 going to show you how to build a little guessing\n 1628 02:19:01,370 --> 02:19:04,010 because we're actually going to be able to\n 1629 02:19:04,010 --> 02:19:08,460 up to this point in the course. So we'll use\n 1630 02:19:08,459 --> 02:19:14,239 use variables, we use all sorts of stuff in\n 1631 02:19:14,239 --> 02:19:19,909 how this is going to go is the user is going\n 1632 02:19:19,909 --> 02:19:24,299 I'm gonna have a secret number stored here\n 1633 02:19:24,299 --> 02:19:28,600 to try and guess what that number is. So the\n 1634 02:19:28,601 --> 02:19:33,319 as you'll see in a second, it's actually pretty\n 1635 02:19:33,319 --> 02:19:37,949 here's the one caveat is if the user doesn't\n 1636 02:19:37,950 --> 02:19:42,229 to keep asking them keep prompting them to\n 1637 02:19:42,228 --> 02:19:47,468 you guys how we can do this. So the first\n 1638 02:19:47,468 --> 02:19:51,978 So I'm just going to make an integer and I'm\n 1639 02:19:51,978 --> 02:19:56,329 going to set this equal to I don't know, let's\n 1640 02:19:56,329 --> 02:20:00,110 number. And then the next thing I want to\n 1641 02:20:00,110 --> 02:20:05,350 call guests, and we're not going to give guests\n 1642 02:20:05,350 --> 02:20:09,930 secret number, and we have our guests. And\n 1643 02:20:09,930 --> 02:20:14,829 to guess what the secret number is until they\n 1644 02:20:14,829 --> 02:20:19,299 to be done continually, that's usually a good\n 1645 02:20:19,299 --> 02:20:23,259 I'm going to go ahead and say, while when\n 1646 02:20:23,260 --> 02:20:27,360 gonna make an open and close curly bracket.\n 1647 02:20:27,360 --> 02:20:32,390 ask the user to enter in the number until\n 1648 02:20:32,389 --> 02:20:38,949 is specify a condition. In other words, I\n 1649 02:20:38,950 --> 02:20:44,700 not equal to the guests. So as long as the\n 1650 02:20:44,700 --> 02:20:49,200 other words, as long as the user hasn't guessed\n 1651 02:20:49,200 --> 02:20:55,150 loop. Now, every time through the loop, I\n 1652 02:20:55,149 --> 02:21:01,189 So I'm just going to say C out. And we'll\n 1653 02:21:01,189 --> 02:21:06,079 going to enter the number that they want to\n 1654 02:21:06,079 --> 02:21:11,001 to get that answer, we want to store it in\n 1655 02:21:11,001 --> 02:21:15,210 greater than signs. And I'm just gonna put\n 1656 02:21:15,209 --> 02:21:20,270 see is that we want to take whatever the user\n 1657 02:21:20,271 --> 02:21:23,920 every time we go through this loop, the user\n 1658 02:21:23,920 --> 02:21:29,021 to check their guests against the secret num.\n 1659 02:21:29,021 --> 02:21:33,110 just break out of the loop. So down here,\n 1660 02:21:33,110 --> 02:21:39,550 means they got the guest right, so I can just\n 1661 02:21:39,549 --> 02:21:43,938 message. Alright, so this is essentially all\n 1662 02:21:43,939 --> 02:21:47,771 going to go ahead and run this program, and\n 1663 02:21:47,771 --> 02:21:50,950 enter guests, so I'm just going to enter in\n 1664 02:21:50,950 --> 02:21:55,850 a three, that wasn't the secret number, so\n 1665 02:21:55,850 --> 02:22:00,750 And no matter how many times I guess, it's\n 1666 02:22:00,750 --> 02:22:05,350 it right. Now let's try to get the guests\n 1667 02:22:05,350 --> 02:22:10,739 when I enter a seven in now, all the sudden\n 1668 02:22:10,739 --> 02:22:16,209 is going to be false. So the secret num is\n 1669 02:22:16,209 --> 02:22:20,089 we'll break out of the while loop. And it's\n 1670 02:22:20,090 --> 02:22:25,139 how we can build our little guessing game.\n 1671 02:22:25,139 --> 02:22:30,629 using a while loop, right. But there's actually\n 1672 02:22:30,629 --> 02:22:35,319 do while loop. So your homework for this tutorial\n 1673 02:22:35,319 --> 02:22:40,159 a do while loop instead of just a normal while\n 1674 02:22:40,159 --> 02:22:44,110 actually a pretty fun game, and it works out\n 1675 02:22:44,110 --> 02:22:48,300 But the game is a little bit unfair. It's\n 1676 02:22:48,299 --> 02:22:53,670 unlimited guesses. So they can guess as many\n 1677 02:22:53,670 --> 02:22:59,680 seem fair. So what we could do is we can impose\n 1678 02:22:59,680 --> 02:23:03,889 hey, the user is only able to guess like three\n 1679 02:23:03,889 --> 02:23:07,709 So I'm going to go ahead and show you guys\n 1680 02:23:07,709 --> 02:23:12,069 that, we're going to need to add in a couple\n 1681 02:23:12,069 --> 02:23:17,159 to add in is going to be called guest count.\n 1682 02:23:17,159 --> 02:23:22,939 to keep track of how many times the user has\n 1683 02:23:22,939 --> 02:23:27,950 time the user guesses the secret number, we\n 1684 02:23:27,950 --> 02:23:33,350 actually going to set this equal to zero initially,\n 1685 02:23:33,350 --> 02:23:38,700 then down here, every time the user guesses,\n 1686 02:23:38,700 --> 02:23:44,180 I'm just gonna say, guest count, plus plus.\n 1687 02:23:44,180 --> 02:23:49,389 of how many times the user has tried to guess\n 1688 02:23:49,389 --> 02:23:55,529 make another variable over here. And I basically\n 1689 02:23:55,530 --> 02:24:01,689 limit is going to specify how many times the\n 1690 02:24:01,689 --> 02:24:05,540 why don't we set this equal to 30. So we'll\n 1691 02:24:05,540 --> 02:24:09,351 can't get the word and three guesses, then\n 1692 02:24:09,351 --> 02:24:13,271 then one more thing, we want to create another\n 1693 02:24:13,271 --> 02:24:20,500 and this is going to be called out of guesses.\n 1694 02:24:20,500 --> 02:24:24,829 So out of guesses will tell us whether or\n 1695 02:24:24,829 --> 02:24:29,539 of guesses is false. That means the user has\n 1696 02:24:29,540 --> 02:24:34,070 of guesses. If it's true, it means they don't\n 1697 02:24:34,069 --> 02:24:38,719 of guesses. Alright, so now that we have these\n 1698 02:24:38,719 --> 02:24:43,109 can modify this a while loop. So down here,\n 1699 02:24:43,110 --> 02:24:46,650 you'll see that we're letting the user guessed\n 1700 02:24:46,649 --> 02:24:51,189 user doesn't have any guesses left, then we\n 1701 02:24:51,189 --> 02:24:54,970 Right? In other words, if they've reached\n 1702 02:24:54,970 --> 02:25:00,020 another guess. So what I can do here is I\n 1703 02:25:00,021 --> 02:25:07,390 I'm going to say is if guest count is less\n 1704 02:25:07,389 --> 02:25:12,119 less than the guest limit, then I'm going\n 1705 02:25:12,120 --> 02:25:16,430 condition is true up here, that means that\n 1706 02:25:16,430 --> 02:25:21,220 They haven't reached the guests limit. So\n 1707 02:25:21,220 --> 02:25:26,469 increment the guest count, etc. Otherwise,\n 1708 02:25:26,469 --> 02:25:31,109 the guest limit, that means that they ran\n 1709 02:25:31,110 --> 02:25:37,930 is I want to toggle this Boolean. So basically,\n 1710 02:25:37,930 --> 02:25:43,760 So I'm telling my program that they ran out\n 1711 02:25:43,760 --> 02:25:48,069 equal to true now, we're basically done inside\n 1712 02:25:48,069 --> 02:25:53,250 go through, we're checking to see if they\n 1713 02:25:53,250 --> 02:25:58,180 let them guess. Otherwise, we tell our program\n 1714 02:25:58,180 --> 02:26:02,030 thing that we have to do to this while loop\n 1715 02:26:02,030 --> 02:26:07,340 in this while loop condition, we can use this\n 1716 02:26:07,340 --> 02:26:12,420 me to put two conditions inside of there.\n 1717 02:26:12,420 --> 02:26:17,000 to guests, and we can check another condition.\n 1718 02:26:17,000 --> 02:26:23,220 see if they're out of guesses. So I want to\n 1719 02:26:23,220 --> 02:26:26,978 to check to see if they're not out of guesses.\n 1720 02:26:26,978 --> 02:26:31,959 they haven't guessed the secret word. And\n 1721 02:26:31,959 --> 02:26:35,899 those becomes false, so if they run out of\n 1722 02:26:35,899 --> 02:26:39,359 then we're going to break out of the loop.\n 1723 02:26:39,360 --> 02:26:44,810 Alright, so one more thing down here below\n 1724 02:26:44,810 --> 02:26:50,319 just printing out you win. But this isn't\n 1725 02:26:50,319 --> 02:26:55,079 out of guesses, then they're going to break\n 1726 02:26:55,079 --> 02:26:58,069 shouldn't tell them that they won, we should\n 1727 02:26:58,069 --> 02:27:04,340 to do is make another if statement. And I'm\n 1728 02:27:04,340 --> 02:27:13,700 if out of guesses is equal to true, then I\n 1729 02:27:13,700 --> 02:27:20,500 And otherwise, if it's not equal to true in\n 1730 02:27:20,500 --> 02:27:25,229 means that they want so that means they guess\n 1731 02:27:25,229 --> 02:27:29,969 and run this program. And we'll see how we\n 1732 02:27:29,969 --> 02:27:34,010 a guest. So why don't we try to lose the game.\n 1733 02:27:34,010 --> 02:27:38,661 So this is our last guest. If we don't get\n 1734 02:27:38,661 --> 02:27:43,620 you lose, right? So we lost the game. Alright,\n 1735 02:27:43,620 --> 02:27:48,430 of being able to guess infinite times, we\n 1736 02:27:48,430 --> 02:27:54,440 can win the game now. So we're gonna guess\n 1737 02:27:54,440 --> 02:28:00,310 guests, I'm gonna say seven. And when I enter\n 1738 02:28:00,310 --> 02:28:05,829 win the game, as well. So this is sort of\n 1739 02:28:05,829 --> 02:28:09,840 structures together. So you'll see down here,\n 1740 02:28:09,840 --> 02:28:15,180 not only did I use all these variables, but\n 1741 02:28:15,180 --> 02:28:19,851 all that stuff. And really, this is what real\n 1742 02:28:19,851 --> 02:28:23,530 it's not just going to be like little simple\n 1743 02:28:23,530 --> 02:28:28,610 just like this. Not that this is messy code.\n 1744 02:28:28,610 --> 02:28:32,710 different programming structures in combination.\n 1745 02:28:32,709 --> 02:28:38,039 you guys, which is the way that I wrote this\n 1746 02:28:38,040 --> 02:28:42,660 we could have written this like a dozen different\n 1747 02:28:42,659 --> 02:28:46,409 And you know, I can think of like at least\n 1748 02:28:46,409 --> 02:28:50,879 done this. And this is another lesson in programming\n 1749 02:28:50,879 --> 02:28:55,359 five or six different ways to do the same\n 1750 02:28:55,360 --> 02:28:59,420 while loop, I could have used different things\n 1751 02:28:59,420 --> 02:29:02,950 something else. And so that's one of the cool\n 1752 02:29:02,950 --> 02:29:08,351 in and trying different ways to do the same\n 1753 02:29:08,351 --> 02:29:11,810 this guessing game. Hopefully, you guys learned\n 1754 02:29:11,810 --> 02:29:21,159 structures like ifs and Wiles, and variables\n 1755 02:29:21,159 --> 02:29:26,899 tutorial, I want to talk to you guys about\n 1756 02:29:26,899 --> 02:29:32,569 type of loop, which actually allows us to\n 1757 02:29:32,569 --> 02:29:37,719 the loop. So in a for loop, we can use something\n 1758 02:29:37,719 --> 02:29:41,840 indexing variable will allow us to keep track\n 1759 02:29:41,840 --> 02:29:45,390 And you can also use the indexing variable\n 1760 02:29:45,390 --> 02:29:49,420 to show you guys how for loops work, we're\n 1761 02:29:49,420 --> 02:29:53,790 what situations you're going to want to use\n 1762 02:29:53,790 --> 02:29:58,330 this basic program set up and essentially\n 1763 02:29:58,329 --> 02:30:04,250 this a integer called index and I just set\n 1764 02:30:04,250 --> 02:30:08,739 than or equal to five, I'm just printing out\n 1765 02:30:08,739 --> 02:30:12,100 it. So I'm gonna go ahead and run this program,\n 1766 02:30:12,100 --> 02:30:17,290 So you'll see, we're basically just printing\n 1767 02:30:17,290 --> 02:30:20,450 And if you've been following along with this\n 1768 02:30:20,450 --> 02:30:25,680 familiar with what while loops do at this\n 1769 02:30:25,680 --> 02:30:32,710 things. So this while loop is special, because\n 1770 02:30:32,709 --> 02:30:38,649 index tells us what iteration of the loop\n 1771 02:30:38,649 --> 02:30:44,279 see over here, like the first time we go through\n 1772 02:30:44,280 --> 02:30:49,210 has the value one, the second time we go through\n 1773 02:30:49,209 --> 02:30:54,728 has the value of three, etc. Right? So this\n 1774 02:30:54,728 --> 02:30:59,619 iteration of the loop we're currently on.\n 1775 02:30:59,620 --> 02:31:04,180 of the loop, the value inside of this index\n 1776 02:31:04,180 --> 02:31:08,550 it's incrementing, by one, but the point is,\n 1777 02:31:08,549 --> 02:31:12,609 variable, and it's essentially just keeping\n 1778 02:31:12,610 --> 02:31:18,560 the loop. Now, in c++, and in just about every\n 1779 02:31:18,559 --> 02:31:24,329 very powerful looping structure. In other\n 1780 02:31:24,329 --> 02:31:29,000 track of you know how many times we've gone\n 1781 02:31:29,000 --> 02:31:33,340 that's going to change every time we go through\n 1782 02:31:33,340 --> 02:31:39,260 is such a useful situation, that there's actually\n 1783 02:31:39,260 --> 02:31:44,450 So there's a special type of loop whose sole\n 1784 02:31:44,450 --> 02:31:49,560 very similar to this, where we have this indexing\n 1785 02:31:49,559 --> 02:31:53,640 we go through the loop. And in a lot of circumstances,\n 1786 02:31:53,640 --> 02:31:56,369 of the loop we're currently on. And that's\n 1787 02:31:56,370 --> 02:32:01,751 guys how we can build a for loop. And essentially\n 1788 02:32:01,751 --> 02:32:06,969 we have up here, it's just going to be a lot\n 1789 02:32:06,969 --> 02:32:11,438 So it's great if we're live, we can just say\n 1790 02:32:11,439 --> 02:32:16,000 open and close curly bracket. So so far, it\n 1791 02:32:16,000 --> 02:32:22,040 one difference with the for loop is instead\n 1792 02:32:22,040 --> 02:32:26,130 So in this while loop, we just have our looping\n 1793 02:32:26,129 --> 02:32:30,879 like a loop guard. Down here in this for loop\n 1794 02:32:30,879 --> 02:32:36,599 three different things that we want to include.\n 1795 02:32:36,600 --> 02:32:42,559 of this for loop parentheses is a variable\n 1796 02:32:42,559 --> 02:32:47,359 here, you'll notice that I'm creating this\n 1797 02:32:47,360 --> 02:32:52,819 it a value of one. So I'm declaring the variable\n 1798 02:32:52,819 --> 02:32:58,549 I'm initializing the variable. inside of this\n 1799 02:32:58,549 --> 02:33:03,270 So I could actually just copy this line, and\n 1800 02:33:03,271 --> 02:33:07,329 And instead of calling it index, why don't\n 1801 02:33:07,329 --> 02:33:11,700 index, we'll set it equal to one, then you'll\n 1802 02:33:11,700 --> 02:33:17,280 put this semi colon, we can actually put another\n 1803 02:33:17,280 --> 02:33:21,460 wild looping structure is our loop guard,\n 1804 02:33:21,459 --> 02:33:26,478 telling us when we should loop so if this\n 1805 02:33:26,478 --> 02:33:30,649 keep looping. So that's the next thing that\n 1806 02:33:30,649 --> 02:33:36,250 So we're putting this variable declaration\n 1807 02:33:36,250 --> 02:33:40,709 also going to put the looping condition. So\n 1808 02:33:40,709 --> 02:33:45,459 stop and when it should go. Alright, so then\n 1809 02:33:45,459 --> 02:33:49,719 here. So you'll notice I have a semicolon\n 1810 02:33:49,719 --> 02:33:55,399 have another semicolon here, after we specify\n 1811 02:33:55,399 --> 02:34:02,209 do is put in a line of code that's going to\n 1812 02:34:02,209 --> 02:34:06,000 Up here in this while loop, you'll notice\n 1813 02:34:06,000 --> 02:34:11,290 index plus plus, this line of code is going\n 1814 02:34:11,290 --> 02:34:15,240 loop iteration. So the last thing that we're\n 1815 02:34:15,239 --> 02:34:19,521 loop is increment the index variable, right.\n 1816 02:34:19,521 --> 02:34:23,760 put over here, we're going to put a line of\n 1817 02:34:23,760 --> 02:34:29,309 every iteration of this loop. And in our case,\n 1818 02:34:29,309 --> 02:34:35,420 i so I'm just going to say i plus plus, we're\n 1819 02:34:35,420 --> 02:34:39,700 any line of code here that I want, I mean,\n 1820 02:34:39,700 --> 02:34:44,820 you know, basically whatever I want, but in\n 1821 02:34:44,819 --> 02:34:51,360 just like we did up here with index. So now\n 1822 02:34:51,360 --> 02:34:56,200 open and close curly brackets, we can just\n 1823 02:34:56,200 --> 02:35:01,409 of the loop. So that's going to be this line\n 1824 02:35:01,409 --> 02:35:08,200 guy in right here. And now we have a completed\n 1825 02:35:08,200 --> 02:35:15,050 down here is actually equivalent to this loop\n 1826 02:35:15,049 --> 02:35:20,619 of code, whereas this only takes two lines\n 1827 02:35:20,620 --> 02:35:25,110 scenario where we want to have a variable\n 1828 02:35:25,110 --> 02:35:29,181 changing every time we go through the loop\n 1829 02:35:29,181 --> 02:35:34,190 the current loop iteration, such a common\n 1830 02:35:34,190 --> 02:35:38,020 a for loop for that. And the for loop, the\n 1831 02:35:38,020 --> 02:35:42,540 like I did up there. So I'm initializing this\n 1832 02:35:42,540 --> 02:35:47,610 the looping guard the looping conditions,\n 1833 02:35:47,610 --> 02:35:51,550 a line of code that's going to get executed\n 1834 02:35:51,549 --> 02:35:56,459 going to be this i plus plus. And you'll notice\n 1835 02:35:56,459 --> 02:36:00,500 And you'll notice also that I don't need a\n 1836 02:36:00,500 --> 02:36:04,090 rid of this while loop. And I'm going to go\n 1837 02:36:04,090 --> 02:36:08,390 we run the for loop. And actually, I need\n 1838 02:36:08,390 --> 02:36:12,719 being index, I'm just gonna leave it as i\n 1839 02:36:12,719 --> 02:36:18,329 int is equal to one, we're going to keep looping\n 1840 02:36:18,329 --> 02:36:22,309 And then at the end, we're just going to increment\n 1841 02:36:22,309 --> 02:36:27,199 time through the loop, we are printing out,\n 1842 02:36:27,200 --> 02:36:31,360 you'll see we get the same exact output as\n 1843 02:36:31,360 --> 02:36:38,200 just 12345. So what's cool about these four\n 1844 02:36:38,200 --> 02:36:42,409 of a value every time we go through. And in\n 1845 02:36:42,409 --> 02:36:46,049 of how many times we've gone through the loop,\n 1846 02:36:46,049 --> 02:36:51,829 for loops to actually iterate through the\n 1847 02:36:51,829 --> 02:36:56,228 an array of integers, so we'll just call it\n 1848 02:36:56,228 --> 02:37:04,099 an initial value. So why don't we just say\n 1849 02:37:04,100 --> 02:37:08,761 it just has a bunch of numbers in it. And\n 1850 02:37:08,761 --> 02:37:13,911 to access a specific element inside of this\n 1851 02:37:13,911 --> 02:37:18,399 put the index in here. So if I said num zero,\n 1852 02:37:18,399 --> 02:37:24,190 if I said nums, four, it's going to give us\n 1853 02:37:24,191 --> 02:37:30,140 to this three, what I can actually do is I\n 1854 02:37:30,139 --> 02:37:36,420 to actually loop through and print out all\n 1855 02:37:36,420 --> 02:37:42,049 start at zero, so I'm going to start this\n 1856 02:37:42,049 --> 02:37:48,720 do is I'm basically going to say i is less\n 1857 02:37:48,720 --> 02:37:55,478 array. So inside of this array, we have 12345\n 1858 02:37:55,478 --> 02:38:00,130 than five, we want to keep looping and then\n 1859 02:38:00,130 --> 02:38:05,809 here, instead of printing out, I could actually\n 1860 02:38:05,809 --> 02:38:11,470 to do is on the first iteration of the loop,\n 1861 02:38:11,470 --> 02:38:15,809 second iteration of the loop, it's going to\n 1862 02:38:15,809 --> 02:38:20,449 of the loop, it's going to print out nums,\n 1863 02:38:20,450 --> 02:38:25,840 way up to number four, which as we saw is\n 1864 02:38:25,840 --> 02:38:31,090 be the last element in the array. So we can\n 1865 02:38:31,090 --> 02:38:35,760 all the elements in the nums array. So let's\n 1866 02:38:35,760 --> 02:38:42,250 here, we're printing out all the elements.\n 1867 02:38:42,250 --> 02:38:47,549 very common situation, we can use for loops\n 1868 02:38:47,549 --> 02:38:52,799 array. And it can be really useful. So play\n 1869 02:38:52,799 --> 02:38:56,319 useful. And one more time, I just want to\n 1870 02:38:56,319 --> 02:39:01,420 we're doing over here is we're creating a\n 1871 02:39:01,420 --> 02:39:07,409 so I'm saying int is equal to zero. And then\n 1872 02:39:07,409 --> 02:39:11,869 condition, I'm saying we're gonna keep looping\n 1873 02:39:11,870 --> 02:39:16,360 is a line of code that will get run after\n 1874 02:39:16,360 --> 02:39:19,989 we go through this loop, we'll come up here,\n 1875 02:39:19,989 --> 02:39:24,010 the condition. Again, that is the basics of\n 1876 02:39:24,010 --> 02:39:28,399 would say this is almost even more widely\n 1877 02:39:28,399 --> 02:39:36,109 So you definitely want to practice and play\n 1878 02:39:36,110 --> 02:39:42,140 I'm gonna show you guys how to build an exponent\n 1879 02:39:42,139 --> 02:39:47,760 a function that will take a number to a specific\n 1880 02:39:47,760 --> 02:39:52,620 could pass in two numbers, like if I passed\n 1881 02:39:52,620 --> 02:39:57,550 me back three race to the fourth power. So\n 1882 02:39:57,549 --> 02:40:02,000 and we'll actually get a chance to use four\n 1883 02:40:02,000 --> 02:40:06,569 build this function, that's going to be pretty\n 1884 02:40:06,569 --> 02:40:12,010 exponent function. So we're going to have\n 1885 02:40:12,010 --> 02:40:17,390 int. And why don't we just call this power\n 1886 02:40:17,390 --> 02:40:22,139 power, and make an open and close parentheses\n 1887 02:40:22,139 --> 02:40:27,250 power function is going to take two arguments.\n 1888 02:40:27,250 --> 02:40:32,159 going to take a power number. And we're basically\n 1889 02:40:32,159 --> 02:40:38,909 of the power number. So I'm just going to\n 1890 02:40:38,909 --> 02:40:44,739 here in our power function, we need to figure\n 1891 02:40:44,739 --> 02:40:50,430 to take bass num to power num. And we can\n 1892 02:40:50,430 --> 02:40:54,220 do that. So the first thing I want to do is\n 1893 02:40:54,219 --> 02:40:59,269 to call it result. And I'm just going to set\n 1894 02:40:59,270 --> 02:41:05,670 basically just going to return results. So\n 1895 02:41:05,670 --> 02:41:11,250 is to get rid the result variable equal to\n 1896 02:41:11,250 --> 02:41:16,360 number, right, that's kind of our goal. Throughout\n 1897 02:41:16,360 --> 02:41:19,641 of simplicity, and the purposes just for this\n 1898 02:41:19,640 --> 02:41:24,529 to handle positive number exponents. So we're\n 1899 02:41:24,530 --> 02:41:28,630 is going to be positive. And now let's just\n 1900 02:41:28,629 --> 02:41:32,299 to drive home the point a little bit better,\n 1901 02:41:32,299 --> 02:41:37,220 I'm going to go ahead and write out this for\n 1902 02:41:37,220 --> 02:41:41,779 to specify three things, the first thing I\n 1903 02:41:41,780 --> 02:41:47,030 gonna say int i is equal to zero, I'll start\n 1904 02:41:47,030 --> 02:41:54,170 specify a looping a condition or a loop guard.\n 1905 02:41:54,170 --> 02:41:59,450 less than the power num. Essentially, what\n 1906 02:41:59,450 --> 02:42:04,909 loop power num times. So as many times as\n 1907 02:42:04,909 --> 02:42:09,389 this loop. So if power num is three, I want\n 1908 02:42:09,389 --> 02:42:13,969 I want to loop through five times. That's\n 1909 02:42:13,969 --> 02:42:18,559 here, we can just specify something that we\n 1910 02:42:18,559 --> 02:42:23,049 So I'm just gonna say i plus plus. And basically\n 1911 02:42:23,049 --> 02:42:27,641 every time we go through the loop. Alright,\n 1912 02:42:27,641 --> 02:42:31,639 to think about what we can do. So where are\n 1913 02:42:31,639 --> 02:42:38,379 through here, power num times, right? So what\n 1914 02:42:38,379 --> 02:42:43,659 result times the base num, every time we go\n 1915 02:42:43,659 --> 02:42:51,959 is result is equal to result times base num.\n 1916 02:42:51,959 --> 02:42:57,989 is because let's just kind of break this down,\n 1917 02:42:57,989 --> 02:43:00,931 result is going to be equal to one. So the\n 1918 02:43:00,931 --> 02:43:05,770 multiplying base num by one, so we just get\n 1919 02:43:05,770 --> 02:43:11,021 loop result is equal to based on right, in\n 1920 02:43:11,021 --> 02:43:15,310 num. So the second time we go through, we're\n 1921 02:43:15,309 --> 02:43:20,680 on based on squared, right, the third time\n 1922 02:43:20,680 --> 02:43:27,130 of base num squared. So for molting multiplying\n 1923 02:43:27,129 --> 02:43:32,728 us base num cubed. So that's kind of why this\n 1924 02:43:32,728 --> 02:43:37,429 through this for loop power num times. And\n 1925 02:43:37,430 --> 02:43:43,300 result times the base num. And you can see\n 1926 02:43:43,299 --> 02:43:47,969 us to only loop through the loop a specified\n 1927 02:43:47,969 --> 02:43:53,319 easy for us to only loop through, you know,\n 1928 02:43:53,319 --> 02:43:57,699 is the basic function. And this looks pretty\n 1929 02:43:57,700 --> 02:44:02,530 this is only going to be able to handle positive\n 1930 02:44:02,530 --> 02:44:07,909 nums. Okay, so let's go ahead and call this.\n 1931 02:44:07,909 --> 02:44:14,239 we print out the result. So I'm going to see\n 1932 02:44:14,239 --> 02:44:19,629 So why don't we pass in two, and three, so\n 1933 02:44:19,629 --> 02:44:24,300 So now let's run this function. And you'll\n 1934 02:44:24,300 --> 02:44:29,199 Two times two is four, four times two is eight.\n 1935 02:44:29,200 --> 02:44:36,760 squared. So now we should get 16. And you\n 1936 02:44:36,760 --> 02:44:41,889 like our little function is working. And basically\n 1937 02:44:41,889 --> 02:44:46,279 of demonstrate to you another way that we\n 1938 02:44:46,280 --> 02:44:50,851 for loop in order to essentially specify how\n 1939 02:44:50,851 --> 02:44:55,270 And four leaves are really useful for that\n 1940 02:44:55,270 --> 02:44:59,521 representing how many times we've gone through\n 1941 02:44:59,521 --> 02:45:04,399 loop I can tell us that we've gone through\n 1942 02:45:04,398 --> 02:45:08,228 is useful. And so you can see, it's actually\n 1943 02:45:08,228 --> 02:45:14,579 takes up like two lines of code. So that's\n 1944 02:45:14,579 --> 02:45:18,690 function. And actually, this is kind of useful,\n 1945 02:45:18,690 --> 02:45:26,090 like this might get put together. In this\n 1946 02:45:26,090 --> 02:45:30,950 two separate subjects in c++, the first subject\n 1947 02:45:30,950 --> 02:45:35,891 two dimensional arrays. And a two dimensional\n 1948 02:45:35,890 --> 02:45:42,180 where every single element inside the array\n 1949 02:45:42,180 --> 02:45:46,470 situation. And I want to talk to you guys\n 1950 02:45:46,469 --> 02:45:52,519 loops. And a nested for loop is a situation\n 1951 02:45:52,520 --> 02:45:56,860 for loop. So this is gonna be kind of cool.\n 1952 02:45:56,860 --> 02:46:01,120 subjects together two dimensional arrays,\n 1953 02:46:01,120 --> 02:46:05,450 of a cool program. So I'm gonna show you guys\n 1954 02:46:05,450 --> 02:46:09,450 I want to show you is a two dimensional array.\n 1955 02:46:09,450 --> 02:46:14,350 of numbers. And I'm just going to call it\n 1956 02:46:14,350 --> 02:46:18,760 a regular array, we're just going to make\n 1957 02:46:18,760 --> 02:46:22,728 we're making a two dimensional array, I want\n 1958 02:46:22,728 --> 02:46:28,409 after this. Now remember, a two dimensional\n 1959 02:46:28,409 --> 02:46:33,181 where every element inside of the array is\n 1960 02:46:33,181 --> 02:46:37,770 how we can go ahead and set something like\n 1961 02:46:37,770 --> 02:46:41,819 value. So I'm just gonna initialize this.\n 1962 02:46:41,819 --> 02:46:46,969 of array elements inside of here. So the first\n 1963 02:46:46,969 --> 02:46:50,889 element in the array. Now normally, if I was\n 1964 02:46:50,889 --> 02:46:54,869 out elements like this, right? You know, I\n 1965 02:46:54,870 --> 02:47:00,840 a comma, and then we have our array. But with\n 1966 02:47:00,840 --> 02:47:06,090 element is actually another array. So if I\n 1967 02:47:06,090 --> 02:47:11,530 two dimensional array, I can basically go\n 1968 02:47:11,530 --> 02:47:16,430 of mini array inside of here. And I'm actually\n 1969 02:47:16,430 --> 02:47:21,430 so now the first element in this number grid\n 1970 02:47:21,430 --> 02:47:29,210 one and two. So number grid, first element\n 1971 02:47:29,209 --> 02:47:33,629 of its own. So I'm going to copy this, and\n 1972 02:47:33,629 --> 02:47:37,579 going to put a comma here, because remember,\n 1973 02:47:37,579 --> 02:47:43,351 elements. And then down here, I'm just going\n 1974 02:47:43,351 --> 02:47:53,190 four. So we have 1234. And why don't we do\n 1975 02:47:53,190 --> 02:47:58,221 so essentially, what's happening here is we\n 1976 02:47:58,220 --> 02:48:02,949 curly brackets represent the number grid array.\n 1977 02:48:02,950 --> 02:48:07,439 three elements. So this is the first element,\n 1978 02:48:07,439 --> 02:48:15,310 third element, all of which are arrays. And\n 1979 02:48:15,310 --> 02:48:19,100 inside of them. So whenever we're creating\n 1980 02:48:19,100 --> 02:48:25,229 specify the numbers over here. So inside of\n 1981 02:48:25,229 --> 02:48:31,139 we want to tell c++, how many total elements\n 1982 02:48:31,139 --> 02:48:38,039 we have three, because again, there's 123\n 1983 02:48:38,040 --> 02:48:45,351 how many elements are inside of each array\n 1984 02:48:45,351 --> 02:48:51,960 etc. So there's going to be two elements in\n 1985 02:48:51,959 --> 02:48:56,769 especially when you're dealing with two dimensional\n 1986 02:48:56,770 --> 02:49:01,489 otherwise you can get really confused, you\n 1987 02:49:01,489 --> 02:49:07,209 the basic layout, like I know that this array\n 1988 02:49:07,209 --> 02:49:11,319 and then it has two columns. So these would\n 1989 02:49:11,319 --> 02:49:16,819 a matrix. Alright, so that is a two dimensional\n 1990 02:49:16,819 --> 02:49:21,299 access some of these elements. So if I want\n 1991 02:49:21,299 --> 02:49:26,050 just gonna go ahead and print some of these\n 1992 02:49:26,050 --> 02:49:30,819 and what I can do is I can make two open and\n 1993 02:49:30,819 --> 02:49:35,069 just like this. And inside of these open and\n 1994 02:49:35,069 --> 02:49:40,559 want to specify the row. In other words, I\n 1995 02:49:40,559 --> 02:49:45,139 grid that I want to access. So this would\n 1996 02:49:45,139 --> 02:49:49,159 be the element at position one, and this would\n 1997 02:49:49,159 --> 02:49:54,379 we want to access this element right here.\n 1998 02:49:54,379 --> 02:49:59,989 element zero. And then over here, I want to\n 1999 02:49:59,989 --> 02:50:06,860 array, so it's going to be an index position\n 2000 02:50:06,860 --> 02:50:12,980 overall element, and one is corresponding\n 2001 02:50:12,979 --> 02:50:17,369 so now when we print this out, we should get\n 2002 02:50:17,370 --> 02:50:22,470 two. Let's try one more, why don't we try\n 2003 02:50:22,469 --> 02:50:28,600 to be an element 012. So we're going to put\n 2004 02:50:28,601 --> 02:50:33,920 zero, so we're just going to put a zero and\n 2005 02:50:33,920 --> 02:50:38,579 Alright, so that kind of shows you a little\n 2006 02:50:38,579 --> 02:50:44,700 array. And actually, this same concept can\n 2007 02:50:44,700 --> 02:50:48,870 could have a three or four or five dimensional\n 2008 02:50:48,870 --> 02:50:53,600 to apply. Obviously, the more dimensions you\n 2009 02:50:53,600 --> 02:50:58,700 can get pretty complex with arrays, just by\n 2010 02:50:58,700 --> 02:51:02,659 thing I wanted to show you guys. And now I\n 2011 02:51:02,659 --> 02:51:07,969 a nested for loop. And nested for loop is\n 2012 02:51:07,969 --> 02:51:13,019 of another for loop. And actually nested for\n 2013 02:51:13,020 --> 02:51:19,210 can use them to print out all of the elements\n 2014 02:51:19,209 --> 02:51:23,029 we could iterate through all the elements\n 2015 02:51:23,030 --> 02:51:27,590 I'm going to show you guys how that's going\n 2016 02:51:27,590 --> 02:51:32,550 basic for loop. So I'm just gonna say for,\n 2017 02:51:32,550 --> 02:51:37,930 Again, our goal here is to be able to loop\n 2018 02:51:37,930 --> 02:51:42,090 And, you know, as I sort of create this for\n 2019 02:51:42,090 --> 02:51:47,989 this is all gonna make sense. But what I want\n 2020 02:51:47,989 --> 02:51:55,659 less than three. And I'm using three here,\n 2021 02:51:55,659 --> 02:52:00,450 all of these individual elements. So all of\n 2022 02:52:00,450 --> 02:52:06,470 and over here, I'm just gonna say i plus plus.\n 2023 02:52:06,469 --> 02:52:11,679 over all of these elements. So this first\n 2024 02:52:11,680 --> 02:52:17,350 element, but remember, each of these elements\n 2025 02:52:17,350 --> 02:52:23,260 for each of these arrays, I want to iterate\n 2026 02:52:23,260 --> 02:52:27,290 arrays. So I can create another for loop to\n 2027 02:52:27,290 --> 02:52:31,899 to call this J. And a lot of times when we're\n 2028 02:52:31,898 --> 02:52:36,099 ij, that's kind of a convention, I'm gonna\n 2029 02:52:36,100 --> 02:52:43,649 looping as long as j is less than two. And\n 2030 02:52:43,648 --> 02:52:48,539 each of these arrays, right? So this loop\n 2031 02:52:48,540 --> 02:52:53,590 all of these elements, and this one down here\n 2032 02:52:53,590 --> 02:52:58,680 these elements. So I'm gonna say j less than\n 2033 02:52:58,680 --> 02:53:04,540 So now we have our basic structure setup.\n 2034 02:53:04,540 --> 02:53:09,410 loop is going to fully iterate. So it's going\n 2035 02:53:09,409 --> 02:53:13,899 I'm just going to see out. And I'm basically\n 2036 02:53:13,899 --> 02:53:19,978 elements. So I'm going to print out number\n 2037 02:53:19,978 --> 02:53:24,189 basically how this is going to work. And then\n 2038 02:53:24,190 --> 02:53:29,420 out a new line. So I'm just going to say C\n 2039 02:53:29,420 --> 02:53:33,920 line. So let's go ahead and run this. And\n 2040 02:53:33,920 --> 02:53:38,030 as far as what it's doing. So when I run this,\n 2041 02:53:38,030 --> 02:53:47,489 out all of these elements. So we're printing\n 2042 02:53:47,489 --> 02:53:53,629 and iterate over every single element inside\n 2043 02:53:53,629 --> 02:53:58,380 what's happening is, every time we go through\n 2044 02:53:58,380 --> 02:54:04,549 fully iterating through the J loop. So this\n 2045 02:54:04,549 --> 02:54:09,849 individual element. So it's responsible for\n 2046 02:54:09,850 --> 02:54:14,809 j loop is responsible for iterating over each\n 2047 02:54:14,809 --> 02:54:18,799 which are arrays. So the J loop is going to\n 2048 02:54:18,799 --> 02:54:23,369 we go through this loop is going to be equal\n 2049 02:54:23,370 --> 02:54:27,310 So we're going to print this out, then we're\n 2050 02:54:27,309 --> 02:54:31,239 still going to be equal to zero, but j is\n 2051 02:54:31,239 --> 02:54:35,148 print this element out. And then AI is going\n 2052 02:54:35,148 --> 02:54:41,149 zero, we'll print this out and then it's going\n 2053 02:54:41,149 --> 02:54:46,140 that's essentially what's happening here.\n 2054 02:54:46,140 --> 02:54:50,859 loops, I mean, any sort of nested loop can\n 2055 02:54:50,860 --> 02:54:59,970 through like I said, complex structures like\n 2056 02:54:59,969 --> 02:55:06,019 By using comments in c++, or comments are\n 2057 02:55:06,020 --> 02:55:12,090 actually going to get executed or rendered\n 2058 02:55:12,090 --> 02:55:16,478 you're going to want to, you know, basically\n 2059 02:55:16,478 --> 02:55:21,260 So whenever we're writing programs, like whenever\n 2060 02:55:21,260 --> 02:55:24,610 instructions are meant for the computer. So\n 2061 02:55:24,610 --> 02:55:29,430 out, or I can tell the computer to loop over\n 2062 02:55:29,430 --> 02:55:33,689 a lot of times, we're going to want to write\n 2063 02:55:33,689 --> 02:55:38,950 for yourself or for someone else. And we can\n 2064 02:55:38,950 --> 02:55:41,750 And I'm gonna show you guys what comments\n 2065 02:55:41,750 --> 02:55:47,379 know, a little line of code or a block of\n 2066 02:55:47,379 --> 02:55:51,949 we can use it to write little messages for\n 2067 02:55:51,950 --> 02:55:55,640 in c++, there's actually a couple of ways\n 2068 02:55:55,639 --> 02:56:00,729 two forward slashes. So when I make two forward\n 2069 02:56:00,729 --> 02:56:05,409 all of this text is actually colored different\n 2070 02:56:05,409 --> 02:56:11,640 is a comment. So any text that I put after\n 2071 02:56:11,640 --> 02:56:16,569 a comment. And it's not actually going to\n 2072 02:56:16,569 --> 02:56:20,728 a bunch of nonsense up here, I can still run\n 2073 02:56:20,728 --> 02:56:24,709 to execute. So you'll see I can run the program.\n 2074 02:56:24,709 --> 02:56:29,649 out comments are fun. So this is a really\n 2075 02:56:29,649 --> 02:56:34,180 a lot of people will use this to write notes\n 2076 02:56:34,180 --> 02:56:38,689 developers. You can also use this to like\n 2077 02:56:38,689 --> 02:56:45,271 this line of code over here, I can say like,\n 2078 02:56:45,271 --> 02:56:49,271 you probably wouldn't need to describe this\n 2079 02:56:49,271 --> 02:56:53,671 or you know, complex loop or something like\n 2080 02:56:53,671 --> 02:56:58,550 also put these comments like after a line\n 2081 02:56:58,549 --> 02:57:03,260 it down here. And you'll see that everything\n 2082 02:57:03,261 --> 02:57:07,939 is going to be considered a comment. But I\n 2083 02:57:07,939 --> 02:57:13,130 can use this to like describe what the line\n 2084 02:57:13,129 --> 02:57:17,728 one downside to this type of comment, though,\n 2085 02:57:17,728 --> 02:57:21,840 So if I come down here to the new line, all\n 2086 02:57:21,840 --> 02:57:26,930 So this is no longer a comment. If you want\n 2087 02:57:26,930 --> 02:57:30,590 you can use something called an opening and\n 2088 02:57:30,590 --> 02:57:35,399 and an Asterix, then everything that comes\n 2089 02:57:35,399 --> 02:57:39,549 is going to be considered a comments, you\n 2090 02:57:39,549 --> 02:57:44,750 But I can close this off by saying an Asterix\n 2091 02:57:44,750 --> 02:57:50,010 that's in between these two tags is going\n 2092 02:57:50,010 --> 02:57:54,300 types of comments are very common. And you\n 2093 02:57:54,299 --> 02:57:58,090 to be correct. And it's going to work out.\n 2094 02:57:58,090 --> 02:58:02,510 types of comments and how you can use them.\n 2095 02:58:02,510 --> 02:58:08,290 commenting out lines of code. So a lot of\n 2096 02:58:08,290 --> 02:58:12,620 maybe you want to try to run your program\n 2097 02:58:12,620 --> 02:58:16,950 be running into a problem and you think a\n 2098 02:58:16,950 --> 02:58:21,079 one option would be to just remove the line\n 2099 02:58:21,079 --> 02:58:26,450 line of code was potentially like messing\n 2100 02:58:26,450 --> 02:58:32,220 program would act without that line of code.\n 2101 02:58:32,219 --> 02:58:36,379 and then run the program. And now we're running\n 2102 02:58:36,379 --> 02:58:41,100 problem with that, though, is I have to physically\n 2103 02:58:41,101 --> 02:58:45,329 though, I could just put a comment in front\n 2104 02:58:45,329 --> 02:58:51,030 get ignored by c++. So it's essentially the\n 2105 02:58:51,030 --> 02:58:56,220 have to physically remove it from the file,\n 2106 02:58:56,219 --> 02:59:00,959 it, we still know that it's there. It's just\n 2107 02:59:00,959 --> 02:59:06,419 useful way that comments can come in handy.\n 2108 02:59:06,420 --> 02:59:11,930 you definitely want to take advantage of them\n 2109 02:59:11,930 --> 02:59:20,250 In this tutorial, I want to talk to you guys\n 2110 02:59:20,250 --> 02:59:24,719 just a type of information that we can work\n 2111 02:59:24,719 --> 02:59:27,909 with this course up to this point, we've been\n 2112 02:59:27,909 --> 02:59:31,719 So we were working with things like integers,\n 2113 02:59:31,719 --> 02:59:35,709 with like doubles, which are decimal numbers\n 2114 02:59:35,709 --> 02:59:40,789 are like plain text. And this is where I want\n 2115 02:59:40,790 --> 02:59:45,680 we can deal with which are called pointers.\n 2116 02:59:45,680 --> 02:59:48,880 So we're going to have get into what that\n 2117 02:59:48,879 --> 02:59:53,569 talk about all that stuff. And I'll give you\n 2118 02:59:53,569 --> 02:59:57,379 here in my program, I have a few different\n 2119 02:59:57,379 --> 03:00:02,489 called age and I gave it you know, a value\n 2120 03:00:02,489 --> 03:00:07,489 Now all of these are variables in my program,\n 2121 03:00:07,489 --> 03:00:13,100 essentially just containers where I'm storing\n 2122 03:00:13,100 --> 03:00:18,809 I'm writing this program, I'm storing the\n 2123 03:00:18,809 --> 03:00:24,648 I'm storing 2.7 inside of this GPA variable.\n 2124 03:00:24,648 --> 03:00:30,019 the hood a little bit and talk about what's\n 2125 03:00:30,020 --> 03:00:34,441 you have something called your memory. And\n 2126 03:00:34,441 --> 03:00:38,280 might have heard people talk about ram stands\n 2127 03:00:38,280 --> 03:00:43,239 just the active memory that your computer's\n 2128 03:00:43,239 --> 03:00:49,129 your computer runs a program, it's using Ram.\n 2129 03:00:49,129 --> 03:00:54,629 memory, let's just say our program, for example.\n 2130 03:00:54,629 --> 03:00:59,929 run this program, my computer would actually\n 2131 03:00:59,930 --> 03:01:05,648 is going to use its memory in order to store\n 2132 03:01:05,648 --> 03:01:11,909 going to be storing all of these values inside\n 2133 03:01:11,909 --> 03:01:16,939 age, and I give it a value, what's actually\n 2134 03:01:16,939 --> 03:01:23,819 value 19. And it's going to store it inside\n 2135 03:01:23,819 --> 03:01:28,459 create this double GPA, my computer is going\n 2136 03:01:28,459 --> 03:01:33,919 it physically inside of the memory in my computer.\n 2137 03:01:33,920 --> 03:01:39,030 of these different pieces of data that are\n 2138 03:01:39,030 --> 03:01:43,790 memory of my computer, so when I write the\n 2139 03:01:43,790 --> 03:01:49,460 that 19 is stored inside the age variable.\n 2140 03:01:49,459 --> 03:01:54,739 stored in side of the computer's memory, so\n 2141 03:01:54,739 --> 03:01:58,439 one of the cool things about the memory of\n 2142 03:01:58,439 --> 03:02:02,409 containers, right, each one of these variables,\n 2143 03:02:02,409 --> 03:02:07,610 like inside of one of those containers, right?\n 2144 03:02:07,610 --> 03:02:13,069 but you can basically think of it as like\n 2145 03:02:13,069 --> 03:02:19,079 in memory, this value 2.7 is stored inside\n 2146 03:02:19,079 --> 03:02:24,478 containers inside the memory of my computer\n 2147 03:02:24,478 --> 03:02:30,909 So it has an address, which uniquely identifies\n 2148 03:02:30,909 --> 03:02:36,069 inside the physical memory of my computer,\n 2149 03:02:36,069 --> 03:02:40,989 This value 2.7 is stored in the memory of\n 2150 03:02:40,989 --> 03:02:46,920 memory address. And so when my program wants\n 2151 03:02:46,920 --> 03:02:51,489 using that memory address. When I want to\n 2152 03:02:51,489 --> 03:02:56,898 using like age or GPA. But when my computer\n 2153 03:02:56,898 --> 03:03:02,750 it using the physical memory address. So that's\n 2154 03:03:02,750 --> 03:03:07,351 show you guys how we can go ahead and access\n 2155 03:03:07,351 --> 03:03:14,159 print it out, I get to say C out. And if I\n 2156 03:03:14,159 --> 03:03:17,520 address where each of these variables are\n 2157 03:03:17,520 --> 03:03:22,450 the memory address where this value 19 is\n 2158 03:03:22,450 --> 03:03:27,680 where this value 2.7 is stored. All I have\n 2159 03:03:27,680 --> 03:03:32,450 can type in the name of a variable. So I could\n 2160 03:03:32,450 --> 03:03:37,329 is going to do is when I put this ampersand\n 2161 03:03:37,329 --> 03:03:42,680 I want to print out the memory address where\n 2162 03:03:42,680 --> 03:03:46,630 I want to print out the memory address where\n 2163 03:03:46,629 --> 03:03:52,469 my program, you'll notice over here that I'm\n 2164 03:03:52,469 --> 03:03:58,969 six, a FPS zero. This is a hexadecimal number,\n 2165 03:03:58,969 --> 03:04:03,340 will be very difficult for a human being to\n 2166 03:04:03,340 --> 03:04:09,329 it just fine. So if you were to go to this\n 2167 03:04:09,329 --> 03:04:14,549 you would find the value 19. I mean, that's\n 2168 03:04:14,549 --> 03:04:18,969 that's basically like where that value 19\n 2169 03:04:18,969 --> 03:04:24,289 wanted to access or change it or modify it,\n 2170 03:04:24,290 --> 03:04:29,450 that's essentially what we're talking about.\n 2171 03:04:29,450 --> 03:04:32,990 So we have like a special word that we use\n 2172 03:04:32,989 --> 03:04:38,049 a pointer. So generally, if I'm working in\n 2173 03:04:38,049 --> 03:04:43,039 I'm going to talk about pointers. So I would\n 2174 03:04:43,040 --> 03:04:47,730 here, we can say that I'm printing out a pointer.\n 2175 03:04:47,729 --> 03:04:52,228 It's just a memory address. So any memory\n 2176 03:04:52,228 --> 03:04:56,920 using inside of our programs is going to be\n 2177 03:04:56,920 --> 03:05:00,569 can access the pointer of these variables\n 2178 03:05:00,569 --> 03:05:06,360 memory addresses where these variables are\n 2179 03:05:06,360 --> 03:05:10,250 a little demonstration I want to show you\n 2180 03:05:10,250 --> 03:05:15,940 wrote out before the tutorial. And it's essentially\n 2181 03:05:15,940 --> 03:05:20,550 for all of these variables. So I'm going to\n 2182 03:05:20,549 --> 03:05:25,159 here, I'm essentially just printing out all\n 2183 03:05:25,159 --> 03:05:29,659 these variables. So we have age, and it's\n 2184 03:05:29,659 --> 03:05:34,149 at this memory address and name at this memory\n 2185 03:05:34,149 --> 03:05:39,359 if we were to go to them in our like physical\n 2186 03:05:39,360 --> 03:05:44,939 we would see those values. And again, we would\n 2187 03:05:44,939 --> 03:05:49,891 this is a pointer pointer is just a memory\n 2188 03:05:49,891 --> 03:05:54,119 just giving it another name. So that's kind\n 2189 03:05:54,120 --> 03:05:59,710 we can access like the memory addresses of\n 2190 03:05:59,709 --> 03:06:04,049 take this a step further. So I want to show\n 2191 03:06:04,049 --> 03:06:09,559 can actually create a variable where I can\n 2192 03:06:09,559 --> 03:06:14,600 creating an integer variable, and inside of\n 2193 03:06:14,600 --> 03:06:18,960 I'm creating a double variable, and I'm storing\n 2194 03:06:18,959 --> 03:06:24,089 variable, I'm storing a string. And actually,\n 2195 03:06:24,090 --> 03:06:28,450 memory addresses or the pointers inside of\n 2196 03:06:28,450 --> 03:06:31,850 So I'm going to show you guys how we can do\n 2197 03:06:31,850 --> 03:06:36,590 be just a container where we can store a pointer,\n 2198 03:06:36,590 --> 03:06:41,809 a memory address. Generally, when we're working\n 2199 03:06:41,809 --> 03:06:46,090 not just going to work with random addresses,\n 2200 03:06:46,090 --> 03:06:50,189 any, like meaningful memory addresses off\n 2201 03:06:50,189 --> 03:06:54,180 using memory addresses, we're going to be\n 2202 03:06:54,180 --> 03:06:59,720 variables in our programs. So therefore, when\n 2203 03:06:59,719 --> 03:07:04,920 words, when I create a container, what I'm\n 2204 03:07:04,920 --> 03:07:10,360 to create it based off of one of these variables.\n 2205 03:07:10,360 --> 03:07:16,489 that will store the pointer. For this age\n 2206 03:07:16,489 --> 03:07:19,670 we create a pointer variable, you always want\n 2207 03:07:19,670 --> 03:07:23,700 to be the Asterix, and then you want to type\n 2208 03:07:23,700 --> 03:07:28,150 to call this P age. And a lot of times when\n 2209 03:07:28,149 --> 03:07:33,979 use this lowercase P. And then you'll type\n 2210 03:07:33,979 --> 03:07:40,119 address you're storing. So I could say int\n 2211 03:07:40,120 --> 03:07:44,470 age. So remember when we use this ampersand,\n 2212 03:07:44,469 --> 03:07:47,879 that gives us the pointer. In other words,\n 2213 03:07:47,879 --> 03:07:54,100 value is stored. So I'm essentially storing\n 2214 03:07:54,101 --> 03:07:57,950 here called p age, I could do the same thing\n 2215 03:07:57,950 --> 03:08:05,750 double Asterix, and I'm just gonna say p GPA.\n 2216 03:08:05,750 --> 03:08:13,290 GPA. So now this pgpa pointer variable is\n 2217 03:08:13,290 --> 03:08:16,910 that storing inside of it a memory address,\n 2218 03:08:16,909 --> 03:08:21,760 of this GPA variable. I can do the same thing\n 2219 03:08:21,760 --> 03:08:29,050 p name. And actually don't forget to put the\n 2220 03:08:29,049 --> 03:08:35,519 name. And now this pointer variable p name\n 2221 03:08:35,520 --> 03:08:40,280 storing the memory address have this name\n 2222 03:08:40,280 --> 03:08:44,250 these different pointer values using these\n 2223 03:08:44,250 --> 03:08:49,170 here, I could say C out. And I could just\n 2224 03:08:49,170 --> 03:08:53,490 to go ahead and print out the value that's\n 2225 03:08:53,490 --> 03:08:59,420 is going to be a pointer, which should be\n 2226 03:08:59,420 --> 03:09:03,610 there, that's exactly what we get. So that's\n 2227 03:09:03,610 --> 03:09:08,860 a lot of times people get a little intimidated\n 2228 03:09:08,860 --> 03:09:13,610 are really simple. A pointer is just another\n 2229 03:09:13,610 --> 03:09:16,790 So you know, you can work with things like\n 2230 03:09:16,790 --> 03:09:21,270 work with doubles, which are decimal numbers,\n 2231 03:09:21,270 --> 03:09:25,380 a bunch of characters, you could also work\n 2232 03:09:25,379 --> 03:09:30,478 you know, that's all it is. It's just a different\n 2233 03:09:30,478 --> 03:09:35,170 variable, it's just a container where we can\n 2234 03:09:35,170 --> 03:09:39,840 Now I want to point out to you guys, whenever\n 2235 03:09:39,840 --> 03:09:46,351 that I use the data type of the variable that\n 2236 03:09:46,351 --> 03:09:51,250 is storing the memory address of an integer.\n 2237 03:09:51,250 --> 03:09:55,590 variable is storing the address of a double.\n 2238 03:09:55,590 --> 03:10:00,670 here. This is storing the memory does have\n 2239 03:10:00,670 --> 03:10:04,129 basically just what you have to do when we're\n 2240 03:10:04,129 --> 03:10:07,989 me to another point I want to show you guys\n 2241 03:10:07,989 --> 03:10:13,049 dereferencing, a pointer. And dereferencing.\n 2242 03:10:13,049 --> 03:10:18,259 to grab the value that's inside of the memory\n 2243 03:10:18,260 --> 03:10:24,430 address. So if I have a pointer, that is a\n 2244 03:10:24,430 --> 03:10:29,090 or a physical location, in my computer's RAM,\n 2245 03:10:29,090 --> 03:10:32,898 it's just an address, right? Like you have\n 2246 03:10:32,898 --> 03:10:37,760 what this is, it's an address. But instead\n 2247 03:10:37,760 --> 03:10:43,219 And when we dereference a pointer, we're basically\n 2248 03:10:43,219 --> 03:10:47,250 pointer, we now want to go to that physical\n 2249 03:10:47,250 --> 03:10:52,530 and use it in our program. And the way that\n 2250 03:10:52,530 --> 03:10:56,591 you'll notice, like when I print out p h,\n 2251 03:10:56,591 --> 03:11:01,890 I run this program, and I print it out, we\n 2252 03:11:01,889 --> 03:11:07,409 this pointer, we would actually end up getting\n 2253 03:11:07,409 --> 03:11:12,590 So if I put an Asterix here, this is what's\n 2254 03:11:12,590 --> 03:11:19,309 say Asterix p age, and now we'll be dereferencing,\n 2255 03:11:19,309 --> 03:11:23,709 that memory address, when I run this program,\n 2256 03:11:23,709 --> 03:11:29,899 is the value at the memory address that the\n 2257 03:11:29,899 --> 03:11:34,719 So I'm here in my program, and you'll see\n 2258 03:11:34,719 --> 03:11:39,619 this Asterix, we get the memory address, when\n 2259 03:11:39,620 --> 03:11:44,310 the pointer. So we just get 19. And that's\n 2260 03:11:44,309 --> 03:11:48,350 makes sense. I'm gonna show you guys one more\n 2261 03:11:48,350 --> 03:11:56,790 And if I just said, for example, like ampersand\n 2262 03:11:56,790 --> 03:12:01,400 it's storing the value of 2.7. This is a pointer,\n 2263 03:12:01,399 --> 03:12:06,020 address. So over here, when I run this, we\n 2264 03:12:06,020 --> 03:12:09,791 dereference this, and hopefully this kind\n 2265 03:12:09,790 --> 03:12:15,029 just put an Asterix here, and this is going\n 2266 03:12:15,030 --> 03:12:21,641 this Asterix is dereferencing, this pointer,\n 2267 03:12:21,640 --> 03:12:26,529 which is 2.7. So you can see we get this value.\n 2268 03:12:26,530 --> 03:12:32,060 together. Not that you'd want to but I could\n 2269 03:12:32,059 --> 03:12:36,939 memory address again. So that's kind of how\n 2270 03:12:36,940 --> 03:12:42,189 you know, working with pointers, doing stuff\n 2271 03:12:42,189 --> 03:12:48,829 This is also a very useful concept in another\n 2272 03:12:48,829 --> 03:12:54,689 the programming language that c++ is based\n 2273 03:12:54,689 --> 03:12:59,290 which but they're also important in c++. And\n 2274 03:12:59,290 --> 03:13:03,601 you need to have at least a baseline understanding\n 2275 03:13:03,601 --> 03:13:07,870 hopefully that gives you a little bit of an\n 2276 03:13:07,870 --> 03:13:12,280 pointers are just types of information. It's\n 2277 03:13:12,280 --> 03:13:15,620 in our programs, we can print them out, we\n 2278 03:13:15,620 --> 03:13:21,311 variables, we can also dereference them, as\n 2279 03:13:21,310 --> 03:13:30,279 that helps. And hopefully now you can kind\n 2280 03:13:30,280 --> 03:13:37,290 I'm gonna teach you guys about classes and\n 2281 03:13:37,290 --> 03:13:42,240 useful. And this is a very important topic\n 2282 03:13:42,239 --> 03:13:47,209 overview of what these are. And we'll kind\n 2283 03:13:47,209 --> 03:13:52,299 objects. So down here in my little program\n 2284 03:13:52,299 --> 03:13:55,929 basically, what I'm doing here is I'm just\n 2285 03:13:55,930 --> 03:14:02,200 I'm storing my name, inside of this name variable,\n 2286 03:14:02,200 --> 03:14:07,440 storing pi, the first three digits of Pi in\n 2287 03:14:07,440 --> 03:14:13,140 my favorite letter G inside of this character\n 2288 03:14:13,140 --> 03:14:18,020 able to store a bunch of different types of\n 2289 03:14:18,021 --> 03:14:23,280 about c++ data types, you'll know that by\n 2290 03:14:23,280 --> 03:14:27,750 different types of data. So we can store like\n 2291 03:14:27,750 --> 03:14:32,950 whole numbers, decimal numbers, we can store\n 2292 03:14:32,950 --> 03:14:38,280 types of information. But here's the problem\n 2293 03:14:38,280 --> 03:14:43,141 this is that there's a lot of types of information.\n 2294 03:14:43,140 --> 03:14:49,020 a lot of real world entities that can't just\n 2295 03:14:49,020 --> 03:14:53,489 or a character. Like there's a lot of things\n 2296 03:14:53,489 --> 03:14:58,829 or a number or a character like, like a phone\n 2297 03:14:58,829 --> 03:15:04,700 a phone In my program using like a string\n 2298 03:15:04,700 --> 03:15:09,570 like a computer, or a keyboard, or an animal\n 2299 03:15:09,569 --> 03:15:16,989 real world entities, that it can't necessarily\n 2300 03:15:16,989 --> 03:15:21,101 types that we have, or we only have like,\n 2301 03:15:21,101 --> 03:15:26,939 use. And those data types really aren't enough\n 2302 03:15:26,939 --> 03:15:32,139 the real world. So imagine I was creating\n 2303 03:15:32,139 --> 03:15:36,799 work with books, like maybe I was creating\n 2304 03:15:36,799 --> 03:15:41,569 program, we needed to represent book like,\n 2305 03:15:41,569 --> 03:15:47,569 store books and use books inside of my program.\n 2306 03:15:47,569 --> 03:15:52,601 no, like, I can't just come over here and\n 2307 03:15:52,601 --> 03:15:57,400 like, there's no book data type for me to\n 2308 03:15:57,399 --> 03:16:02,079 know, forget, forget about books for a second\n 2309 03:16:02,079 --> 03:16:08,190 like a person or a location, or a musical\n 2310 03:16:08,190 --> 03:16:12,440 in the real world that I'd want to represent\n 2311 03:16:12,440 --> 03:16:16,860 problem is we only have a limited data types,\n 2312 03:16:16,860 --> 03:16:20,739 we can represent. And this is where classes\n 2313 03:16:20,739 --> 03:16:27,189 we can actually create a class. And a class\n 2314 03:16:27,189 --> 03:16:33,939 create a class, I'm basically creating a new\n 2315 03:16:33,939 --> 03:16:39,800 are useful, because we can kind of create\n 2316 03:16:39,799 --> 03:16:43,819 program. So like I said, before, you know,\n 2317 03:16:43,819 --> 03:16:49,931 like a book data type, right. But what I can\n 2318 03:16:49,931 --> 03:16:55,489 what a book data type is. And then I can actually\n 2319 03:16:55,489 --> 03:16:59,209 of my program. So I'm going to show you guys\n 2320 03:16:59,209 --> 03:17:04,648 that will allow us to store and work with\n 2321 03:17:04,648 --> 03:17:08,599 So we're essentially going to be creating\n 2322 03:17:08,600 --> 03:17:13,670 I am just going to come up here. And I can\n 2323 03:17:13,670 --> 03:17:20,260 And I'm going to create a class and a class\n 2324 03:17:20,260 --> 03:17:25,149 for a new data type in our program. So when\n 2325 03:17:25,149 --> 03:17:30,978 new data type, I'm creating a new type of\n 2326 03:17:30,978 --> 03:17:34,829 in our programs, it's pretty cool. So over\n 2327 03:17:34,829 --> 03:17:39,569 class, and then I'm going to give this a name.\n 2328 03:17:39,569 --> 03:17:43,739 are going to name them with capital letter.\n 2329 03:17:43,739 --> 03:17:48,760 So we're going to create a book class. So\n 2330 03:17:48,760 --> 03:17:55,581 or a template for the book data type. Okay,\n 2331 03:17:55,581 --> 03:18:00,040 basically specifying what a book is, inside\n 2332 03:18:00,040 --> 03:18:04,700 here is I want to actually define the book\n 2333 03:18:04,700 --> 03:18:10,040 attributes. So we can basically say that a\n 2334 03:18:10,040 --> 03:18:15,210 five different attributes that will describe\n 2335 03:18:15,209 --> 03:18:20,759 data types like strings, integers, doubles,\n 2336 03:18:20,760 --> 03:18:26,260 attributes. So essentially, this book class\n 2337 03:18:26,260 --> 03:18:29,750 which are going to be things like numbers\n 2338 03:18:29,750 --> 03:18:34,310 public, and I'm going to make a colon here.\n 2339 03:18:34,310 --> 03:18:38,350 I'm actually going to end up this. So it's\n 2340 03:18:38,350 --> 03:18:43,659 below where I said public, I want to specify\n 2341 03:18:43,659 --> 03:18:47,619 out what a book is going to be and what it's\n 2342 03:18:47,620 --> 03:18:52,160 the different attributes of a book? Well,\n 2343 03:18:52,159 --> 03:18:56,689 going to be the title. And we can represent\n 2344 03:18:56,689 --> 03:19:02,430 title. And I'm just declaring these variables,\n 2345 03:19:02,430 --> 03:19:07,550 another walnuts thing? Probably the author,\n 2346 03:19:07,549 --> 03:19:12,750 be the book's author. And let's try to think\n 2347 03:19:12,750 --> 03:19:17,831 be maybe let's do pages. So like this would\n 2348 03:19:17,831 --> 03:19:21,630 sure you can think of a lot more we could\n 2349 03:19:21,629 --> 03:19:25,569 company, you know, you could think of, you\n 2350 03:19:25,569 --> 03:19:29,520 attributes we could store for a book. But\n 2351 03:19:29,521 --> 03:19:33,680 what I'm doing here, as I'm mapping out a\n 2352 03:19:33,680 --> 03:19:39,521 for the book, data type. And a book in our\n 2353 03:19:39,521 --> 03:19:44,700 and can have a number of pages associated\n 2354 03:19:44,700 --> 03:19:50,530 type. Really, it's a it's a class. So this\n 2355 03:19:50,530 --> 03:19:55,420 just specifying what a book is. We're telling\n 2356 03:19:55,420 --> 03:19:59,228 I'm going to come down here and I'm actually\n 2357 03:19:59,228 --> 03:20:04,449 is just a blueprint. This is a template, it's\n 2358 03:20:04,450 --> 03:20:09,570 book, if I want to actually, like have a physical\n 2359 03:20:09,569 --> 03:20:15,090 I need to create it down here. And we're actually\n 2360 03:20:15,090 --> 03:20:20,510 So here's a little terminology lesson, a class\n 2361 03:20:20,510 --> 03:20:25,750 it's the template of a data type. So this\n 2362 03:20:25,750 --> 03:20:32,431 blueprint of a book inside of our program,\n 2363 03:20:32,431 --> 03:20:38,200 or it's an actual instance of that class.\n 2364 03:20:38,200 --> 03:20:42,810 to create an object down here, we'll call\n 2365 03:20:42,809 --> 03:20:47,279 an actual book that's going to have an actual\n 2366 03:20:47,280 --> 03:20:52,939 of pages associated to it. And we can create,\n 2367 03:20:52,939 --> 03:20:58,569 but just know that a class is the template,\n 2368 03:20:58,569 --> 03:21:03,709 actual instance of that specification. So\n 2369 03:21:03,709 --> 03:21:08,779 author, and page. So let's go ahead and do\n 2370 03:21:08,780 --> 03:21:15,280 I'm basically just telling c++, what type\n 2371 03:21:15,280 --> 03:21:18,079 I want to store. And then I'm going to give\n 2372 03:21:18,079 --> 03:21:23,310 book one. So now we have this book inside\n 2373 03:21:23,310 --> 03:21:29,209 what we want to do is start giving it some\n 2374 03:21:29,209 --> 03:21:35,809 title. And we can actually give this a title.\n 2375 03:21:35,809 --> 03:21:40,590 title. So why don't we just say the title\n 2376 03:21:40,590 --> 03:21:45,130 be a Harry Potter book. And I can do the same\n 2377 03:21:45,129 --> 03:21:53,269 say book, one dot author, and I can just give\n 2378 03:21:53,270 --> 03:21:56,899 going to give this a number of pages. So I\n 2379 03:21:56,898 --> 03:22:02,010 going to be an integer. So let's say it has\n 2380 03:22:02,010 --> 03:22:08,139 to represent, and I'm able to work with a\n 2381 03:22:08,139 --> 03:22:14,019 up here is a class. It's a template for what\n 2382 03:22:14,020 --> 03:22:20,159 a physical book in our program that has actual\n 2383 03:22:20,159 --> 03:22:25,000 book, with the JK Rowling author and 500 pages.\n 2384 03:22:25,000 --> 03:22:30,360 actually print out this information. So I\n 2385 03:22:30,360 --> 03:22:36,060 book one dot title. And so now I'm able to\n 2386 03:22:36,059 --> 03:22:40,309 book, one object. So I'm basically able to\n 2387 03:22:40,309 --> 03:22:43,829 this program, now, you'll see we're printing\n 2388 03:22:43,829 --> 03:22:49,079 Potter, I can do the same thing for like pages.\n 2389 03:22:49,079 --> 03:22:55,829 in book one, which is going to be 500. So\n 2390 03:22:55,829 --> 03:23:01,920 model a real world entity like a book inside\n 2391 03:23:01,920 --> 03:23:06,450 have a book data type, right, I had nothing\n 2392 03:23:06,450 --> 03:23:12,351 Now all of a sudden, I have one. So I can\n 2393 03:23:12,351 --> 03:23:16,739 And we can make as many of these as we wanted.\n 2394 03:23:16,739 --> 03:23:20,699 let's make another book. So let's say in addition\n 2395 03:23:20,700 --> 03:23:25,030 make another one. And I'm just going to call\n 2396 03:23:25,030 --> 03:23:28,970 of these. So now all of these are sets of\n 2397 03:23:28,969 --> 03:23:34,369 attributes. Instead of it being a Harry Potter\n 2398 03:23:34,370 --> 03:23:41,520 book, and the author is going to be token.\n 2399 03:23:41,520 --> 03:23:47,560 So now I have two books in my program, I have\n 2400 03:23:47,559 --> 03:23:52,519 all of these attributes associated to it,\n 2401 03:23:52,520 --> 03:23:58,859 to it. But both of these books are using this\n 2402 03:23:58,859 --> 03:24:04,210 same book class, this is just a specification\n 2403 03:24:04,209 --> 03:24:09,938 to create individual instances of that specification.\n 2404 03:24:09,939 --> 03:24:15,569 book objects. So I could also print out stuff\n 2405 03:24:15,569 --> 03:24:24,629 Two dot author, and this is going to print\n 2406 03:24:24,629 --> 03:24:30,329 just like before, when we have like integers,\n 2407 03:24:30,329 --> 03:24:35,590 Now, in addition to those data types, we also\n 2408 03:24:35,590 --> 03:24:40,030 can use a book, I can store it, I can, you\n 2409 03:24:40,030 --> 03:24:44,239 that. And, you know, down here, basically,\n 2410 03:24:44,239 --> 03:24:49,389 giving it value. So I can say like, book one\n 2411 03:24:49,389 --> 03:24:54,869 said book to title down here, I could change\n 2412 03:24:54,870 --> 03:25:01,829 or something. And now, Book Two title is going\n 2413 03:25:01,829 --> 03:25:05,969 variables would work. And you can see now\n 2414 03:25:05,969 --> 03:25:12,279 cool. And honestly, this is just a, an introduction\n 2415 03:25:12,280 --> 03:25:16,271 to learn about, there's a lot more to talk\n 2416 03:25:16,271 --> 03:25:20,870 you want to do is just play around with modeling\n 2417 03:25:20,870 --> 03:25:25,200 book. So I created a book data type, but you\n 2418 03:25:25,200 --> 03:25:30,110 create a like a keyboard data type, you can\n 2419 03:25:30,110 --> 03:25:35,130 just taking a real world entity, breaking\n 2420 03:25:35,129 --> 03:25:43,869 author, and pages, and then you can represent\n 2421 03:25:43,870 --> 03:25:50,271 going to teach you guys how to use constructors\n 2422 03:25:50,271 --> 03:25:56,989 is a basically a special function that is\n 2423 03:25:56,989 --> 03:26:01,399 object of a class. So let me show you guys,\n 2424 03:26:01,399 --> 03:26:04,899 actually up here, I have this class, it's\n 2425 03:26:04,899 --> 03:26:09,520 the course, we created this class in the last\n 2426 03:26:09,520 --> 03:26:14,700 just sort of a blueprint or a specification\n 2427 03:26:14,700 --> 03:26:19,670 So you know, a book has a title, has an author\n 2428 03:26:19,670 --> 03:26:25,450 we actually created some book objects. And\n 2429 03:26:25,450 --> 03:26:30,960 So we have book one, and book one has a title.\n 2430 03:26:30,959 --> 03:26:35,750 pages, and all that stuff. So I'm going to\n 2431 03:26:35,750 --> 03:26:40,040 play. So a constructor, like I said, it's\n 2432 03:26:40,040 --> 03:26:45,720 get called whenever we create one of these\n 2433 03:26:45,719 --> 03:26:49,909 to go ahead and create a constructor. And\n 2434 03:26:49,909 --> 03:26:56,129 is just by essentially creating a function\n 2435 03:26:56,129 --> 03:27:00,500 And I'm gonna make an open and close parentheses\n 2436 03:27:00,500 --> 03:27:05,670 what we have here is a constructor. So this\n 2437 03:27:05,670 --> 03:27:11,149 to get called whenever we create a book object.\n 2438 03:27:11,149 --> 03:27:17,501 going to print something out. And I'll just\n 2439 03:27:17,501 --> 03:27:24,420 to print a new line. So down here, I'm creating\n 2440 03:27:24,420 --> 03:27:30,040 creating Book Two, whenever I create a new\n 2441 03:27:30,040 --> 03:27:35,720 function up here is going to get called. So\n 2442 03:27:35,719 --> 03:27:42,219 here, it says, creating object twice. So it\n 2443 03:27:42,219 --> 03:27:45,869 made this line of code. And then down here,\n 2444 03:27:45,870 --> 03:27:51,649 when we created this second object. So we\n 2445 03:27:51,648 --> 03:27:56,069 function got called twice. Hopefully that\n 2446 03:27:56,069 --> 03:28:01,831 this book function is that it can accept parameters.\n 2447 03:28:01,831 --> 03:28:07,670 this is going to accept a parameter like name.\n 2448 03:28:07,670 --> 03:28:12,420 whatever the user passed it. And so now down\n 2449 03:28:12,420 --> 03:28:19,250 pass values in so I could pass in like Harry\n 2450 03:28:19,250 --> 03:28:25,059 we could pass in like, Lord of the Rings.\n 2451 03:28:25,059 --> 03:28:30,629 when I run my program, it's going to actually\n 2452 03:28:30,629 --> 03:28:36,728 of printing out like, creating object, it's\n 2453 03:28:36,728 --> 03:28:42,398 the constructor. Pretty cool, right? And constructors\n 2454 03:28:42,398 --> 03:28:46,500 we create objects. So let me point something\n 2455 03:28:46,500 --> 03:28:53,020 to get rid of this stuff up here. So only\n 2456 03:28:53,020 --> 03:28:57,989 these objects, right. And when I wanted to\n 2457 03:28:57,989 --> 03:29:03,530 so when I created book one, and Book Two,\n 2458 03:29:03,530 --> 03:29:08,229 going to be, what the author was going to\n 2459 03:29:08,228 --> 03:29:12,059 it kind of took up a lot of time, right, it\n 2460 03:29:12,059 --> 03:29:16,469 out book one dot title, book, one dot author.\n 2461 03:29:16,469 --> 03:29:20,909 that I create. Well, that gets really, really\n 2462 03:29:20,909 --> 03:29:25,939 two objects, I wanted to create like 100 or\n 2463 03:29:25,939 --> 03:29:30,521 lines of code, I mean, just to create one\n 2464 03:29:30,521 --> 03:29:37,270 We can actually use these constructors in\n 2465 03:29:37,270 --> 03:29:41,760 So like when I create this book, one instead\n 2466 03:29:41,760 --> 03:29:48,000 author and the pages. Instead, I could just\n 2467 03:29:48,000 --> 03:29:52,760 the constructor could initialize the values\n 2468 03:29:52,760 --> 03:29:57,000 do that up here. In our constructor, I'm going\n 2469 03:29:57,000 --> 03:30:04,350 to take three values. So this book constructor\n 2470 03:30:04,350 --> 03:30:08,460 we're just going to call this a title, it's\n 2471 03:30:08,459 --> 03:30:14,469 call it a author. And it's going to take an\n 2472 03:30:14,469 --> 03:30:18,090 And I'm putting this a here, you don't have\n 2473 03:30:18,090 --> 03:30:21,989 of easy for us to see what's going on, a is\n 2474 03:30:21,989 --> 03:30:26,728 will be like the title, that's an argument.\n 2475 03:30:26,728 --> 03:30:33,489 can actually assign the values of title, author\n 2476 03:30:33,489 --> 03:30:38,649 So down here, we're assigning the values of\n 2477 03:30:38,649 --> 03:30:43,879 But instead of having to do it down here,\n 2478 03:30:43,879 --> 03:30:50,179 So I could say that the title is going to\n 2479 03:30:50,180 --> 03:30:55,370 title of the object, the title that we want\n 2480 03:30:55,370 --> 03:30:59,460 to be equal to the title that gets passed\n 2481 03:30:59,459 --> 03:31:06,739 So I could say, author is going to be equal\n 2482 03:31:06,739 --> 03:31:12,969 to A pages. And again, you don't have to name\n 2483 03:31:12,969 --> 03:31:17,489 whatever you want. I'm just kind of doing\n 2484 03:31:17,489 --> 03:31:24,829 going on. So down here, what I can do now\n 2485 03:31:24,829 --> 03:31:30,469 it a title and author and a number of pages.\n 2486 03:31:30,469 --> 03:31:35,898 you'll see we're getting an error, we're basically\n 2487 03:31:35,898 --> 03:31:43,310 these values. So what I can do is I can actually\n 2488 03:31:43,310 --> 03:31:49,219 I can take the number of pages, so 500, and\n 2489 03:31:49,219 --> 03:31:52,319 I can just get rid of all this code, because\n 2490 03:31:52,319 --> 03:31:56,750 same thing for the Lord of the Rings book.\n 2491 03:31:56,750 --> 03:32:01,360 pages. And so now we can get rid of all this\n 2492 03:32:01,360 --> 03:32:05,960 of code to create two objects. So now we just\n 2493 03:32:05,959 --> 03:32:12,709 my program, we should be able to essentially\n 2494 03:32:12,709 --> 03:32:17,819 So let's go ahead and print out this stuff.\n 2495 03:32:17,819 --> 03:32:23,369 just going to see out while we see our book,\n 2496 03:32:23,370 --> 03:32:29,920 So we should get Harry Potter, which we do.\n 2497 03:32:29,920 --> 03:32:35,739 except we're able to do it a lot easier and\n 2498 03:32:35,739 --> 03:32:40,760 So this was a very, very powerful tool for\n 2499 03:32:40,760 --> 03:32:45,398 we can still modify these. So I could still\n 2500 03:32:45,398 --> 03:32:50,789 the title. So I can change the title to whatever\n 2501 03:32:50,790 --> 03:32:55,580 doing with this constructor here is we're\n 2502 03:32:55,579 --> 03:33:01,689 just making it easier for us to initialize\n 2503 03:33:01,689 --> 03:33:04,819 sort of the basics of using constructors.\n 2504 03:33:04,819 --> 03:33:10,750 do, you can actually create multiple constructors.\n 2505 03:33:10,750 --> 03:33:16,601 essentially just allow us to take in a title\n 2506 03:33:16,601 --> 03:33:21,630 say that for some books, we wouldn't want\n 2507 03:33:21,629 --> 03:33:27,879 make another constructor over here. And this\n 2508 03:33:27,879 --> 03:33:32,500 parameters. And I can just give these values\n 2509 03:33:32,500 --> 03:33:42,030 say like title is equal to no title. Author\n 2510 03:33:42,030 --> 03:33:47,649 like pages is equal to zero. So this is basically\n 2511 03:33:47,648 --> 03:33:52,350 information if we don't pass anything it and\n 2512 03:33:52,351 --> 03:33:58,350 here and I can create another book. So I can\n 2513 03:33:58,350 --> 03:34:03,970 And I now I don't have to pass in this information.\n 2514 03:34:03,970 --> 03:34:08,100 print out like Book Three dot title, and it's\n 2515 03:34:08,100 --> 03:34:15,370 this needs to be capital whoops. So now you\n 2516 03:34:15,370 --> 03:34:20,680 will create multiple constructors, you're\n 2517 03:34:20,680 --> 03:34:27,139 they can create your objects. But I'd say\n 2518 03:34:27,139 --> 03:34:32,549 where you pass in all of the attributes, and\n 2519 03:34:32,549 --> 03:34:36,590 that's the basics of constructors. Hopefully\n 2520 03:34:36,590 --> 03:34:44,680 so you're definitely going to want to use\n 2521 03:34:44,680 --> 03:34:49,689 I'm going to talk to you guys about object\n 2522 03:34:49,689 --> 03:34:54,860 refer to these sometimes as like instance\n 2523 03:34:54,860 --> 03:35:00,500 it's a function that we can put inside of\n 2524 03:35:00,500 --> 03:35:05,689 objects of that class can use that function\n 2525 03:35:05,689 --> 03:35:09,319 about themselves, or modify information about\n 2526 03:35:09,319 --> 03:35:14,139 a sort of introduction into how to do this.\n 2527 03:35:14,139 --> 03:35:20,309 up a class. And this class is called student.\n 2528 03:35:20,309 --> 03:35:25,049 like what a student is going to be in our\n 2529 03:35:25,049 --> 03:35:29,069 is going to have a name, a student is going\n 2530 03:35:29,069 --> 03:35:36,170 to have a GPA. So that information is sort\n 2531 03:35:36,170 --> 03:35:41,450 And then down here, I created a constructor,\n 2532 03:35:41,450 --> 03:35:45,590 these objects owner to pass in some initial\n 2533 03:35:45,590 --> 03:35:51,530 of major and then also the GPA. So I'm essentially\n 2534 03:35:51,530 --> 03:35:55,820 would any other constructor. So this is our\n 2535 03:35:55,819 --> 03:35:59,851 method, you'll see that I actually have a\n 2536 03:35:59,851 --> 03:36:06,060 student one, his name is Jim, he's a business\n 2537 03:36:06,059 --> 03:36:13,529 another student student two, her name is Pam.\n 2538 03:36:13,530 --> 03:36:18,370 So these are now two students that I'm working\n 2539 03:36:18,370 --> 03:36:23,960 of my programs. That's awesome. So let me\n 2540 03:36:23,959 --> 03:36:29,259 object functions. Let's say that we wanted\n 2541 03:36:29,260 --> 03:36:33,109 these students was on the honor roll. Right.\n 2542 03:36:33,109 --> 03:36:37,630 students attend, there's an honor roll, right,\n 2543 03:36:37,629 --> 03:36:44,279 the honor roll as you need to have a GPA of\n 2544 03:36:44,280 --> 03:36:49,540 or greater, that means that you're on the\n 2545 03:36:49,540 --> 03:36:54,260 have an easy way to figure out whether or\n 2546 03:36:54,260 --> 03:36:59,690 Well, what I could do is I could actually\n 2547 03:36:59,690 --> 03:37:03,710 which each of the objects can use to tell\n 2548 03:37:03,709 --> 03:37:08,319 what I'm going to do is I'm going to go down\n 2549 03:37:08,319 --> 03:37:13,398 just create a function like I normally would,\n 2550 03:37:13,398 --> 03:37:18,869 going to give this a Boolean return type.\n 2551 03:37:18,870 --> 03:37:24,220 and this function is basically going to return\n 2552 03:37:24,219 --> 03:37:29,789 if the student has honors right? No return\n 2553 03:37:29,790 --> 03:37:33,750 If they don't, it's going to return false.\n 2554 03:37:33,750 --> 03:37:38,329 in any information, we don't need any parameters,\n 2555 03:37:38,329 --> 03:37:44,299 bracket. Now down here inside of this function,\n 2556 03:37:44,299 --> 03:37:47,939 So I can just use an if statement, I'm just\n 2557 03:37:47,940 --> 03:37:55,081 say if GPA is greater than 3.5. Or actually,\n 2558 03:37:55,081 --> 03:38:01,239 we're gonna come down here, and we can just\n 2559 03:38:01,239 --> 03:38:05,909 that means that they have a GPA of 3.5 or\n 2560 03:38:05,909 --> 03:38:11,389 the case, we can just return false. So that's\n 2561 03:38:11,389 --> 03:38:15,811 to do. It's very simple if they have a GPA\n 2562 03:38:15,811 --> 03:38:22,228 false. Now, what's cool about this function\n 2563 03:38:22,228 --> 03:38:27,789 this function, and depending on their specific\n 2564 03:38:27,790 --> 03:38:33,780 So for example, let's go ahead and call this\n 2565 03:38:33,780 --> 03:38:41,450 C out I just want to print out the answer.\n 2566 03:38:41,450 --> 03:38:46,609 So now if I want to figure out whether or\n 2567 03:38:46,609 --> 03:38:51,710 I can say student one dot has honors. And\n 2568 03:38:51,709 --> 03:38:57,688 not Jim has honors. So you'll see over here,\n 2569 03:38:57,689 --> 03:39:01,590 Whenever you print out Boolean values, if\n 2570 03:39:01,590 --> 03:39:05,860 as a zero. If it's a true, it's going to get\n 2571 03:39:05,860 --> 03:39:11,460 seeing a zero here means that student one\n 2572 03:39:11,459 --> 03:39:15,079 thing for Pam. So we can do the same thing\n 2573 03:39:15,079 --> 03:39:24,170 to dot has honors. And now this should be\n 2574 03:39:24,170 --> 03:39:29,450 is going to have honors. What's cool about\n 2575 03:39:29,450 --> 03:39:33,990 to be using different information depending\n 2576 03:39:33,989 --> 03:39:41,639 gym object calls it, the GPA is Jim's GPA.\n 2577 03:39:41,639 --> 03:39:48,010 GPA. So we can define a general function over\n 2578 03:39:48,010 --> 03:39:52,819 that calls it, it's going to be giving or\n 2579 03:39:52,819 --> 03:39:57,359 to be different, depending on if Jim's calling\n 2580 03:39:57,359 --> 03:40:01,930 of why these are cool so you can make awesome\n 2581 03:40:01,930 --> 03:40:06,899 will make these to get information about the\n 2582 03:40:06,899 --> 03:40:11,310 or not they have honors, or modify values.\n 2583 03:40:11,310 --> 03:40:16,459 at functions which are going to be modifying\n 2584 03:40:16,459 --> 03:40:21,239 kind of gives you an idea of what you can\n 2585 03:40:21,239 --> 03:40:25,139 cases, you're going to want to have different\n 2586 03:40:25,139 --> 03:40:30,068 going to do stuff. Now I do want to just point\n 2587 03:40:30,068 --> 03:40:35,010 let's say that I have this program written.\n 2588 03:40:35,010 --> 03:40:38,250 students. And maybe I have a program that\n 2589 03:40:38,250 --> 03:40:43,340 something. Well, let's say that one day, the\n 2590 03:40:43,340 --> 03:40:49,049 Hey, Mike, we're going to change the qualification\n 2591 03:40:49,049 --> 03:40:53,688 a 3.5, and greater is going to have honors,\n 2592 03:40:53,689 --> 03:40:57,889 and greater is going to have honors, in order\n 2593 03:40:57,889 --> 03:41:02,648 In other words, in order for me to update\n 2594 03:41:02,648 --> 03:41:09,010 here and change this to 2.0. And now all of\n 2595 03:41:09,011 --> 03:41:13,850 And these has honors are still going to work.\n 2596 03:41:13,850 --> 03:41:19,360 to be lowered. So I can say student one has\n 2597 03:41:19,360 --> 03:41:23,810 because we changed the qualification. So now\n 2598 03:41:23,809 --> 03:41:29,279 are powerful, you can kind of adjust different\n 2599 03:41:29,280 --> 03:41:35,130 things about the overall class and about every\n 2600 03:41:35,129 --> 03:41:40,099 So hopefully that is clear. Hopefully, you\n 2601 03:41:40,100 --> 03:41:48,700 different objects functions. In this tutorial,\n 2602 03:41:48,700 --> 03:41:55,280 and setters in c++ classes. Now, getters and\n 2603 03:41:55,280 --> 03:42:00,899 they allow you to control the access to the\n 2604 03:42:00,898 --> 03:42:07,449 inside of your c++ classes. So I'm going to\n 2605 03:42:07,450 --> 03:42:12,069 order to do that, we're going to use a little\n 2606 03:42:12,068 --> 03:42:16,779 created, it's called movie. And this is basically\n 2607 03:42:16,780 --> 03:42:21,470 inside of our program. So I have a few different\n 2608 03:42:21,469 --> 03:42:25,769 it's going to have a director, it's also going\n 2609 03:42:25,770 --> 03:42:29,710 attributes of a movie, right, we can basically\n 2610 03:42:29,709 --> 03:42:32,909 it's going to be, that's what it's going to\n 2611 03:42:32,909 --> 03:42:37,890 So I'm just passing in the title, the director,\n 2612 03:42:37,890 --> 03:42:42,889 we're assigning those values to the values\n 2613 03:42:42,889 --> 03:42:46,170 stuff. And if you've been following along\n 2614 03:42:46,170 --> 03:42:49,809 kind of make sense. You know what I'm doing\n 2615 03:42:49,809 --> 03:42:55,709 class, movie data type. And down here, I actually\n 2616 03:42:55,709 --> 03:43:01,339 it's called Avengers and the title is The\n 2617 03:43:01,340 --> 03:43:06,380 rating is pG 13. So um, I'm creating an actual\n 2618 03:43:06,379 --> 03:43:11,129 out the rating. So why don't we run our program,\n 2619 03:43:11,129 --> 03:43:15,380 So over here, I have pG 13. So it's printing\n 2620 03:43:15,380 --> 03:43:21,609 looks good. Now, here's the thing, a lot of\n 2621 03:43:21,610 --> 03:43:28,239 like a class up here, like this movie, we're\n 2622 03:43:28,239 --> 03:43:33,780 can be stored for a particular movie. And\n 2623 03:43:33,780 --> 03:43:41,050 I have this rating as pG 13. Right. And generally\n 2624 03:43:41,049 --> 03:43:49,890 of ratings that you can have, so it'd be like\n 2625 03:43:49,890 --> 03:43:53,889 rated. So just for our purposes, let's say\n 2626 03:43:53,889 --> 03:43:58,629 give to move PG, PG, PG, 13, Rn, nr, right?\n 2627 03:43:58,629 --> 03:44:02,839 of. But let's just say that those are the\n 2628 03:44:02,840 --> 03:44:07,500 for a movie, those are the ratings that are\n 2629 03:44:07,500 --> 03:44:14,299 Well, over here, I'm inserting pG 13. But\n 2630 03:44:14,299 --> 03:44:19,188 else. There's nothing stopping me from just\n 2631 03:44:19,189 --> 03:44:24,979 nothing that's stopping me from just typing\n 2632 03:44:24,979 --> 03:44:28,459 the program and being able to store it inside\n 2633 03:44:28,459 --> 03:44:34,500 set the rating equal to dog, even though that's\n 2634 03:44:34,500 --> 03:44:38,610 that we can have. And there's a lot of circumstances\n 2635 03:44:38,610 --> 03:44:43,189 for example, you know, valid ratings that\n 2636 03:44:43,189 --> 03:44:47,290 words, like when you're writing this program,\n 2637 03:44:47,290 --> 03:44:52,260 want a movie object to be created. That's\n 2638 03:44:52,260 --> 03:44:56,911 want this to be able to happen down here.\n 2639 03:44:56,911 --> 03:45:02,210 rating in as dogs. So I'm gonna show you guys\n 2640 03:45:02,209 --> 03:45:07,459 how we could make it so that the user can\n 2641 03:45:07,459 --> 03:45:13,029 a valid rating. And to do that, we can use\n 2642 03:45:13,030 --> 03:45:16,640 the first thing that I'm going to do, after\n 2643 03:45:16,639 --> 03:45:21,789 here into my class. So up here in my movie\n 2644 03:45:21,790 --> 03:45:26,950 you'll see up here, I have this keyword public.\n 2645 03:45:26,950 --> 03:45:33,250 put all this stuff underneath public, what\n 2646 03:45:33,250 --> 03:45:37,840 And basically, when something's public, it\n 2647 03:45:37,840 --> 03:45:44,521 can access it. So essentially, any code outside\n 2648 03:45:44,521 --> 03:45:49,230 of the movie, the director of the rating and\n 2649 03:45:49,229 --> 03:45:56,930 print out Avengers dot rating, because rating\n 2650 03:45:56,931 --> 03:46:00,750 because it's underneath this little public\n 2651 03:46:00,750 --> 03:46:06,020 we can use in c++, which is called private.\n 2652 03:46:06,020 --> 03:46:11,640 public, I can just say private, and any attributes,\n 2653 03:46:11,639 --> 03:46:16,879 I put underneath this private keyword, is\n 2654 03:46:16,879 --> 03:46:23,898 if I was to take this string rating, and I\n 2655 03:46:23,898 --> 03:46:30,689 what this means is now only code inside of\n 2656 03:46:30,690 --> 03:46:36,710 attribute, only code that's inside the movie\n 2657 03:46:36,709 --> 03:46:41,259 down here now and try to print out Avengers\n 2658 03:46:41,260 --> 03:46:44,460 that anymore. And you're going to see that\n 2659 03:46:44,459 --> 03:46:51,019 this highlights in red basically telling us\n 2660 03:46:51,020 --> 03:46:57,200 because it's private, so I no longer have\n 2661 03:46:57,200 --> 03:47:02,140 Now one thing I will point out is I have access\n 2662 03:47:02,139 --> 03:47:08,760 because the rating variable, the rating attribute\n 2663 03:47:08,760 --> 03:47:14,920 so it's able to access it. But this main function\n 2664 03:47:14,920 --> 03:47:19,960 the main function can't, because it's not\n 2665 03:47:19,959 --> 03:47:23,688 the difference between public and private.\n 2666 03:47:23,689 --> 03:47:28,680 order to control what ratings are able to\n 2667 03:47:28,680 --> 03:47:31,770 guys how we can do this, the first thing I\n 2668 03:47:31,770 --> 03:47:39,649 I'm going to create a public function, and\n 2669 03:47:39,648 --> 03:47:43,148 this is going to be void. And I'm just going\n 2670 03:47:43,148 --> 03:47:49,279 take as a parameter, it's going to take one\n 2671 03:47:49,280 --> 03:47:56,130 So this is going to take a rating as a parameter\n 2672 03:47:56,129 --> 03:48:02,750 I'm basically going to say rating is equal\n 2673 03:48:02,750 --> 03:48:09,359 a value to the rating, I'm going to make it\n 2674 03:48:09,359 --> 03:48:14,550 So over here, instead of saying rating is\n 2675 03:48:14,549 --> 03:48:21,329 to say, set rating, and I'm going to pass\n 2676 03:48:21,329 --> 03:48:26,101 rating, it's going to go through this set\n 2677 03:48:26,101 --> 03:48:32,189 to modify the rating down here, so if I wanted\n 2678 03:48:32,189 --> 03:48:37,649 dog, I'm not going to be able to do this again,\n 2679 03:48:37,649 --> 03:48:42,739 it over here. But if I want to modify the\n 2680 03:48:42,739 --> 03:48:47,601 function, because it's public. So over here,\n 2681 03:48:47,601 --> 03:48:52,579 of saying Avengers dot rating, I could say\n 2682 03:48:52,579 --> 03:49:00,161 this as a parameter, dog. Alright, so now\n 2683 03:49:00,161 --> 03:49:05,879 here in the constructor, or down here in the\n 2684 03:49:05,879 --> 03:49:11,939 set rating function. And that's going to be\n 2685 03:49:11,940 --> 03:49:17,550 do now is we can set up some rules. So I can\n 2686 03:49:17,549 --> 03:49:22,228 function for what ratings are going to be\n 2687 03:49:22,228 --> 03:49:26,529 Essentially, what I'll do is I'll create an\n 2688 03:49:26,530 --> 03:49:33,120 passed in is one of the valid ratings like\n 2689 03:49:33,120 --> 03:49:37,870 it. Otherwise, we'll be able to essentially\n 2690 03:49:37,870 --> 03:49:42,390 like, Hey, this is an invalid rating. So down\n 2691 03:49:42,389 --> 03:49:47,689 And I'm just gonna say if. And I'm basically\n 2692 03:49:47,689 --> 03:49:58,700 one of the valid rating so we can check to\n 2693 03:49:58,700 --> 03:50:05,550 is equal to P And I can keep doing this for\n 2694 03:50:05,549 --> 03:50:17,090 this over here. And I'm just gonna say, or\n 2695 03:50:17,090 --> 03:50:26,780 equal to R. And then there's one more, which\n 2696 03:50:26,780 --> 03:50:31,890 So basically, what I'm doing is I'm creating\n 2697 03:50:31,889 --> 03:50:36,680 all of these conditions. So it's checking\n 2698 03:50:36,680 --> 03:50:43,898 to PG, or if it's equal to pG 13, or R or\n 2699 03:50:43,898 --> 03:50:48,760 those, right, if it's equal to one of those\n 2700 03:50:48,761 --> 03:50:54,870 set it normally. So I could say like rating\n 2701 03:50:54,870 --> 03:50:59,689 entered in a valid rating, so it's going to\n 2702 03:50:59,689 --> 03:51:04,460 enter in a valid rating, that means that we're\n 2703 03:51:04,459 --> 03:51:08,799 that they entered, so I can say else. And\n 2704 03:51:08,799 --> 03:51:14,090 set rating equal to an R. So we'll say that\n 2705 03:51:14,090 --> 03:51:18,859 they tried to set an invalid rating, for the\n 2706 03:51:18,859 --> 03:51:22,899 go ahead and set it to nr because they didn't\n 2707 03:51:22,898 --> 03:51:28,250 to be not rated. So here's the thing. Now\n 2708 03:51:28,250 --> 03:51:33,719 to go through this set rating function. So\n 2709 03:51:33,719 --> 03:51:38,469 say Avengers, set rating and dog. And then\n 2710 03:51:38,469 --> 03:51:44,229 gonna say nr, because they entered in an invalid\n 2711 03:51:44,229 --> 03:51:49,100 But here's the other problem is when I can't\n 2712 03:51:49,100 --> 03:51:54,420 Access Avengers dot rating, because it's private,\n 2713 03:51:54,420 --> 03:51:59,299 another function up here, and this one is\n 2714 03:51:59,299 --> 03:52:03,979 a string. And I'm just going to call it get\n 2715 03:52:03,979 --> 03:52:12,370 it's just going to return rating, so it'll\n 2716 03:52:12,370 --> 03:52:16,659 to print this out, I could say Avengers dot\n 2717 03:52:16,659 --> 03:52:22,090 So let's go ahead and see what happens. So\n 2718 03:52:22,090 --> 03:52:27,040 dog. That's an invalid rating. So now when\n 2719 03:52:27,040 --> 03:52:31,340 just print out nr. And actually looks like\n 2720 03:52:31,340 --> 03:52:35,719 equals in there. Let me see if I did that\n 2721 03:52:35,719 --> 03:52:42,929 able to run this now. Yeah, so down here,\n 2722 03:52:42,930 --> 03:52:47,800 I tried to set the rating u equal to dog,\n 2723 03:52:47,799 --> 03:52:52,649 to get it, it's just giving me an R. And that's\n 2724 03:52:52,649 --> 03:52:58,469 over here, when I just first created this,\n 2725 03:52:58,469 --> 03:53:02,479 that is one of the official ratings that we\n 2726 03:53:02,479 --> 03:53:08,770 have that it'll have a rating of pG 13. But\n 2727 03:53:08,771 --> 03:53:13,859 that's not a valid rating, right. So when\n 2728 03:53:13,859 --> 03:53:17,870 say that it's not rated because we didn't\n 2729 03:53:17,870 --> 03:53:21,410 can essentially do whatever you wanted there.\n 2730 03:53:21,409 --> 03:53:25,939 is that there's going to be certain times\n 2731 03:53:25,939 --> 03:53:31,439 you know how the user can interact with the\n 2732 03:53:31,439 --> 03:53:36,880 our case, we wanted to be able to restrict\n 2733 03:53:36,879 --> 03:53:42,500 inside of a movie. So I was able to set the\n 2734 03:53:42,500 --> 03:53:47,059 could access it directly. They couldn't just\n 2735 03:53:47,059 --> 03:53:51,180 or the ratings equal to that. Instead, if\n 2736 03:53:51,180 --> 03:53:55,380 through the set rating function. And they\n 2737 03:53:55,379 --> 03:54:00,449 here. And that is an awesome way to control\n 2738 03:54:00,450 --> 03:54:08,720 individual attributes in a specific object.\n 2739 03:54:08,719 --> 03:54:16,429 guys about inheritance in c++. inheritance\n 2740 03:54:16,430 --> 03:54:20,770 And then we can define other classes. And\n 2741 03:54:20,770 --> 03:54:26,010 or they can inherit all the functionality,\n 2742 03:54:26,010 --> 03:54:29,909 So the easiest way for me to explain this\n 2743 03:54:29,909 --> 03:54:35,959 So over here in my program, I created a class\n 2744 03:54:35,959 --> 03:54:40,279 this class is like modeling like a chef in\n 2745 03:54:40,280 --> 03:54:44,920 functions that the chef class can perform.\n 2746 03:54:44,920 --> 03:54:48,969 salad and the chef can make a special dish.\n 2747 03:54:48,969 --> 03:54:53,670 out like what it's doing. So this one says\n 2748 03:54:53,670 --> 03:54:59,090 Chef makes barbecue ribs. Very simple class.\n 2749 03:54:59,090 --> 03:55:04,079 an instance of this Chef class, and called\n 2750 03:55:04,079 --> 03:55:08,069 make chicken. So let's run the program. And\n 2751 03:55:08,069 --> 03:55:13,590 program, you'll see, it prints out the chef\n 2752 03:55:13,590 --> 03:55:18,950 class. And let's say that I'm running my program.\n 2753 03:55:18,950 --> 03:55:23,630 in addition to representing just a normal\n 2754 03:55:23,629 --> 03:55:28,619 Italian chef. So what I'm going to do is I'm\n 2755 03:55:28,620 --> 03:55:33,910 another class. So I'm just going to say class.\n 2756 03:55:33,909 --> 03:55:40,369 going to create an Italian chef class. So\n 2757 03:55:40,370 --> 03:55:46,620 our purposes, when we're creating this Italian\n 2758 03:55:46,620 --> 03:55:52,760 able to do everything that the normal chef\n 2759 03:55:52,760 --> 03:55:57,659 can also make salad and can also make a special\n 2760 03:55:57,659 --> 03:56:02,629 chef will be able to do a bunch of other stuff,\n 2761 03:56:02,629 --> 03:56:08,759 to build this Italian chef. Because the Italian\n 2762 03:56:08,760 --> 03:56:13,940 that the normal chef could do, like make chicken,\n 2763 03:56:13,940 --> 03:56:20,780 actually inherit all of these functions. From\n 2764 03:56:20,780 --> 03:56:24,319 I'll show you guys how to do that, it's actually\n 2765 03:56:24,318 --> 03:56:31,010 here. And I'm just going to make a colon.\n 2766 03:56:31,010 --> 03:56:36,439 this is referring to the class that I want\n 2767 03:56:36,439 --> 03:56:42,540 this is this Italian chef is going to have\n 2768 03:56:42,540 --> 03:56:48,130 in this chef class. So it's basically going\n 2769 03:56:48,129 --> 03:56:52,619 show you if I was to come down here and create\n 2770 03:56:52,620 --> 03:57:03,220 chef, we'll just call it Italian chef. I could\n 2771 03:57:03,219 --> 03:57:09,159 even though I didn't specify anything up here,\n 2772 03:57:09,159 --> 03:57:14,818 even though I didn't specify a make chicken\n 2773 03:57:14,818 --> 03:57:21,859 function up here, I'm still able to call make\n 2774 03:57:21,859 --> 03:57:28,239 this program, now, you'll see it says the\n 2775 03:57:28,239 --> 03:57:33,949 function on the normal chef and the Italian\n 2776 03:57:33,950 --> 03:57:39,450 Italian chef down here is inheriting all of\n 2777 03:57:39,450 --> 03:57:44,560 of demonstrate this even further, if I came\n 2778 03:57:44,559 --> 03:57:49,739 yummy chicken. Now when I run my program,\n 2779 03:57:49,739 --> 03:57:55,568 also going to be able to make yummy chicken.\n 2780 03:57:55,568 --> 03:58:00,079 from the chef class. And what's cool about\n 2781 03:58:00,079 --> 03:58:04,899 all that in functionality, but we could extend\n 2782 03:58:04,899 --> 03:58:08,860 to be able to do everything the chef does.\n 2783 03:58:08,861 --> 03:58:15,460 Italian chef could also like make pasta. And\n 2784 03:58:15,459 --> 03:58:23,099 like the chef makes pasta. So in addition\n 2785 03:58:23,100 --> 03:58:27,870 normal chef can make, this Italian chef can\n 2786 03:58:27,870 --> 03:58:34,200 say make pasta. But it's important to note\n 2787 03:58:34,200 --> 03:58:39,070 if I tried to call pop make pasta on the normal\n 2788 03:58:39,069 --> 03:58:43,760 So you'll see over here, it's not going to\n 2789 03:58:43,760 --> 03:58:48,530 it looks like I had an error up here. So this\n 2790 03:58:48,530 --> 03:58:52,649 get an error down by the other chef. Yeah,\n 2791 03:58:52,648 --> 03:58:58,649 basically saying this, this chef can't make\n 2792 03:58:58,649 --> 03:59:02,199 now that you'll see the Italian chef is gonna\n 2793 03:59:02,200 --> 03:59:08,109 chicken. And actually one more thing I forgot,\n 2794 03:59:08,109 --> 03:59:13,590 to do that. So I'm gonna say public. And then\n 2795 03:59:13,590 --> 03:59:18,121 function is going to be public. So now we\n 2796 03:59:18,120 --> 03:59:23,459 see it says the chef makes yummy chicken and\n 2797 03:59:23,459 --> 03:59:27,960 are able to do different things. And that's\n 2798 03:59:27,960 --> 03:59:33,859 do with inheritance is I can actually override\n 2799 03:59:33,860 --> 03:59:38,710 the normal chef has this make special dish\n 2800 03:59:38,709 --> 03:59:43,649 ribs as a special dish. But let's say that\n 2801 03:59:43,649 --> 03:59:48,569 special dish. Well, I can do something called\n 2802 03:59:48,569 --> 03:59:54,840 this function from up here. And I can paste\n 2803 03:59:54,840 --> 04:00:00,790 now this is going to override the function\n 2804 04:00:00,790 --> 04:00:07,729 ribs we could have him make like chicken parm.\n 2805 04:00:07,728 --> 04:00:12,108 chicken parm while the normal chef will make\n 2806 04:00:12,109 --> 04:00:20,569 I said make special dish on the normal chef\n 2807 04:00:20,569 --> 04:00:26,489 Italian chef. Now these are going to be two\n 2808 04:00:26,489 --> 04:00:32,250 overrode that original function. So chef makes\n 2809 04:00:32,250 --> 04:00:37,069 So that's kind of how overriding can be useful.\n 2810 04:00:37,069 --> 04:00:42,690 want to change, like what it's doing, or modify\n 2811 04:00:42,690 --> 04:00:48,950 do that. Now, just a quick terminology. So\n 2812 04:00:48,950 --> 04:00:55,319 And then we would call this Italian chef class\n 2813 04:00:55,318 --> 04:01:02,159 from the chef class, which is the superclass\n 2814 04:01:02,159 --> 04:01:05,889 is you're essentially creating a class and\n 2815 04:01:05,889 --> 04:01:10,689 another class inside of it. And then you can\n 2816 04:01:10,689 --> 04:01:16,040 add on to it, or you can override the functions\n 2817 04:01:16,040 --> 04:01:18,249 If you enjoyed the video, please leave a like\nand subscribe. 231534

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.