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

af Afrikaans
ak Akan
sq Albanian
am Amharic
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

Original subtitles

Hey, welcome to draft Academy. My name is\n

you guys everything you need to know to get\n

popular programming languages around. And\n

language, it's actually a language that is\n

In fact, c++ is essentially just like the\n

So if you're already familiar with the C programming\n

picking up c++. But even if you're not c++\n

And in this course, I'm going to teach you\n

gonna start off just with the basics, we're\n

we'll install c++, we'll get you guys set\n

how to write your first program, then we're\n

we'll start looking at things like variables.\n

a couple of different programs and some little\n

into the thick of it, we're going to learn\n

things like loops, and if statements and classes\n

going to cover all of the core concepts, not\n

programming in general. So the knowledge you\n

to carry over to potentially other programming\n

able to bring you guys tutorials on c++, it's\n

in. And it's a good first language to learn\n

stick around for this course, you can kind\n

And hopefully you guys can learn something\n

I'm going to show you guys how to get everything\n

to start working with c++, and started writing\n

actually have to do a little bit of setup,\n

our computer. The first thing we're going\n

just going to use this text editor in order\n

is going to work. Generally you don't want\n

Google Docs, you're gonna want to use just\n

like Notepad, I'm going to show you guys a\n

for integrated development environment. And\n

just a an environment that's really awesome\n

going to need in addition to a text editor,\n

specifically a c++ compiler. And this is a\n

that we write, and it will translate it or\n

is going to be able to understand. So as long\n

c++ compiler, then we're ready to start programming\n

to get all that set up. First thing we're\n

I'm over here on this website called codeblocks.\n

is what's called an ID. So it's an integrated\n

just a special environment, special text editor\n

is going to be exactly what we need. I'm just\n

see there's a few options one says download\n

we're going to click download the binary release.\n

you can see there's a link over here for Windows\n

links for Linux and Mac, let's click on this\n

there's a bunch of these different options.\n

this one over here that says codeblocks 1601\n

this is it's going to include not only the\n

to include that c++ compiler that I was talking\n

in this one download for code blocks. So this\n

So let's go ahead and download this, I'm just\n

link for SourceForge. And this should start\n

codeblocks has finished downloading, let's\n

to head over to my downloads folder. And we\n

it says codeblocks 1601 m i n GW setup. Let's\n

installer window. So let's click through this\n

the default options. And they should start\n

once code blocks has finished downloading,\n

to start writing in c++. And you can see over\n

next tutorial we're going to talk about how\n

get started writing c++. In this tutorial,\n

set up. To start working with and start writing\n

we're actually going to need two different\n

is a text editor where we can write our c++\n

any text editor that you want. So a lot of\n

or maybe a different text editor. In our case,\n

ID, which stands for integrated development\n

codeblocks. That is specially designed for\n

guys how to download that, we're also going\n

be a c++ compiler. And basically, this is\n

we write, and it translates it into a language\n

we want to run our programs, we want to, you\n

we can use this compiler to translate the\n

first thing I want to do is show you guys\n

that if you're on Mac, you might already have\n

search bar. And we're just going to type in\n

And this should open up the terminal. This\n

we can use to interact with the computer using\n

to see if we already have the c++ compiler\n

hyphen, V. And just click enter. If you have\n

be using installed and all this stuff should\n

everything. If this doesn't come up. In other\n

have it, all you need to do to get this is\n

and this is going to go off and install everything\n

Enter. And I already have these installed.\n

can see I already have them installed. But\n

then this will basically just prompt you to\n

running, then you can just check to make sure\n

hyphen, V. And make sure that you have it.\n

and we've run this Xcode, select Install command.\n

So like I said, we're going to be using a\n

really, you can use any text editor that you\n

browser, and I'm over here on this website\n

we can download this program code blocks,\n

there's a couple options, you want to click\n

release. So I'm going to click this. And you'll\n

click on Mac OSX. And this will bring us down\n

contains the codeblocks application. Over\n

I'm just gonna click this. And this should\n

file for us. When codeblocks is done downloading,\n

folder, and we'll see what we got. So we just\n

click it. And you'll see over here we get\n

do is take this and drag it over to your Applications\n

application we want to use, then you have\n

c++. So in the next tutorial, we're going\n

going to set up our first c++ file, and then\n

set up and ready to go. In this tutorial,\n

c++ project up and running in code blocks.\n

And this is sort of like the welcome screen\n

over here, there's a couple options. One says\n

we're going to do. So before we're gonna start\n

how to get a c++ project up and running and\n

Create new project. And this should open up\n

there's all these different options. And these\n

applications that we can create. We're going\n

come over here and click console application.\n

to click Next. And over here, you'll see we\n

we want to click c plus plus. So I'm going\n

this project a title. So I'm just going to\n

storing it inside of my desktop if you want\n

can put it wherever you want. Let's click\n

a bunch of options. You can just leave these\n

Once we click finish, then our c++ projects\n

our little Tree Viewer, you'll see that we\n

of the sources folder, we have this file main\n

stands for c++. So I'm just going to right\n

And you'll see over here we have a bunch of\n

file. So this is essentially just like the\n

mean, this is what we call like a Hello World\n

printing out hello world onto the screen.\n

this stuff up here is, really, let's just\n

actually going to print something out for\n

actually going to come up here in my editor,\n

option, when I click this, a window should\n

like, Hello World, you'll see down here, this\n

hello world. So let's just go over some basic\n

to run a program in c++, we're going to build\n

program. Building the program basically means\n

and we're converting it down into a language\n

thing we always have to do is build the file,\n

basically means we're telling our computer\n

wrote in our program. And there's a bunch\n

blocks, you can click this little cog wheel\n

then you can click this play button over here,\n

of times, if you just wrote some new code,\n

click this build and run option. And for the\n

going to be whenever I say we're running the\n

and we'll build it and run it at the same\n

c++ file. In next tutorial, we're going to\n

going to look at writing some of our own instructions,\n

kind of dive a little bit deeper into you\n

now, we have everything set up. So we have\n

c++ file called main dot cpp, and we're ready\n

going to talk to you guys about the basics\n

to talk generally about what programs are\n

to write a little program, which is going\n

is going to be pretty fun. Down here, I just\n

created my c++ project, in the last tutorial,\n

was kind of given to us. And this is, you\n

So I'm going to walk you guys through essentially\n

a couple different things, and then we'll\n

these two lines of code. This is like hashtag\n

named scape STD. Essentially, what this does\n

for our c++ file. As a beginner, like, you\n

this stuff is or what it's doing. We're going\n

the course. But for now, just know that you\n

our programs. Down here we have this line,\n

close parentheses. This is actually what's\n

too much about what a function is, I'm just\n

of familiar with hearing them. But essentially,\n

to put the code inside of our c++ programs.\n

function because any lines of code that we\n

of code that we put in between these open\n

to get executed when we run our program. So\n

return zero. And again, don't worry too much\n

to have this in this main function. Over here,\n

this says c out. And then it says hello world,\n

of code in our program. So again, any lines\n

brackets for this main function is going to\n

I was to come up here and run my program,\n

run option right here, you'll see when the\n

you'll see this little window that opened\n

And the console is basically just a little\n

we run our c++ code, this console window is\n

c++ that we want to print things out onto\n

referring to the console, I'm just referring\n

and start talking about programming. So again,\n

is going to get executed. And here, we just\n

do is I can copy this and down below here,\n

like my name, Mike. And now when I run this\n

both of these things. So here on the first\n

over here on the second line, it prints out\n

how we could print something out to the console.\n

stands for console out. And then over here,\n

end L and this stands for end line. And basically,\n

we're going to print out text. So you'll notice\n

on the next line, we printed out Mike. So\n

going to show you guys how we can write a\n

out onto the screen. So I'm actually going\n

I'm just going to copy this guy here a couple\n

I'm going to print out a triangle onto the\n

slash, and then we'll do a space and a forward\n

And you'll see we're kind of drawing this\n

to use vertical bars, and we're going to go\n

going like this. And down here, why don't\n

the last vertical bar, you'll see over here,\n

And each of these instructions is telling\n

line onto the console. So now when I run my\n

out this little triangle. This is a very basic\n

four simple instructions, we were able to\n

So let's talk about this. Essentially, what's\n

c++ is going and it's looking inside of our\n

do is it's going to look for this main function\n

block of code. And that's basically just what\n

block of code called main and inside of these\n

to execute all of the instructions inside\n

a program, all we're doing is we're just telling\n

giving the computer a bunch of instructions\n

for example, in real life, like you were using\n

a program, a recipe has a list of instructions.\n

then you end up with like something delicious.\n

is just a collection of instructions that\n

the computer simple instructions like this.\n

out a shape. But as we go through this course,\n

and we learn how to use them together in unison\n

tell the computer to do a bunch of complex\n

you guys about is the order that these instructions\n

the recipe, and you would start with the first\n

instruction, the computer is going to execute\n

to start with this instruction. And basically\n

telling c++ that we want to print this line\n

to do this. And then once it's done with that,\n

it's going to print this out to the screen\n

that. So actually, let me show you guys if\n

put it up here. Now you'll see when we run\n

a funky looking shape. So instead of this\n

going to print it out on the top. And that's\n

So again, all a program is it's just a set\n

That's it, it's very simple, the more complex\n

and the more ways that we're able to combine\n

more complex Our programs are going to be.\n

to be teaching you guys all sorts of more\n

different ways to do different things and\n

applications. And you'll end up learning a\n

going to talk to you guys about using variables\n

programs in c++, we're going to be dealing\n

And a lot of times when we're dealing with\n

of hard to keep track of. and a variable is\n

different pieces of information or different\n

it a lot easier for us to manage and maintain\n

guys an example. And we'll show you guys basically\n

them in c++. So down here, I have a very basic\n

down here, I'm basically just printing out\n

was a man named George, he was 70 years old,\n

being 70. So this is basically like my little\n

And this is a valid program in c++, it basically\n

of our information. So you know, this is a\n

But let's say that I'm looking at my story.\n

the character's name, right. So maybe I don't\n

it to a different name. So what I could do\n

it in each line of code. So I could come here\n

Let's say we want to change the character's\n

john. I'll keep looking through the story\n

it to john. And there we go. We've changed\n

it. Let's say maybe now I'm thinking to myself,\n

bit younger, instead of 70. Why don't we make\n

go in and manually change the value of 70\n

say he was 70, which changes to 35. And we'll\n

change that to 35 as well. So now we've officially\n

name, and we've changed the character's age.\n

those changes, I had to manually go through\n

where the characters name showed up or the\n

instead of having a story that was only four\n

of lines. And we mentioned the character's\n

age hundreds of times, well, all of a sudden,\n

manage those pieces of information. So it's\n

name and the character's age. Right, if I\n

and we mentioned the character's name 100\n

update that name would be a very tedious task,\n

just do it manually. This is where something\n

our programs, we're going to have different\n

that we want to keep track of, and we want\n

we can take those pieces of information, and\n

variables. And variable. Like I said, it's\n

of data. And we'll make it a lot easier for\n

our programs. So I'm gonna show you guys how\n

the characters name and the character's age.\n

like this. So over here, I'm going to create\n

in c++, we actually have to tell c++ a couple\n

is what type of information we want to store\n

I'm going to talk to you guys all about the\n

c++. But for now, I'm just gonna show you\n

data that we can store inside of a variable\n

it's a string of characters. So it's like\n

saying There once was a man named john, this\n

program, a lot of times we're going to be\n

a string variable. In other words, I'm going\n

value. So I'm just going to say string. And\n

c++. The next thing we have to do is give\n

So what we want to do is give this a descriptive\n

inside of the variable. So I'm just going\n

And what I can do now is I can give this a\n

to and now we can type in the character's\n

Alright, so once we've created this character\n

this string value is now stored inside of\n

we're going to do is create another variable\n

to storing data in the form of a string, we\n

number. So what I can do is I can store it\n

an integer is basically just a whole number.\n

this character age. Now I want to show you\n

what we did is we said string character name,\n

But what I could also do is put a semicolon\n

we're writing lines of code in c++, every\n

want to put in this semi colon. I'm not sure\n

the semicolon basically tells c that we're\n

one line of code from another. So you need\n

But with a variable, what I could do is I\n

same thing for string. And then I could go\n

value. So I could say like, character age\n

in a number. So we said that john was going\n

we use numbers, we don't have to surround\n

out the number. So now we have two variables,\n

can create them. And what we can do is we\n

And you'll see how this makes it a lot easier\n

want to do is we want to replace every instance\n

age with the variable. So instead of just\n

this variable. And the way that we need to\n

variable. So over here, I'm printing out this\n

plain text, right. But let's say instead of\n

I want to instead print out the value that\n

what I can do is I can just get rid of john.\n

And what this is basically going to tell c++\n

going to type out here, so I'm just going\n

telling c++ that we want to take this value,\n

of this line of text. So when I go ahead and\n

still printing out there once was a man named\n

john, all I did was include this variable\n

we want to put the variable right in there.\n

of one of these print statements. So over\n

just going to say less than less than character\n

character name. In other words, it's going\n

name variable. at this position, we can do\n

the characters age, I'm going to get rid of\n

than, and now, character age. And so the value\n

to get placed right in there. And we have\n

age. So over here, I'm going to get rid of\n

So you'll see over here, we want to insert\n

right in between all of this text. So I want\n

make two quotation marks. And essentially\n

going to be its own string of text. And this\n

I can make to less than signs, I can type\n

going to make two more or less than signs.\n

all of these together. So it's gonna say,\n

inside of the character age variable, then\n

every instance of the characters age, and\n

those variables. Let's run our program and\n

have the same exact story as we did before,\n

old john 35. So without having to manually\n

values. And now what's cool about variables\n

or update the character's age, all I have\n

if I wanted to change the character's name\n

50 years old, I only have to modify the values\n

automatically update down in our story. So\n

using the name Tom. And it's saying that he's\n

way that we can use these variables. Another\n

do is modify the value. So let's say that\n

the character's name. So halfway through,\n

all I have to do is say, character name. And\n

So I could give this the value of Mike. And\n

at the end of this line of code. And now you'll\n

name is going to change. So it says There\n

using the name, Mike. So not only was I able\n

values, but I can actually modify those variables\n

pretty awesome. Now, this is just sort of\n

are containers, they allow us to maintain\n

in our programs a lot better. And they also\n

a value once so I can assign a value once\n

it in different places down here. I can also\n

my programs. So in this tutorial, we talked\n

as integers, which are whole numbers. In the\n

all of the different types of information\n

we can create in our programs. In this tutorial,\n

data types in c++. a data type basically just\n

that we can use and work with inside of our\n

of information, we can store like text, different\n

values, all sorts of stuff. And I'm gonna\n

those are and how we can use them. So the\n

just going to be to create a bunch of different\n

data that we can work with in c++, we can\n

just going to create a couple of different\n

how this is going to work. So the first data\n

a character. And a character basically allows\n

way we can create a character variable is\n

this a name. So let's just call it like grade\n

we're going to use these single quotation\n

that I would want inside of here. So you know,\n

of, you could store in here, and then we're\n

basically like the character data type. And\n

there's going to be a lot of situations where\n

one. And what we can actually do is use something\n

just a string of characters. So it's, instead\n

a bunch of different characters. So this would\n

we would see in a program. So I could just\n

phrase. And when I create a string, I can\n

say, like, draft Academy or something. And\n

of just one character, a bunch of different\n

where you might want to use either like a\n

think strings are probably a little bit more\n

plain text, we can also store and work with\n

types of numbers are two basic types of numbers.\n

numbers. Some people will also call those\n

like a counting number. So think like 12345,\n

numbers, there's no decimal points, right?\n

0.5, or 1.267, or 10. Point 11. You know,\n

after it. When we work with these different\n

between them. So the first type a number we\n

say int, and this could be like an age or\n

we can just type out the number so I could\n

any quotation marks. I don't need anything\n

out the number. In addition to positive numbers.\n

we're using an integer, you can't have a decimal\n

these are just going to be solid whole numbers.\n

two basic options. So there's two data types\n

first is called float. And this basically\n

The second one is called double. Now you'll\n

data types, the main difference is just how\n

can store more decimal points than a float.\n

as far as like how many decimal points you\n

use a double. And I would say for the most\n

doubles, floats will be used more in specific\n

learning this language, really just worry\n

GPA. And I can set this equal to like 4.5,\n

decimal number that I wanted. Keep in mind,\n

have to be like a different number decimal.\n

no problem. So ants are going to be what we're\n

part doubles are going to be what we're going\n

text and numbers. And just with those two\n

and strings and an instant doubles. You can\n

in your programs. But c++ is awesome. So they're\n

which is called a Boolean. And a Boolean is\n

A Boolean is actually what we would call a\n

programs, there's actually going to be a lot\n

to represent true or false data. And a Boolean\n

Right. So I could say B o L stands for Boolean,\n

right, so this variable is male is going to\n

And this will basically tell us whether or\n

say true, because I am a male, right. So you'll\n

different things like, we could say something\n

And that allows us to represent a certain\n

over here. And that's going to be the opposite.\n

these true false values. And we can use Boolean\n

are the basic data types. Now there's a couple\n

But I think 99% of the time, as a beginner,\n

don't concern yourself with anything that\n

are just decimal numbers, and which are whole\n

chars, which are just single characters. That's\n

we go forward in the course, we're going to\n

information. Now, I want to point out one\n

a little print statement here. And you know,\n

to, I could print out any one of these variables,\n

And this is going to go ahead and print that\n

just printing out a, but we don't have to\n

So if I wanted, I could just type in a string\n

a variable. And this is what we would call\n

of a variable, I could also you know, type\n

like 4.5. Or I could type out an integer.\n

don't have to put these things inside of variables,\n

up like that. And this is what we would call\n

to want to store information in variables\n

when you do that, you have to declare the\n

of data you want to work with. In this tutorial,\n

and outs of working with strings in c++. And\n

common types of data that you're going to\n

strings are basically just plain text. So\n

or work with in our program is going to be\n

see I have this little program set up basically\n

I can create a string is just by using an\n

So I can basically type out whatever I want.\n

You'll see now I'm printing out draft Academy\n

see that we Drop Academy and Hello. First\n

to do with this see our line of code over\n

right here. And basically when we put end\n

print a new line after we print whatever is\n

I just said, See our draft Academy. Now, what\n

on the same line as draft Academy, because\n

line. If I wanted to, though, I could actually\n

by saying a backslash n. So backslash n basically\n

So this inside of a string represents the\n

program, you'll see that Hello gets printed\n

that backslash n inside of our string in order\n

is doing. And if I wanted, I could put this\n

put them on a new line. So in addition to\n

here, I could also store a string inside of\n

variable, I can just say string, we'll give\n

and I could set it equal to whatever I want.\n

then I can do exactly what I did down here.\n

now it'll be printing out draft Academy onto\n

to just printing out strings, and kind of\n

of variables, we can also use what's called\n

that we're going to get into more later in\n

But for now, just know that a function is\n

we can call, which will perform a specific\n

of things. And there's a lot of functions\n

called string functions. So these functions\n

give us information about the strings. So\n

first string function that I want to show\n

have to do to use this is I can just come\n

print out the result of using these functions.\n

to say phrase dot length. And I can make an\n

when we're calling a function and see, we're\n

to type the name of the function. So this\n

make an open and close parentheses like that.\n

see we're getting 15. So this is basically\n

of this phrase, strings, how many characters\n

to, I could actually access individual characters\n

to access just this G. So I wanted to print\n

can make an open and closed square brackets\n

put zero and zero is going to refer to this\n

I run my program, you'll see we're just printing\n

this R, for example, I could say two, and\n

I run my program, we're printing out our as\n

on yet, whenever we're indexing a string,\n

index positions to each one of these characters\n

position zero, I is an index position one,\n

etc. So whenever c++ is indexing a string,\n

start counting basically 01234. Even though\n

it's technically at index position zero. So\n

we're referring to like a specific character,\n

is going to start at zero. Another thing I\n

a specific character in a string. So I could\n

character inside of this string. So we could\n

a new value. So I can assign this the value\n

these single quotes, so I could say like,\n

FFP, it's going to say, Be IRA FFV because\n

in this string. So now when we print this\n

of draft Academy, so that can be kind of handy\n

of a string. We could also find out information\n

we can find out the length of the string But\n

not a specific string or a specific character\n

dot find. And I can make an open and close\n

open and close parentheses, I'm going to give\n

of information. So I'm going to give it some\n

And these are called parameter. So anytime\n

we call it passing parameters. Or you also\n

arguments, or passing parameters, basically,\n

function. So this fine function, I need to\n

thing I can do is give it a string or a character\n

it to find Academy. So basically, I want to\n

of this phrase string up here. The next argument,\n

to be an integer. And it's going to be the\n

I wanted to just check to see if it was in\n

to check to see if Academy occurred after\n

just say zero. So now, this is actually going\n

at what index position inside of this string\n

program, you'll see over here, it's giving\n

starts at index position 012345678. So Academy\n

why it gave that back to us. So I could do\n

or something. And now this will tell me where\n

starts at index position four. So that can\n

way to find the figure out of different things,\n

you're working with. There's one more string\n

is called substring. So it's just phrase.su.\n

parameter. So we're going to give this two\n

information we're going to give this is a\n

take, you know just part of this string, so\n

the characters after this a or I can specify\n

zero from index position one all the way to\n

like just a subsection of this string. So\n

a starting index, so I could say like eight.\n

a new string at index position eight, then\n

going to tell substring, how many characters\n

is basically going to start at index position\n

a, and it's going to grab three characters.\n

a. So now when I print this out, you'll see\n

what we do. So this is the starting index,\n

things we could do is we could actually take\n

So I could say like, string, phrase sub, just\n

and I could say phrase sub is equal to, and\n

substring. And now if we print it out phrase\n

storing the value of the substring in another\n

that's really the basics of working with strings.\n

that I left out, you know, I could spend an\n

things we could do with strings. But I think\n

you all the basic things that you can do,\n

about grabbing individual characters, we talked\n

that should be a good introduction into working\n

to talk to you guys about working with numbers\n

and C, one of the most common types of data\n

to be numbers. So these can be things like\n

I'm gonna give you guys a full overview of\n

the basics, we'll look at how we can use different\n

mathematical operations with our numbers.\n

Now, down here, I'm just going to talk to\n

two types of numbers and see that we deal\n

whole numbers are basically referred to as\n

to as two things either floats or doubles.\n

know about that as a beginner is that doubles\n

So the double you can store you know, potentially\n

there's more differences. But if you want\n

it up. But the basics of using numbers as\n

for example, print out the number 14, you\n

it in and we can print it out, we can work\n

we could use negative numbers, if I wanted,\n

are very simple, you just kind of type out\n

math. So for example, I could say like five\n

five and seven, this is actually going to\n

print out the result of five plus seven. So\n

use addition, we can also use subtraction,\n

this forward slash, and we can use multiplication,\n

was to multiply these two numbers, now you'll\n

four basic math, you know operations. So that's\n

thing I want to show you guys, which is called\n

will basically give us the remainder of dividing\n

I made this percent sign, and actually this\n

we would read this 10 mod three, what this\n

by three, and then it's going to give us the\n

give us the remainder, so 10 divided by three\n

So now we just we should just get one. And\n

that modules operator can come in handy, you\n

C. So C is going to adhere to like the normal\n

Please Excuse My Dear Aunt Sally, basically\n

to come before addition and subtraction. So\n

times 10, this is going to do five times 10\n

we get 54. But if I wanted to do the addition,\n

this. So now it's going to do five plus four,\n

you can see we do so if you need to separate\n

just following basic math order of operations\n

that. So in addition to doing all that stuff,\n

numbers inside of variables. So I can make\n

number. And we'll just make this five. I could\n

de nom for decimal number. And this would\n

these numbers inside of variables. If I wanted,\n

like we did down here, I want to show you\n

is incrementing, a number that's stored in\n

I could say plus plus. And what this is going\n

So now when we print out w num instead of\n

we're adding one to it. So you can see we\n

in handy a lot. There's a lot of situations\n

also do like minus minus, and that will subtract\n

equals, and we could say like 80. And so what\n

w nom and it's going to add 80 to it. So now\n

do plus equals multiplication equals minus\n

and all of that will it's just basically shorthand\n

So now that we kind of looked at all the different\n

and integers work together. So here's a little\n

I added 5.5 plus nine, so I'm adding a decimal\n

right, so let's see what happens over here,\n

number back. So anytime we're doing math between\n

and an integer, a whole number, we're always\n

always going to give us the decimal back.\n

math with two integers, so for example, let\n

by three, and these are both integers. Keep\n

number back. So we're going to get like three\n

But here's the thing. This isn't actually\n

with a remainder of one. But because we did\n

get an integer value back. If I was to make\n

made both of them a decimal, a decimal number.\n

full answer. So it's going to be three with\n

see if we do math between just two integers,\n

if that's not like fully the correct answer.\n

to want to do that in other circumstances\n

that's kind of how integers and decimal numbers\n

to do is show you guys how we can use different\n

math, there's all sorts of different, like,\n

root, you can take a number to a power, we\n

these things called functions, which can do\n

just a collection of code that we can call\n

going to talk more about functions later.\n

math functions that we can use. In order to\n

to do something called importing them. And\n

basically going we're telling c++ that we\n

So up here, you can see we're using this include\n

iostream, I'm going to add another line here,\n

just going to copy this guy up here. And we\n

sign. And in here, I just want to type in\n

to do is it's going to tell our c++ program\n

kind of all you need to know at this point,\n

in order to follow along with what I'm going\n

a bunch of different math functions, essentially\n

say like POW. And what this will do is it'll\n

two numbers, like I could pass a two, and\n

is it'll take two raised to the power of five,\n

when I run my program, you'll see we're getting\n

And you can kind of do that with any number.\n

third power, so three cubed, and now we should\n

can be pretty useful. There's another one\n

So we can say like square root 36. And now\n

36 back, which is going to be six. So that\n

functions, we you can put a decimal numbers\n

numbers and also decimal numbers. There's\n

going to round a number. So if I put like\n

number. So you see, we just get four and this\n

change this to 4.6, now we should get five\n

which will similarly like round decimal numbers,\n

automatically just round the number up. So\n

the number up to the next highest whole number.\n

the opposite, which is floor. So if I just\n

it's supposed to round up, but now it's going\n

or that floor function. So those can be pretty\n

you guys, which is called f max. And f Max\n

in like a three and a 10. And this will tell\n

back to us the bigger of the two numbers.\n

it's giving us a 10 back because 10 was the\n

in C, you're going to have two numbers, you\n

can be really useful to tell us. And you could\n

So this will tell us what the smallest number\n

get three over here. So those are some basic\n

just go online and search c++ math functions,\n

that you can use. There's things to do like\n

stuff you can do, you can use like exponentials\n

useful. But that's kind of the basics of how\n

are extremely useful. And that's kind of been\n

you can do with them. In this tutorial, I'm\n

a user in c++. A lot of times in our programs,\n

types of information. But one of the most\n

be information that the user inputs. So a\n

allow the user to input information. And then\n

in order to do different things. So in this\n

of how that's done, we'll talk about how to\n

know, you'll kind of learn everything you\n

getting information from the user, the first\n

somewhere. So whenever I'm asking the user\n

give me that information, and I don't put\n

so we usually what we want to do is create\n

a little program that will allow the user\n

a integer just called age. And I'm not going\n

a semicolon there, we're essentially declaring\n

want to use this integer, but we're not giving\n

this variable a value. The next thing I want\n

in something right. So if I don't give them\n

I want, then they're not going to know what\n

C out. And I'll just print out a little prompt,\n

basically just prompting them to enter in\n

the variable, and once we've prompted them\n

do is we can actually get the information\n

is actually the opposite of the way that we\n

c out, I'm just gonna say C n, and I'm gonna\n

C out, we use these lesson signs, when we\n

that's really important. So over here, I'm\n

that I want to store what they enter inside\n

I want to store whatever they input into this\n

going to enter in an integer number, and I'm\n

of this integer that we created. Now, what\n

So we'll print out a little message to them,\n

say like age, or we can say like, years. Old.\n

to enter in their name, we're taking whatever\n

this age variable, we can do that using the\n

out You are the age years old. So let's go\n

we did. So I'm going to build and run. And\n

we can just put like 30. And now when I click\n

we entered in 30, it's going to store it inside\n

the prompt. So when I click enter, you'll\n

awesome. So we can do that and we can get\n

if I made this a double, it would be the same\n

I can enter in like 4.5. So maybe someone's\n

entering in 4.5. So it's gonna work the same\n

for characters. So if I made this a sharp,\n

to get a character from them as well. So now\n

in like a G, for example, whatever, obviously,\n

So it's able to take in that character, and\n

that's how we can get characters in numbers.\n

actually going to do something different.\n

not going to use this C in command. So I'm\n

So instead of entering in the age, why don't\n

here, I'm going to make a string, and I'm\n

C and I'm going to use another command, which\n

allow us to get an entire line of text. So\n

one character, we're going to get like the\n

we need to pass this a couple of different\n

And c n is basically just that little like\n

stuff into that command prompt, that's basically\n

in the name of the variable where we want\n

I'm just going to store inside of name. So\n

So I could say hello. And it's going to be\n

from the user. So we're basically get the\n

here I can say like john smith, and now when\n

So that's how we can get strings of text.\n

to get like an integer and store it inside\n

a char and store it inside of a char variable,\n

get like a string of text, then I can use\n

to be useful. So that's kind of an overview\n

you can get as many values as you want. And\n

this whole line, paste it a bunch of times\n

different pieces of information and use them.\n

how to build a basic calculator in c++. Essentially,\n

user can enter in two numbers. And then we'll\n

the answer. So this is going to be kind of\n

more about getting input from users. So down\n

we do anything is create two variables, where\n

to add together. So I'm going to create an\n

one. And I'm not going to give this a value\n

give this variable a value, I'm going to create\n

actually, let me show you guys something cool,\n

like this. And they're the same data type,\n

So I could say num, one, comma, num, two.\n

useful. So for example, I could do like as\n

going to have two numbers, though. So now\n

the next thing we want to do is prompt the\n

to say C out. And the first thing we'll do\n

say enter first number. And now we want to\n

So I'm going to say cn, and over here, I'm\n

to store the number that they enter inside\n

just copy this. And we're going to do the\n

say enter second number. And now instead of\n

this point in our program, we should have\n

both of those numbers from the user, the last\n

answer. So we can actually just say, C out.\n

two together. So we should be printing out\n

So let's go ahead and run this program. And\n

and run. And actually Whoops, I put the wrong\n

probably a really common mistake with C and\n

to less than signs. So that's something that\n

me up. So when we're using C and we're using\n

C out we're using these two less than sign.\n

kind of highlight a common mistake for beginners\n

programmed in c++ a lot before. Alright, so\n

first number, so enter in a five, enter second\n

enter, it should add both these numbers together.\n

cool. Another thing we could do is instead\n

doubles. And that's as easy as just changing\n

run the program, we can work with double.\n

enter in like a 9.8. And now we'll be able\n

of cool. And really, that's a basic calculator.\n

up here, we're using C out. And with C out\n

then we're using cn with the greater than\n

the use the input from the user. And it's\n

doing that twice. And because we store these\n

to add them together and print out the answer.\n

Actually, later in the course, I'm going to\n

calculator that will be able to add, subtract,\n

to decide in order to build something like\n

stuff. So stick around, and we'll learn how\n

In this tutorial, I'm gonna show you guys\n

So a Mad Libs is basically a little game where\n

be like nouns, verbs, adjectives, and then\n

into a story. And generally since you entered\n

funny. So let me show you guys over here in\n

you know, essentially there's this story and\n

words that the person entered into the story.\n

in our c++ program. Down here, I have my little\n

it says Roses are red, violets are blue. I\n

a classic poem. But I think this could be\n

So let's say instead of saying Roses are red,\n

instead of saying violets are blue, we'll\n

of saying, I love you, let's say I love celebrity,\n

So basically, we're going to ask the user\n

store them in variables, and then we can print\n

started, this should be kind of cool. The\n

variables for all these things. So I'm just\n

for the color for the plural noun and for\n

told c++ that we're going to use all these\n

And we're actually going to let the user give\n

The first thing we want to do when we want\n

say C out and we're gonna print out a prompt,\n

So we're gonna have them enter in a color,\n

they input, so I'm just going to say, Get\n

N. And that's basically just standing for\n

input text into the console, so it's gonna\n

then we're gonna store it inside of this color\n

that they enter. And I'm actually just going\n

for all the other values. So we're gonna say\n

inside of the plural noun variable. And then\n

for the celebrity. So we'll store that in\n

declaring the very most, we're printing out\n

from the user using this get line function.\n

of the program. So instead of saying roses,\n

color that they entered into the story, same\n

to say, plural noun, and you can see how that\n

then I love celebrity, we're going to actually\n

so now our program should be set up, everything's\n

variables, and we're printing them out, down\n

and we should be able to play our madlibs\n

Enter a plural noun, let's do microwaves.\n

Hanks. So now when I click enter, all of the\n

So it says roses are magenta, microwaves are\n

worked, and we are ready to go. So that's\n

it's it's as easy as getting different inputs\n

the story. But this is a very simple madlibs.\n

could ask the user for like 20 different words\n

And it's going to work out the same way. So\n

game. In this tutorial, I want to talk to\n

of times when we're writing programs in c++,\n

of data. And one way that we can keep track\n

called a variable. But the one thing about\n

one value inside of a variable. So if I create\n

store one character in there. If I create\n

integer in there. A lot of times though, in\n

of data. And that's where arrays can come\n

a variable. But unlike a variable arrays can\n

hold like a list of you know, 1000s, or millions\n

could put, you know, pieces of information\n

inside of the same array. So I'm going to\n

how we can work with them. You create an array,\n

the first thing we have to do is tell c++\n

of the array. So I'm just gonna make an array\n

just like a variable, we're going to give\n

right, and this would be an array of lucky\n

from a variable. When we're creating an array,\n

brackets after the name. So after lucky nums,\n

bracket. And that basically tells c++, okay,\n

to be able to store multiple pieces of information\n

to say equals, and one, the easiest way to\n

default information right off the bat. And\n

and inside of here, I can just start typing\n

So let's say I want to store like a list of\n

right, so I'm storing all of these numbers\n

a variable where we can only store one number,\n

we will refer to these as elements in the\n

the list. And then we would delineate the\n

the second element, 815 16, excetera. So these\n

array. Now down here, I'm going to show you\n

So I'm just gonna say C out. And let's say\n

elements, let's say I wanted to access like\n

because what good is the array, if we can't\n

I can just say, Lucky nums. And I can make\n

of this open and close square bracket, I can\n

that I want to access. So if I want to access\n

to put an index in here, that's going to be\n

see we're printing out four, we're printing\n

wanted to get access to this 15, it's going\n

two inside of this array. So now whenever\n

caught on by now when we index these arrays,\n

say that four is an index position. 08 is\n

three excetera. So we would always say that\n

an index position zero. And if you're familiar\n

the same exact thing. So that's how we can\n

we can also modify an element in the array.\n

say I wanted to change the first element,\n

this a different value. So I could set this\n

I print out lucky numbers, zero, I'm actually\n

whoops, I'm actually going to be printing\n

one of the indexes inside of that array. Another\n

give them a size. So normally, if I just create\n

and an empty square brackets, the array is\n

that I declare over here. But a lot of times\n

not know what all the elements should be.\n

I could say, like 20. And essentially what\n

want to be able to store 20 elements inside\n

don't have 20 elements, yet I only have elements\n

add more elements into here. So I could say\n

And I could give this a value. So I could\n

now down here, if we printed out lucky numbers\n

can see, another thing you can do is just\n

can get rid of all of these. And I can just\n

I can give all these different values. So\n

And now I can you know essentially just assign\n

I said, a lot of times you might not know\n

you declare it and so you can just basically\n

in there and then you can just you know, fill\n

the basics of arrays and arrays are very simple.\n

pieces of information. In this tutorial, I\n

in c++. A function is basically just a little\n

task. So a lot of times in c++, when you're\n

designed to do a certain thing. So you might\n

supposed to do something. And a function is\n

code, and then you can reuse it throughout\n

you guys how we can create a function in this\n

see I have this little block of code here,\n

parentheses. And then there's these open and\n

function. This is a little block of code.\n

task. And the purpose of this main function\n

we run our program. So any code that we put\n

executed when our program runs, I'm gonna\n

So up here above this main function, I'm going\n

this function will be performing is it's going\n

a function in c++, we need to give c++ a couple\n

information we need to give is called a return\n

a lot of times the functions will go off,\n

they'll return a value back to the caller.\n

returns and return types in the next video.\n

kind of just follow along. And I'm just going\n

put void here, it basically means that this\n

So this is kind of like the most basic type\n

need to give this function a name. Remember,\n

a task. So generally, when we're naming a\n

according to the task that is performing or\n

So I'm just going to call mine Say hi, because\n

Now I'm going to make an open and closed parentheses.\n

and closed curly bracket. Any code that I\n

is going to be considered inside of the function.\n

C out, and we'll just print out like Hello,\n

this is a very simple function, I just have\n

lines as I want. This is a simple function.\n

100 lines, if I wanted to, you can put as\n

want. Now, let's run our program. And we'll\n

and run my program. And you'll see over here,\n

isn't actually getting printed out when we\n

we want to execute the code that's inside\n

want to execute a function, we have to do\n

this code inside of here to be executed, I\n

code inside this main function gets executed\n

is going to get executed. So inside of here,\n

type out say hi. And I can type an open close\n

this out, this tells c++ that I want to execute\n

hi function. So when c++ sees this, it's going\n

to execute all the code inside of there, and\n

go ahead and run our program. And we'll see\n

we're printing out Hello, user. And real quick,\n

flow of the so if I said like C out over here,\n

over here, and I said bottom. When I run my\n

top, hello, user and then bottom. And actually,\n

put new lines in there. But the point is that\n

execute this line of code, it's going to see\n

And it's actually going to leave this main\n

Say hi function, it'll execute all of the\n

of code to execute inside of the say, Hi function\n

and execute this line. So that's basically\n

is a very basic function, but we can make\n

With these functions, you can actually give\n

Say hi function, I can give this a piece of\n

that piece of information to, you know, performance\n

these are called parameters. And if I want\n

be given a piece of information, I can just\n

it should take. So, in our case, instead of\n

hello to someone specific. So up here, I could\n

going to accept one parameter a name. And\n

we can just say hello name. Now, whenever\n

it's specifying that it needs to take a parameter,\n

it a value. So in here, I can just pass it\n

Hello, Mike, because the value Mike is going\n

Alright, let's go ahead and run our program.\n

Mike. So that's kind of cool. And you can\n

and you can also take multiple parameters.\n

like age, so now the caller is going to have\n

we can say hello name, will say like you are.\n

So we'll say like age. So now we're passing\n

function. And down here, when I call the function,\n

So now I could just say, like, Mike, and let's\n

function, it's going to be able to take in\n

them to perform the task differently. And\n

call this as many times as I want. In other\n

up here. So I can come down here, I can copy\n

we'll say like, Tom is going to be 45. And\n

now, I'm actually going to run this code three\n

I'm just going to put a and line so that gets\n

the program. And you'll see it says hello,\n

functions are great, because we can reuse\n

So basically, like I wrote this function one\n

I want inside of my program. So anytime you\n

that's a good candidate for a function. Alright,\n

you'll notice that I'm creating this function\n

if I was to take this and move it down here,\n

function. Now when I run my program, we're\n

a little red block here. This is the problem,\n

function, it doesn't actually know about it.\n

executed. So c++ is trying to execute the\n

that is because we created it down here. So\n

called a function stub. So up here, we're\n

signature, and we're going to tell c++ about\n

a variable, like if I created an int, and\n

this a value right away, I could then come\n

or something. This is basically what we're\n

just declare the function and then somewhere\n

over here, I'm just gonna say, void, say hi.\n

int age. So now, when I create this little\n

I'm basically declaring the function and I\n

is going to be able to call it because it's\n

when I run my program, now, we're able to\n

how we can do that with functions. And really,\n

In fact, a good program will have lots and\n

I'm going to show you guys how we can actually\n

the return keyword. In this tutorial, I want\n

So when I'm talking about returns, I'm talking\n

can write functions which are basically like\n

that performs a specific task. And with those\n

pass them information. So I can give them\n

information that they can use to perform their\n

information functions can actually give us\n

not only can I give it parameters, but that\n

Now I'm going to show you guys how we can\n

in c++. So why don't we create a function\n

that's going to cube a number. So when I cube\n

power. So if I was to say like, two cubed,\n

power, or it's just going to be two times\n

number does. So why don't we create a c++\n

when we create a function in c++, the first\n

called a return type. And a return type basically\n

type, this function is going to return. Now\n

along with the course, we just put void here.\n

wasn't going to return any information. In\n

to return some information. So you can put\n

put like int, double, you put character, you\n

can go here. In our case, we're going to cube\n

And I'm going to say double. And now we need\n

call it cube. And we're going to take one\n

we take a double, and we'll just call it num.\n

to do is cube the number and then return the\n

to create a double, I'm going to call it result.\n

value of num, so I'm just gonna set it equal\n

me cubing num. So now result has inside of\n

okay, down here, I want to return the value\n

just say return result. And now this is going\n

stored inside result back to the caller. Now\n

call this function so I could say cube and\n

Right? Now, actually, what's going to happen\n

it's actually going to get a value back. So\n

answer is equal to cube 5.0. And now the value\n

is going to get stored inside of this answer\n

C out, and I'm just gonna print out answer.\n

see is, we're going to be printing out the\n

here, we get 125. So five times five is 2525,\n

number. And you can see here, this is getting\n

that gets returned from this function inside\n

cut out the middleman and I could just print\n

boy down here. And now it's going to do the\n

And actually up here, if we wanted, instead\n

of this result variable, I could instead just\n

cut out the middleman. And we'll just return\n

So there's also one more thing I want to talk\n

this returned keyword right here. This is\n

whenever we type out this return keyword,\n

executing the code inside of this function.\n

I just printed out like hello. When I run\n

printing out Hello, even though we're executing\n

all that code, it's never printing out Hello.\n

keyword, it's going to break us out of the\n

never going to get executed because it's never\n

is is going to break out and we'll head back\n

what this is doing. And that's sort of the\n

you didn't want to return a double, you could\n

you can even return something like an array.\n

And then that value will get stored over here.\n

guys about if statements in c++, an if statement\n

our code, which will allow our program to\n

situation occurs, we can do one thing. And\n

thing, essentially, we're able to check different\n

true, we can do certain things. And when those\n

So I'm going to show you guys exactly how\n

I'm just going to create a couple of different\n

is create a variable, it's going to be a boolean\n

a true or a false value, so I'm going to create\n

give this a value initially of true. So we're\n

storing whether or not someone is male, and\n

to show you guys how we can use an if statement.\n

to respond to different situations. So what\n

write an if statement that will respond to\n

the situation where the user is not a male.\n

I'm going to make an open and close parentheses,\n

curly bracket. Now, inside of this open and\n

So I can actually check a condition. And if\n

and close parentheses is true, then we're\n

If it's false, then we're going to move on.\n

true or a false value. And that's basically\n

So I'm gonna come down here, I'll say if and\n

what this is saying is if the value stored\n

if the value in here is true, then we're going\n

curly brackets. So I could say, like C out,\n

a male. And now when I run my program, you\n

And you'll see over here, it says you are\n

male was true. So the value that was inside\n

parentheses, which was true, and we executed\n

see that this code isn't going to get executed,\n

out. So because the value inside of this parentheses,\n

not going to execute this code. But let's\n

wanted to handle that situation, I can use\n

type out else just like that. And we're gonna\n

inside of this open and close curly bracket,\n

when this is false. So I'm going to show you\n

right, so I'm responding to this situation.\n

I run my program, it's going to be able to\n

are not male. Essentially, what's happening\n

respond to this variable. So if this variable\n

not true, it can also handle that. And so\n

specified a condition in our case, it was\n

of this is male variable. So that's kind of\n

I want to show you guys how we can make these\n

But let's say I added in another Boolean,\n

I'm going to set this equal to true and actually,\n

So now in addition to izmail, I also have\n

to see if the person was both male. And if\n

is I can use something called the AND operator\n

what's happening now is c++ is saying If the\n

we're going to print this out. So I'll just\n

line of code down here, and any of the code\n

is only going to get executed when is male\n

this and operator is allowing me to check\n

have to be true, in order for this line to\n

true and is tall is also true. So now, when\n

you are a tall male. Here's the thing, though,\n

his tall to false, this whole condition is\n

going to go down here to this else block.\n

not male, or not tall, but we'll just leave\n

Alright, so now it says you are not male,\n

should be different. But the point is that\n

values up here was false. And that's how we\n

operator called the OR operator. And that\n

conditions has to be true, in order for the\n

tall is set to false, and his male is set\n

it's still gonna say you are a tall male,\n

and run this program. Now, you'll see it says\n

that was inside this initial if block. And\n

both of these to false now, because we're\n

you are not male. So you'll see down here\n

how we can use and and how we can use or with\n

in both of them have to be true for the whole\n

one of the conditions has to be true for the\n

be true as well. And it'll be true. But if\n

be false. All right, let's make this even\n

another thing we can do, I'm going to bring\n

and is tall. But let's say that we wanted\n

weren't tall. So if they were like a short\n

So I can use another keyword. In c++, it's\n

and close parentheses and open and close curly\n

down to a new line. So else if is basically\n

then we're going to come down here, and we're\n

condition appears false, instead of just going\n

we're going to check another separate condition.\n

male, and they're not tall, so they're not\n

so I'm saying elsif is male, and is tall.\n

not tall. And here, I want to introduce you\n

negation operator, it's basically an exclamation\n

point before a condition like is tall, it's\n

So if is tall is true, and we put this negation\n

to false, and vice versa. So essentially,\n

is not tall. That's basically what this is\n

out, you are a short male, right? Because\n

is true, that means they're male, and they're\n

one more that we can check. So I'm going to\n

more possible scenario with these two variables\n

not male. So I can say not, is male, and is\n

could be like a tall female or something.\n

and say C out, and I'll just say you are tall,\n

printing that out onto the screen. So now\n

covered. So over here in this if else block\n

down here in this else block, we would want\n

are not male and not tall. So that's just\n

right, so we're able to respond to every possible\n

So let's try this out, I'm going to set both\n

to run my program. So they're both equal to\n

to that situation, who see it says you are\n

to that, let's set his male equal to false.\n

our program, once again, is going to be able\n

tall, but not male. So the program is smart\n

depending on the value of these variables.\n

to true and is tall to false. And again, it's\n

you are a short male. And then finally, we'll\n

answer which is going to be you're not male,\n

figure this out just by using all this stuff.\n

time, we have this if statement, and it's\n

Now, these are both conditions, right? So\n

essentially, it's a true or false value, right?\n

of these are true, then we'll execute the\n

we'll come down here and we'll check this\n

that. And so we get down here, and we figured\n

tall. So that's the basics of if statements.\n

of if statements, I talk to you guys about\n

there's one more thing I want to talk to you\n

called comparisons. And down here, we're using\n

conditions right, so I'm using these, and\n

right. But we can also use something called\n

check to see if different values relate to\n

to see if like a number is greater than another\n

comparisons as our conditions. And that's\n

next tutorial. And I'll talk to you guys more\n

I'm going to talk to you guys some more about\n

to be looking at using comparisons inside\n

be kind of cool. In this tutorial, I want\n

a function, and it's going to basically tell\n

will take as parameters, two numbers, and\n

is the largest. And this is a great example\n

So over here, I have my main function. And\n

And let's just say it's going to return an\n

max. And we'll make an open and close parentheses\n

of this function, we're going to take two\n

and we'll get another integer. So essentially,\n

as input. And the goal will be to figure out\n

return that back to the caller. First thing\n

result. And I'm not going to give this value\n

this function, we're going to return results.\n

whichever of these is bigger inside of this\n

interesting. Now, we need to figure out which\n

do that. So I'm just going to say F, open\n

curly bracket. Now, inside of this parentheses,\n

we need to put a true or false value, right?\n

down here. If the value is false, then we'll\n

the last tutorial, when we were learning about\n

and a Boolean is a true or false value. So\n

in there, and it's true, or its false. And\n

But in a lot of cases, we're not going to\n

us. So it's not going to be as easy as just\n

only information that we have are these two\n

or a false value using just those two numbers?\n

So if I want to figure out which of these\n

right so over here inside of this if condition\n

than num two, if num one is greater than num\n

num one. And the reason I'm doing that is\n

if this comparison is true, the num one is\n

num, one greater than num two, it's actually\n

false value. Right? num. One is either greater\n

is going to be a boolean value, right? Once\n

out if it's true or not, it's going to be\n

check to see if num one is greater than num\n

num one. And we can just say else, and we'll\n

reason we're saying this down here is because\n

bigger than num two, then we know that num\n

certain circumstances, the numbers might be\n

So down here, we're going to return the result.\n

I'm just gonna come down here. And why don't\n

say get max. And we'll throw like a two and\n

a five. And now when we run this program,\n

I'm gonna run the program. And Yep, over here,\n

So this is basically how we can use comparisons\n

Technically, this comparison is going to get\n

to get resolved down to a true or false, like\n

And that's kind of interesting. So that's\n

greater than we could also use less than,\n

use greater than or equal to, we can use equal\n

we use the equal sign down here, we're using\n

result the value stored inside num one. When\n

operator. So I'm comparing the value of num\n

that's either going to be true or false, right?\n

or they're not. And then the last one we can\n

what you think it does. This whole thing is\n

num, two. So those are sort of the basics.\n

So this get max function takes two integers.\n

int, num, three. Now all the sudden, instead\n

figure out which is bigger among the three\n

statement a lot more complicated. So why don't\n

how we can do this. So inside of this comparison,\n

than num two, just like we did last time.\n

is bigger than num three. If no one's bigger\n

then we know it's the biggest. So let's start\n

instead of just saying greater than I'm gonna\n

is that chance where they're all the same\n

So we can say if num one is greater than or\n

this and operator and this is going to allow\n

num one is greater than or equal to num three.\n

to num two and is greater than or equal to\n

biggest. So I'm going to set result equal\n

another condition. So I'm gonna say else if\n

two is greater than or equal to num one. And\n

And if this is the case, in other words, we're\n

of here is false. So this condition is false.\n

But if this condition is true down here, then\n

say result is equal to num two. Now all we\n

we can just say result is equal to num three.\n

num one's not the biggest. If this condition\n

biggest. So if num one's not the biggest and\n

must be the biggest. So we're going to default\n

else block that we need. And you see I'm using\n

am I using this and operator, I'm also using\n

these guys are called. So let's go ahead and\n

of saying two parameters, we need to pass\n

and we should get 10 back, which we do, if\n

So for example, I could test out, we'll make\n

we'll see if it works. And it does. And we'll\n

if it works. And it does cool. And then also\n

them were the same. So let's try this were\n

And we're on the program. And yeah, so it's\n

is our max function. And hopefully this gives\n

comparisons. Now we can compare all different\n

we can compare integers, we can also compare\n

characters. So you can compare all those guys\n

this tutorial, I'm going to show you guys\n

c++. Now, if you've been following along with\n

of the course, we created a very simple calculator.\n

take in two numbers as input, and added them\n

this tutorial, now we've learned a little\n

to build a more complex calculator. So this\n

in two numbers, but it's also going to allow\n

to perform. So they can specify that they\n

divide them, multiply them, whatever. So it's\n

So down here, inside of my main function,\n

And the first thing I'm going to do is create\n

variables. And why don't we just create these\n

if you wanted. We'll just call them num one\n

the two numbers that we want to perform the\n

going to want to create a character. And I'm\n

going to throw the two numbers here. And we're\n

either going to be plus or minus division,\n

created those two variables, we want to start\n

user. The first thing that we want to do is\n

C out. And I'll basically just print out enter\n

in the first number. And then down here, we're\n

these, these two greater than signs. And we\n

one, just like that. Okay, cool. So now that\n

copy this code, and then down here, we can\n

going to ask them for the operator. So I'll\n

the operator inside of that Opie variable\n

to enter in the second number, and we'll store\n

doing is I'm prompting the user for all of\n

to get that first number, we're going to get\n

second number. So they'd give me like five\n

like that. Alright, so now that we have all\n

that we need to do, which is we need to figure\n

here, we have the operator. So ideally, they\n

sign, whatever, but we don't know what exactly\n

what what they were going to enter in. So\n

perfect scenario for an if statement. So I'm\n

you guys how we can check this. So I'm just\n

in here. So basically, what we want to do\n

So the first thing I'm gonna do is just check\n

sign. Right? So if the operator is equal to\n

to print out the result of adding the two\n

here, and I'm going to create an integer called\n

equal to num, one plus num, two. And we know\n

is true, then we're going to execute this\n

I basically just want to check to see if it's\n

to a minus sign, and if it is equal to a minus\n

there. But we can subtract the two numbers.\n

so we can do the same thing for multiplication\n

copy this else if, and I'll paste it down\n

forward slash, that means division. And then\n

multiplication. So use this Asterix, and then\n

So now we're basically covering all of the\n

we got that covered minus sign, division sign\n

all of those standard scenarios, but there's\n

an invalid operator. So instead of entering\n

like, you know, random character, in which\n

here. And this LS block is going to get executed\n

So if none of the conditions are true, then\n

So I'm just going to go ahead and print that\n

print out invalid operator. Alright, so basically,\n

a value stored inside of result. So down here,\n

just say C out, and we'll print out result.\n

I'm going to go ahead and run the program.\n

we insert a five? Enter operator, let's enter\n

do 30. So now when I click enter, hopefully\n

be able to figure out which operation I was\n

it correctly. So you see down here, we printed\n

So why don't we try a couple other ones. Let's\n

we get 10. Yes, it looks like that's working.\n

check to see if we enter an invalid operator.\n

the operator, let's make it like a capital\n

And you'll see down here it prints out invalid\n

other little printout here. And actually,\n

we didn't give result in initial value. Alright,\n

you guys can see how we can combine getting\n

if statements to basically figure out what\n

And this tutorial, I'm going to talk to you\n

Now a switch statement is basically a special\n

one particular value against a bunch of other\n

when we're trying to compare different things.\n

statements are. And we'll do an example which\n

So in my program, In this tutorial, I actually\n

going to be able to convert a number into\n

passed in a zero to this function, I'd want\n

the user passed in a one, I'd want to be able\n

to be able to convert an integer number to\n

gonna show you guys how we can do this inside\n

my function, and we're basically just going\n

to call it get day of a week, just like that.\n

And this is going to take one parameter, which\n

call it day num. So this is going to be the\n

through six, basically. Alright, so inside\n

out how we can do this. So depending on the\n

on the day num, that they give us, we want\n

the first thing I'll do is I'm going to create\n

and I'm just going to call it day name. So\n

the name of the day that they requested. And\n

we're going to return it. So I'm just going\n

we're going to end up returning. So our goal\n

this day name variable with the correct day\n

mean, one way that we can build this function\n

like, if day num is equal to zero, and if\n

name is equal to Sunday, right? That works.\n

day of the week. So I can say like, else if\n

is equal to something else. So day num is\n

same exact thing. So we Ad name is equal to\n

single day of the week. Here's the problem,\n

times, right? Potentially eight times, if\n

I'm going to have to create eight of these\n

this out. And that is extremely inefficient.\n

for us to use something called a switch statement.\n

we're doing over here with these if else statements,\n

I want you guys to notice is in every single\n

every single one of these, if conditions,\n

num is equal to a different value. So in here,\n

we're saying Dana equal to one and the next\n

equal to three, all of those conditions are\n

else. And when you have a situation like that,\n

So I'm going to show you guys how we can use\n

So I'm just going to write out switch and\n

close curly brackets. So so far, it looks\n

opening, close parentheses, I'm going to put\n

the value in here that we want to compare\n

it's going to be daenam. Right, I'm comparing\n

is the value that I want to compare to all\n

statement, I can write cases. And basically\n

value in here. So I can say zero and a colon.\n

what I want to happen. So I could say day\n

what this is doing is it's saying in the case,\n

set day name equal to Sunday. And then right\n

I'll explain what break does in a second.\n

for every single number. So I could say like,\n

to one, I'm going to set day name equal to\n

say break. And then I can keep doing this\n

is doing down here, this break statement is\n

statement. So if I don't put this break statement\n

through all these cases. So even if daenam\n

Sunday, it's still going to keep going and\n

I say break right here. And generally, it's\n

be able to check for more than one condition,\n

num is equal to zero, we're going to do all\n

to make one of these for each day of the week.\n

we'll meet back here, and I'll kind of show\n

and made one of these little case blocks for\n

here we have zero through six. And they're\n

So in case three, day name is Wednesday, etc,\n

Now there's one more thing that we have to\n

there's always the chance that the user enters\n

words, if the user doesn't enter zero through\n

In other words, I want to be able to handle\n

isn't in here. And inside of a switch statement,\n

default. So we can just say default, a colon,\n

get executed, if none of the cases up here\n

any of these numbers up here, then this code\n

So down here, I could just say, day name is\n

we have our switch statement set up. And you\n

like an if statement. So this is a lot clearer\n

LSF like 1000 times, we don't need all those\n

it's just really clear, it's really easy to\n

see if our get day the week function is working.\n

going to print out the value. So I'll say\n

day of week and we need to pass this an integer.\n

we should get printed out here Monday. Or\n

so Sunday would be the first day of the week.\n

So I'm going to put one here instead of zero.\n

All right, let's try one more, we'll try six.\n

see if it works. Cool. So Saturday worked\n

which is where we pass in an invalid number.\n

be able to see that this isn't going to work.\n

So this is a pretty cool function. And it's\n

case statements. In order to make this a lot\n

easily done this with an if statement, nothing\n

lot easier to use something like a switch\n

in the language. In this tutorial, I'm going\n

c++. Now a while loop is basically just a\n

through a block of code, while a certain condition\n

into something called loops. And loops are\n

in our programs, specifically in c++, where\n

code and do things a bunch of times. So I'm\n

type of loop, which is a while loop. And we'll\n

Alright, so down here, the first thing I'm\n

is I'm actually just going to create an integer.\n

going to set it equal to one. So this isn't\n

loops. We're just going to use this in our\n

to create a while loop, I can basically just\n

and an open and closed, curly bracket, and\n

main outline for a while loop. Now here's\n

of these parentheses, I'm going to specify\n

about if statements in c++, this is essentially\n

a condition just like we would an if statement.\n

going to loop over and continually execute\n

brackets, as you'll see in a second, we're\n

curly brackets. And as long as the condition\n

through that code. And every single time we\n

this condition. So let me just show you guys\n

going on. So up here in these parentheses,\n

what I want to do is I'm going to say while\n

is now my condition, while index is less than\n

code inside of this loop. So I'm going to\n

So down here, what I want to do is I basically\n

just going to say, C out index. And then I'm\n

line. And then down here, I'm going to increment\n

plus. So you remember index plus, plus just\n

what I'm doing is I'm specifying my condition,\n

I want to execute all of this code. So I'm\n

sort of see already what this is going to\n

we're going to take a look at what's happening.\n

we basically got 12345. Here's what's happening\n

index, I set it equal to one and I basically\n

equal to five, I want to keep looping over\n

the first time we went through, we checked\n

is less than or equal to five. Since that\n

one on the first iteration of the loop, we\n

and then we incremented index, so index was\n

back up here and we check this condition again.\n

equal to five. In this case, index is equal\n

or equal to five. So we're going to execute\n

printed out two, and then we incremented to\n

checked the condition again, every single\n

condition. So before we execute the loop,\n

check it again and execute the code again.\n

was equal to six. So we came up here to check\n

equal to five. So Then we just came down,\n

was happy. So that's essentially what we did.\n

a condition, as long as that condition is\n

much just keep looping through all the code\n

where using loops is gonna come in handy.\n

to build a little game where we can use a\n

to talk to you guys about a couple more things\n

to watch out for when you're using these loops\n

loop is a situation where this condition up\n

like the condition that you specify up here\n

will just continually loop through. So for\n

of code right here, where we're incrementing\n

one. And so this condition up here is never\n

you'll see over here that we're just continually\n

flashing, really what's happening is we're\n

that while loop, and it's never going to stop\n

never going to stop, right because that condition\n

want to make sure that any conditions that\n

point are going to become false. Now, there\n

to want a while loop. But I would say for\n

be necessary. And they can actually be dangerous,\n

you're like creating variables or allocating\n

program or even crashing your computer if\n

tip about infinite loops. There's one more\n

And it's a different type of while loops,\n

But before I show you that, I just want to\n

int index equal to six, when I run my program,\n

going to execute. And that's because before\n

this condition first. So before I'm allowed\n

up here in these parentheses. So I check to\n

since index is starting out at six. We're\n

So if I ran my program, you guys will see\n

do anything. But there's another type of loop,\n

to show you guys how we can make one, I'm\n

it down here. And I need to include a semi\n

to be I'm just gonna say do and this is what's\n

essentially just a normal while loop, but\n

condition, and then executing the code, we're\n

going to check the condition. So it's just\n

even though index is equal to six, I'm still\n

then we're going to check the condition and\n

me show you guys what happens when I run this.\n

out that six. That's because with the do while\n

you check the condition. And there's a bunch\n

while loops or do while loops. And to be honest\n

do while loop you can do with a normal while\n

But in a lot of circumstances, they are useful.\n

B I mean, that's a basic overview of loops.\n

we can talk about in a future tutorial called\n

with these wild loops, you can kind of see\n

going to show you how to build a little guessing\n

because we're actually going to be able to\n

up to this point in the course. So we'll use\n

use variables, we use all sorts of stuff in\n

how this is going to go is the user is going\n

I'm gonna have a secret number stored here\n

to try and guess what that number is. So the\n

as you'll see in a second, it's actually pretty\n

here's the one caveat is if the user doesn't\n

to keep asking them keep prompting them to\n

you guys how we can do this. So the first\n

So I'm just going to make an integer and I'm\n

going to set this equal to I don't know, let's\n

number. And then the next thing I want to\n

call guests, and we're not going to give guests\n

secret number, and we have our guests. And\n

to guess what the secret number is until they\n

to be done continually, that's usually a good\n

I'm going to go ahead and say, while when\n

gonna make an open and close curly bracket.\n

ask the user to enter in the number until\n

is specify a condition. In other words, I\n

not equal to the guests. So as long as the\n

other words, as long as the user hasn't guessed\n

loop. Now, every time through the loop, I\n

So I'm just going to say C out. And we'll\n

going to enter the number that they want to\n

to get that answer, we want to store it in\n

greater than signs. And I'm just gonna put\n

see is that we want to take whatever the user\n

every time we go through this loop, the user\n

to check their guests against the secret num.\n

just break out of the loop. So down here,\n

means they got the guest right, so I can just\n

message. Alright, so this is essentially all\n

going to go ahead and run this program, and\n

enter guests, so I'm just going to enter in\n

a three, that wasn't the secret number, so\n

And no matter how many times I guess, it's\n

it right. Now let's try to get the guests\n

when I enter a seven in now, all the sudden\n

is going to be false. So the secret num is\n

we'll break out of the while loop. And it's\n

how we can build our little guessing game.\n

using a while loop, right. But there's actually\n

do while loop. So your homework for this tutorial\n

a do while loop instead of just a normal while\n

actually a pretty fun game, and it works out\n

But the game is a little bit unfair. It's\n

unlimited guesses. So they can guess as many\n

seem fair. So what we could do is we can impose\n

hey, the user is only able to guess like three\n

So I'm going to go ahead and show you guys\n

that, we're going to need to add in a couple\n

to add in is going to be called guest count.\n

to keep track of how many times the user has\n

time the user guesses the secret number, we\n

actually going to set this equal to zero initially,\n

then down here, every time the user guesses,\n

I'm just gonna say, guest count, plus plus.\n

of how many times the user has tried to guess\n

make another variable over here. And I basically\n

limit is going to specify how many times the\n

why don't we set this equal to 30. So we'll\n

can't get the word and three guesses, then\n

then one more thing, we want to create another\n

and this is going to be called out of guesses.\n

So out of guesses will tell us whether or\n

of guesses is false. That means the user has\n

of guesses. If it's true, it means they don't\n

of guesses. Alright, so now that we have these\n

can modify this a while loop. So down here,\n

you'll see that we're letting the user guessed\n

user doesn't have any guesses left, then we\n

Right? In other words, if they've reached\n

another guess. So what I can do here is I\n

I'm going to say is if guest count is less\n

less than the guest limit, then I'm going\n

condition is true up here, that means that\n

They haven't reached the guests limit. So\n

increment the guest count, etc. Otherwise,\n

the guest limit, that means that they ran\n

is I want to toggle this Boolean. So basically,\n

So I'm telling my program that they ran out\n

equal to true now, we're basically done inside\n

go through, we're checking to see if they\n

let them guess. Otherwise, we tell our program\n

thing that we have to do to this while loop\n

in this while loop condition, we can use this\n

me to put two conditions inside of there.\n

to guests, and we can check another condition.\n

see if they're out of guesses. So I want to\n

to check to see if they're not out of guesses.\n

they haven't guessed the secret word. And\n

those becomes false, so if they run out of\n

then we're going to break out of the loop.\n

Alright, so one more thing down here below\n

just printing out you win. But this isn't\n

out of guesses, then they're going to break\n

shouldn't tell them that they won, we should\n

to do is make another if statement. And I'm\n

if out of guesses is equal to true, then I\n

And otherwise, if it's not equal to true in\n

means that they want so that means they guess\n

and run this program. And we'll see how we\n

a guest. So why don't we try to lose the game.\n

So this is our last guest. If we don't get\n

you lose, right? So we lost the game. Alright,\n

of being able to guess infinite times, we\n

can win the game now. So we're gonna guess\n

guests, I'm gonna say seven. And when I enter\n

win the game, as well. So this is sort of\n

structures together. So you'll see down here,\n

not only did I use all these variables, but\n

all that stuff. And really, this is what real\n

it's not just going to be like little simple\n

just like this. Not that this is messy code.\n

different programming structures in combination.\n

you guys, which is the way that I wrote this\n

we could have written this like a dozen different\n

And you know, I can think of like at least\n

done this. And this is another lesson in programming\n

five or six different ways to do the same\n

while loop, I could have used different things\n

something else. And so that's one of the cool\n

in and trying different ways to do the same\n

this guessing game. Hopefully, you guys learned\n

structures like ifs and Wiles, and variables\n

tutorial, I want to talk to you guys about\n

type of loop, which actually allows us to\n

the loop. So in a for loop, we can use something\n

indexing variable will allow us to keep track\n

And you can also use the indexing variable\n

to show you guys how for loops work, we're\n

what situations you're going to want to use\n

this basic program set up and essentially\n

this a integer called index and I just set\n

than or equal to five, I'm just printing out\n

it. So I'm gonna go ahead and run this program,\n

So you'll see, we're basically just printing\n

And if you've been following along with this\n

familiar with what while loops do at this\n

things. So this while loop is special, because\n

index tells us what iteration of the loop\n

see over here, like the first time we go through\n

has the value one, the second time we go through\n

has the value of three, etc. Right? So this\n

iteration of the loop we're currently on.\n

of the loop, the value inside of this index\n

it's incrementing, by one, but the point is,\n

variable, and it's essentially just keeping\n

the loop. Now, in c++, and in just about every\n

very powerful looping structure. In other\n

track of you know how many times we've gone\n

that's going to change every time we go through\n

is such a useful situation, that there's actually\n

So there's a special type of loop whose sole\n

very similar to this, where we have this indexing\n

we go through the loop. And in a lot of circumstances,\n

of the loop we're currently on. And that's\n

guys how we can build a for loop. And essentially\n

we have up here, it's just going to be a lot\n

So it's great if we're live, we can just say\n

open and close curly bracket. So so far, it\n

one difference with the for loop is instead\n

So in this while loop, we just have our looping\n

like a loop guard. Down here in this for loop\n

three different things that we want to include.\n

of this for loop parentheses is a variable\n

here, you'll notice that I'm creating this\n

it a value of one. So I'm declaring the variable\n

I'm initializing the variable. inside of this\n

So I could actually just copy this line, and\n

And instead of calling it index, why don't\n

index, we'll set it equal to one, then you'll\n

put this semi colon, we can actually put another\n

wild looping structure is our loop guard,\n

telling us when we should loop so if this\n

keep looping. So that's the next thing that\n

So we're putting this variable declaration\n

also going to put the looping condition. So\n

stop and when it should go. Alright, so then\n

here. So you'll notice I have a semicolon\n

have another semicolon here, after we specify\n

do is put in a line of code that's going to\n

Up here in this while loop, you'll notice\n

index plus plus, this line of code is going\n

loop iteration. So the last thing that we're\n

loop is increment the index variable, right.\n

put over here, we're going to put a line of\n

every iteration of this loop. And in our case,\n

i so I'm just going to say i plus plus, we're\n

any line of code here that I want, I mean,\n

you know, basically whatever I want, but in\n

just like we did up here with index. So now\n

open and close curly brackets, we can just\n

of the loop. So that's going to be this line\n

guy in right here. And now we have a completed\n

down here is actually equivalent to this loop\n

of code, whereas this only takes two lines\n

scenario where we want to have a variable\n

changing every time we go through the loop\n

the current loop iteration, such a common\n

a for loop for that. And the for loop, the\n

like I did up there. So I'm initializing this\n

the looping guard the looping conditions,\n

a line of code that's going to get executed\n

going to be this i plus plus. And you'll notice\n

And you'll notice also that I don't need a\n

rid of this while loop. And I'm going to go\n

we run the for loop. And actually, I need\n

being index, I'm just gonna leave it as i\n

int is equal to one, we're going to keep looping\n

And then at the end, we're just going to increment\n

time through the loop, we are printing out,\n

you'll see we get the same exact output as\n

just 12345. So what's cool about these four\n

of a value every time we go through. And in\n

of how many times we've gone through the loop,\n

for loops to actually iterate through the\n

an array of integers, so we'll just call it\n

an initial value. So why don't we just say\n

it just has a bunch of numbers in it. And\n

to access a specific element inside of this\n

put the index in here. So if I said num zero,\n

if I said nums, four, it's going to give us\n

to this three, what I can actually do is I\n

to actually loop through and print out all\n

start at zero, so I'm going to start this\n

do is I'm basically going to say i is less\n

array. So inside of this array, we have 12345\n

than five, we want to keep looping and then\n

here, instead of printing out, I could actually\n

to do is on the first iteration of the loop,\n

second iteration of the loop, it's going to\n

of the loop, it's going to print out nums,\n

way up to number four, which as we saw is\n

be the last element in the array. So we can\n

all the elements in the nums array. So let's\n

here, we're printing out all the elements.\n

very common situation, we can use for loops\n

array. And it can be really useful. So play\n

useful. And one more time, I just want to\n

we're doing over here is we're creating a\n

so I'm saying int is equal to zero. And then\n

condition, I'm saying we're gonna keep looping\n

is a line of code that will get run after\n

we go through this loop, we'll come up here,\n

the condition. Again, that is the basics of\n

would say this is almost even more widely\n

So you definitely want to practice and play\n

I'm gonna show you guys how to build an exponent\n

a function that will take a number to a specific\n

could pass in two numbers, like if I passed\n

me back three race to the fourth power. So\n

and we'll actually get a chance to use four\n

build this function, that's going to be pretty\n

exponent function. So we're going to have\n

int. And why don't we just call this power\n

power, and make an open and close parentheses\n

power function is going to take two arguments.\n

going to take a power number. And we're basically\n

of the power number. So I'm just going to\n

here in our power function, we need to figure\n

to take bass num to power num. And we can\n

do that. So the first thing I want to do is\n

to call it result. And I'm just going to set\n

basically just going to return results. So\n

is to get rid the result variable equal to\n

number, right, that's kind of our goal. Throughout\n

of simplicity, and the purposes just for this\n

to handle positive number exponents. So we're\n

is going to be positive. And now let's just\n

to drive home the point a little bit better,\n

I'm going to go ahead and write out this for\n

to specify three things, the first thing I\n

gonna say int i is equal to zero, I'll start\n

specify a looping a condition or a loop guard.\n

less than the power num. Essentially, what\n

loop power num times. So as many times as\n

this loop. So if power num is three, I want\n

I want to loop through five times. That's\n

here, we can just specify something that we\n

So I'm just gonna say i plus plus. And basically\n

every time we go through the loop. Alright,\n

to think about what we can do. So where are\n

through here, power num times, right? So what\n

result times the base num, every time we go\n

is result is equal to result times base num.\n

is because let's just kind of break this down,\n

result is going to be equal to one. So the\n

multiplying base num by one, so we just get\n

loop result is equal to based on right, in\n

num. So the second time we go through, we're\n

on based on squared, right, the third time\n

of base num squared. So for molting multiplying\n

us base num cubed. So that's kind of why this\n

through this for loop power num times. And\n

result times the base num. And you can see\n

us to only loop through the loop a specified\n

easy for us to only loop through, you know,\n

is the basic function. And this looks pretty\n

this is only going to be able to handle positive\n

nums. Okay, so let's go ahead and call this.\n

we print out the result. So I'm going to see\n

So why don't we pass in two, and three, so\n

So now let's run this function. And you'll\n

Two times two is four, four times two is eight.\n

squared. So now we should get 16. And you\n

like our little function is working. And basically\n

of demonstrate to you another way that we\n

for loop in order to essentially specify how\n

And four leaves are really useful for that\n

representing how many times we've gone through\n

loop I can tell us that we've gone through\n

is useful. And so you can see, it's actually\n

takes up like two lines of code. So that's\n

function. And actually, this is kind of useful,\n

like this might get put together. In this\n

two separate subjects in c++, the first subject\n

two dimensional arrays. And a two dimensional\n

where every single element inside the array\n

situation. And I want to talk to you guys\n

loops. And a nested for loop is a situation\n

for loop. So this is gonna be kind of cool.\n

subjects together two dimensional arrays,\n

of a cool program. So I'm gonna show you guys\n

I want to show you is a two dimensional array.\n

of numbers. And I'm just going to call it\n

a regular array, we're just going to make\n

we're making a two dimensional array, I want\n

after this. Now remember, a two dimensional\n

where every element inside of the array is\n

how we can go ahead and set something like\n

value. So I'm just gonna initialize this.\n

of array elements inside of here. So the first\n

element in the array. Now normally, if I was\n

out elements like this, right? You know, I\n

a comma, and then we have our array. But with\n

element is actually another array. So if I\n

two dimensional array, I can basically go\n

of mini array inside of here. And I'm actually\n

so now the first element in this number grid\n

one and two. So number grid, first element\n

of its own. So I'm going to copy this, and\n

going to put a comma here, because remember,\n

elements. And then down here, I'm just going\n

four. So we have 1234. And why don't we do\n

so essentially, what's happening here is we\n

curly brackets represent the number grid array.\n

three elements. So this is the first element,\n

third element, all of which are arrays. And\n

inside of them. So whenever we're creating\n

specify the numbers over here. So inside of\n

we want to tell c++, how many total elements\n

we have three, because again, there's 123\n

how many elements are inside of each array\n

etc. So there's going to be two elements in\n

especially when you're dealing with two dimensional\n

otherwise you can get really confused, you\n

the basic layout, like I know that this array\n

and then it has two columns. So these would\n

a matrix. Alright, so that is a two dimensional\n

access some of these elements. So if I want\n

just gonna go ahead and print some of these\n

and what I can do is I can make two open and\n

just like this. And inside of these open and\n

want to specify the row. In other words, I\n

grid that I want to access. So this would\n

be the element at position one, and this would\n

we want to access this element right here.\n

element zero. And then over here, I want to\n

array, so it's going to be an index position\n

overall element, and one is corresponding\n

so now when we print this out, we should get\n

two. Let's try one more, why don't we try\n

to be an element 012. So we're going to put\n

zero, so we're just going to put a zero and\n

Alright, so that kind of shows you a little\n

array. And actually, this same concept can\n

could have a three or four or five dimensional\n

to apply. Obviously, the more dimensions you\n

can get pretty complex with arrays, just by\n

thing I wanted to show you guys. And now I\n

a nested for loop. And nested for loop is\n

of another for loop. And actually nested for\n

can use them to print out all of the elements\n

we could iterate through all the elements\n

I'm going to show you guys how that's going\n

basic for loop. So I'm just gonna say for,\n

Again, our goal here is to be able to loop\n

And, you know, as I sort of create this for\n

this is all gonna make sense. But what I want\n

less than three. And I'm using three here,\n

all of these individual elements. So all of\n

and over here, I'm just gonna say i plus plus.\n

over all of these elements. So this first\n

element, but remember, each of these elements\n

for each of these arrays, I want to iterate\n

arrays. So I can create another for loop to\n

to call this J. And a lot of times when we're\n

ij, that's kind of a convention, I'm gonna\n

looping as long as j is less than two. And\n

each of these arrays, right? So this loop\n

all of these elements, and this one down here\n

these elements. So I'm gonna say j less than\n

So now we have our basic structure setup.\n

loop is going to fully iterate. So it's going\n

I'm just going to see out. And I'm basically\n

elements. So I'm going to print out number\n

basically how this is going to work. And then\n

out a new line. So I'm just going to say C\n

line. So let's go ahead and run this. And\n

as far as what it's doing. So when I run this,\n

out all of these elements. So we're printing\n

and iterate over every single element inside\n

what's happening is, every time we go through\n

fully iterating through the J loop. So this\n

individual element. So it's responsible for\n

j loop is responsible for iterating over each\n

which are arrays. So the J loop is going to\n

we go through this loop is going to be equal\n

So we're going to print this out, then we're\n

still going to be equal to zero, but j is\n

print this element out. And then AI is going\n

zero, we'll print this out and then it's going\n

that's essentially what's happening here.\n

loops, I mean, any sort of nested loop can\n

through like I said, complex structures like\n

By using comments in c++, or comments are\n

actually going to get executed or rendered\n

you're going to want to, you know, basically\n

So whenever we're writing programs, like whenever\n

instructions are meant for the computer. So\n

out, or I can tell the computer to loop over\n

a lot of times, we're going to want to write\n

for yourself or for someone else. And we can\n

And I'm gonna show you guys what comments\n

know, a little line of code or a block of\n

we can use it to write little messages for\n

in c++, there's actually a couple of ways\n

two forward slashes. So when I make two forward\n

all of this text is actually colored different\n

is a comment. So any text that I put after\n

a comment. And it's not actually going to\n

a bunch of nonsense up here, I can still run\n

to execute. So you'll see I can run the program.\n

out comments are fun. So this is a really\n

a lot of people will use this to write notes\n

developers. You can also use this to like\n

this line of code over here, I can say like,\n

you probably wouldn't need to describe this\n

or you know, complex loop or something like\n

also put these comments like after a line\n

it down here. And you'll see that everything\n

is going to be considered a comment. But I\n

can use this to like describe what the line\n

one downside to this type of comment, though,\n

So if I come down here to the new line, all\n

So this is no longer a comment. If you want\n

you can use something called an opening and\n

and an Asterix, then everything that comes\n

is going to be considered a comments, you\n

But I can close this off by saying an Asterix\n

that's in between these two tags is going\n

types of comments are very common. And you\n

to be correct. And it's going to work out.\n

types of comments and how you can use them.\n

commenting out lines of code. So a lot of\n

maybe you want to try to run your program\n

be running into a problem and you think a\n

one option would be to just remove the line\n

line of code was potentially like messing\n

program would act without that line of code.\n

and then run the program. And now we're running\n

problem with that, though, is I have to physically\n

though, I could just put a comment in front\n

get ignored by c++. So it's essentially the\n

have to physically remove it from the file,\n

it, we still know that it's there. It's just\n

useful way that comments can come in handy.\n

you definitely want to take advantage of them\n

In this tutorial, I want to talk to you guys\n

just a type of information that we can work\n

with this course up to this point, we've been\n

So we were working with things like integers,\n

with like doubles, which are decimal numbers\n

are like plain text. And this is where I want\n

we can deal with which are called pointers.\n

So we're going to have get into what that\n

talk about all that stuff. And I'll give you\n

here in my program, I have a few different\n

called age and I gave it you know, a value\n

Now all of these are variables in my program,\n

essentially just containers where I'm storing\n

I'm writing this program, I'm storing the\n

I'm storing 2.7 inside of this GPA variable.\n

the hood a little bit and talk about what's\n

you have something called your memory. And\n

might have heard people talk about ram stands\n

just the active memory that your computer's\n

your computer runs a program, it's using Ram.\n

memory, let's just say our program, for example.\n

run this program, my computer would actually\n

is going to use its memory in order to store\n

going to be storing all of these values inside\n

age, and I give it a value, what's actually\n

value 19. And it's going to store it inside\n

create this double GPA, my computer is going\n

it physically inside of the memory in my computer.\n

of these different pieces of data that are\n

memory of my computer, so when I write the\n

that 19 is stored inside the age variable.\n

stored in side of the computer's memory, so\n

one of the cool things about the memory of\n

containers, right, each one of these variables,\n

like inside of one of those containers, right?\n

but you can basically think of it as like\n

in memory, this value 2.7 is stored inside\n

containers inside the memory of my computer\n

So it has an address, which uniquely identifies\n

inside the physical memory of my computer,\n

This value 2.7 is stored in the memory of\n

memory address. And so when my program wants\n

using that memory address. When I want to\n

using like age or GPA. But when my computer\n

it using the physical memory address. So that's\n

show you guys how we can go ahead and access\n

print it out, I get to say C out. And if I\n

address where each of these variables are\n

the memory address where this value 19 is\n

where this value 2.7 is stored. All I have\n

can type in the name of a variable. So I could\n

is going to do is when I put this ampersand\n

I want to print out the memory address where\n

I want to print out the memory address where\n

my program, you'll notice over here that I'm\n

six, a FPS zero. This is a hexadecimal number,\n

will be very difficult for a human being to\n

it just fine. So if you were to go to this\n

you would find the value 19. I mean, that's\n

that's basically like where that value 19\n

wanted to access or change it or modify it,\n

that's essentially what we're talking about.\n

So we have like a special word that we use\n

a pointer. So generally, if I'm working in\n

I'm going to talk about pointers. So I would\n

here, we can say that I'm printing out a pointer.\n

It's just a memory address. So any memory\n

using inside of our programs is going to be\n

can access the pointer of these variables\n

memory addresses where these variables are\n

a little demonstration I want to show you\n

wrote out before the tutorial. And it's essentially\n

for all of these variables. So I'm going to\n

here, I'm essentially just printing out all\n

these variables. So we have age, and it's\n

at this memory address and name at this memory\n

if we were to go to them in our like physical\n

we would see those values. And again, we would\n

this is a pointer pointer is just a memory\n

just giving it another name. So that's kind\n

we can access like the memory addresses of\n

take this a step further. So I want to show\n

can actually create a variable where I can\n

creating an integer variable, and inside of\n

I'm creating a double variable, and I'm storing\n

variable, I'm storing a string. And actually,\n

memory addresses or the pointers inside of\n

So I'm going to show you guys how we can do\n

be just a container where we can store a pointer,\n

a memory address. Generally, when we're working\n

not just going to work with random addresses,\n

any, like meaningful memory addresses off\n

using memory addresses, we're going to be\n

variables in our programs. So therefore, when\n

words, when I create a container, what I'm\n

to create it based off of one of these variables.\n

that will store the pointer. For this age\n

we create a pointer variable, you always want\n

to be the Asterix, and then you want to type\n

to call this P age. And a lot of times when\n

use this lowercase P. And then you'll type\n

address you're storing. So I could say int\n

age. So remember when we use this ampersand,\n

that gives us the pointer. In other words,\n

value is stored. So I'm essentially storing\n

here called p age, I could do the same thing\n

double Asterix, and I'm just gonna say p GPA.\n

GPA. So now this pgpa pointer variable is\n

that storing inside of it a memory address,\n

of this GPA variable. I can do the same thing\n

p name. And actually don't forget to put the\n

name. And now this pointer variable p name\n

storing the memory address have this name\n

these different pointer values using these\n

here, I could say C out. And I could just\n

to go ahead and print out the value that's\n

is going to be a pointer, which should be\n

there, that's exactly what we get. So that's\n

a lot of times people get a little intimidated\n

are really simple. A pointer is just another\n

So you know, you can work with things like\n

work with doubles, which are decimal numbers,\n

a bunch of characters, you could also work\n

you know, that's all it is. It's just a different\n

variable, it's just a container where we can\n

Now I want to point out to you guys, whenever\n

that I use the data type of the variable that\n

is storing the memory address of an integer.\n

variable is storing the address of a double.\n

here. This is storing the memory does have\n

basically just what you have to do when we're\n

me to another point I want to show you guys\n

dereferencing, a pointer. And dereferencing.\n

to grab the value that's inside of the memory\n

address. So if I have a pointer, that is a\n

or a physical location, in my computer's RAM,\n

it's just an address, right? Like you have\n

what this is, it's an address. But instead\n

And when we dereference a pointer, we're basically\n

pointer, we now want to go to that physical\n

and use it in our program. And the way that\n

you'll notice, like when I print out p h,\n

I run this program, and I print it out, we\n

this pointer, we would actually end up getting\n

So if I put an Asterix here, this is what's\n

say Asterix p age, and now we'll be dereferencing,\n

that memory address, when I run this program,\n

is the value at the memory address that the\n

So I'm here in my program, and you'll see\n

this Asterix, we get the memory address, when\n

the pointer. So we just get 19. And that's\n

makes sense. I'm gonna show you guys one more\n

And if I just said, for example, like ampersand\n

it's storing the value of 2.7. This is a pointer,\n

address. So over here, when I run this, we\n

dereference this, and hopefully this kind\n

just put an Asterix here, and this is going\n

this Asterix is dereferencing, this pointer,\n

which is 2.7. So you can see we get this value.\n

together. Not that you'd want to but I could\n

memory address again. So that's kind of how\n

you know, working with pointers, doing stuff\n

This is also a very useful concept in another\n

the programming language that c++ is based\n

which but they're also important in c++. And\n

you need to have at least a baseline understanding\n

hopefully that gives you a little bit of an\n

pointers are just types of information. It's\n

in our programs, we can print them out, we\n

variables, we can also dereference them, as\n

that helps. And hopefully now you can kind\n

I'm gonna teach you guys about classes and\n

useful. And this is a very important topic\n

overview of what these are. And we'll kind\n

objects. So down here in my little program\n

basically, what I'm doing here is I'm just\n

I'm storing my name, inside of this name variable,\n

storing pi, the first three digits of Pi in\n

my favorite letter G inside of this character\n

able to store a bunch of different types of\n

about c++ data types, you'll know that by\n

different types of data. So we can store like\n

whole numbers, decimal numbers, we can store\n

types of information. But here's the problem\n

this is that there's a lot of types of information.\n

a lot of real world entities that can't just\n

or a character. Like there's a lot of things\n

or a number or a character like, like a phone\n

a phone In my program using like a string\n

like a computer, or a keyboard, or an animal\n

real world entities, that it can't necessarily\n

types that we have, or we only have like,\n

use. And those data types really aren't enough\n

the real world. So imagine I was creating\n

work with books, like maybe I was creating\n

program, we needed to represent book like,\n

store books and use books inside of my program.\n

no, like, I can't just come over here and\n

like, there's no book data type for me to\n

know, forget, forget about books for a second\n

like a person or a location, or a musical\n

in the real world that I'd want to represent\n

problem is we only have a limited data types,\n

we can represent. And this is where classes\n

we can actually create a class. And a class\n

create a class, I'm basically creating a new\n

are useful, because we can kind of create\n

program. So like I said, before, you know,\n

like a book data type, right. But what I can\n

what a book data type is. And then I can actually\n

of my program. So I'm going to show you guys\n

that will allow us to store and work with\n

So we're essentially going to be creating\n

I am just going to come up here. And I can\n

And I'm going to create a class and a class\n

for a new data type in our program. So when\n

new data type, I'm creating a new type of\n

in our programs, it's pretty cool. So over\n

class, and then I'm going to give this a name.\n

are going to name them with capital letter.\n

So we're going to create a book class. So\n

or a template for the book data type. Okay,\n

basically specifying what a book is, inside\n

here is I want to actually define the book\n

attributes. So we can basically say that a\n

five different attributes that will describe\n

data types like strings, integers, doubles,\n

attributes. So essentially, this book class\n

which are going to be things like numbers\n

public, and I'm going to make a colon here.\n

I'm actually going to end up this. So it's\n

below where I said public, I want to specify\n

out what a book is going to be and what it's\n

the different attributes of a book? Well,\n

going to be the title. And we can represent\n

title. And I'm just declaring these variables,\n

another walnuts thing? Probably the author,\n

be the book's author. And let's try to think\n

be maybe let's do pages. So like this would\n

sure you can think of a lot more we could\n

company, you know, you could think of, you\n

attributes we could store for a book. But\n

what I'm doing here, as I'm mapping out a\n

for the book, data type. And a book in our\n

and can have a number of pages associated\n

type. Really, it's a it's a class. So this\n

just specifying what a book is. We're telling\n

I'm going to come down here and I'm actually\n

is just a blueprint. This is a template, it's\n

book, if I want to actually, like have a physical\n

I need to create it down here. And we're actually\n

So here's a little terminology lesson, a class\n

it's the template of a data type. So this\n

blueprint of a book inside of our program,\n

or it's an actual instance of that class.\n

to create an object down here, we'll call\n

an actual book that's going to have an actual\n

of pages associated to it. And we can create,\n

but just know that a class is the template,\n

actual instance of that specification. So\n

author, and page. So let's go ahead and do\n

I'm basically just telling c++, what type\n

I want to store. And then I'm going to give\n

book one. So now we have this book inside\n

what we want to do is start giving it some\n

title. And we can actually give this a title.\n

title. So why don't we just say the title\n

be a Harry Potter book. And I can do the same\n

say book, one dot author, and I can just give\n

going to give this a number of pages. So I\n

going to be an integer. So let's say it has\n

to represent, and I'm able to work with a\n

up here is a class. It's a template for what\n

a physical book in our program that has actual\n

book, with the JK Rowling author and 500 pages.\n

actually print out this information. So I\n

book one dot title. And so now I'm able to\n

book, one object. So I'm basically able to\n

this program, now, you'll see we're printing\n

Potter, I can do the same thing for like pages.\n

in book one, which is going to be 500. So\n

model a real world entity like a book inside\n

have a book data type, right, I had nothing\n

Now all of a sudden, I have one. So I can\n

And we can make as many of these as we wanted.\n

let's make another book. So let's say in addition\n

make another one. And I'm just going to call\n

of these. So now all of these are sets of\n

attributes. Instead of it being a Harry Potter\n

book, and the author is going to be token.\n

So now I have two books in my program, I have\n

all of these attributes associated to it,\n

to it. But both of these books are using this\n

same book class, this is just a specification\n

to create individual instances of that specification.\n

book objects. So I could also print out stuff\n

Two dot author, and this is going to print\n

just like before, when we have like integers,\n

Now, in addition to those data types, we also\n

can use a book, I can store it, I can, you\n

that. And, you know, down here, basically,\n

giving it value. So I can say like, book one\n

said book to title down here, I could change\n

or something. And now, Book Two title is going\n

variables would work. And you can see now\n

cool. And honestly, this is just a, an introduction\n

to learn about, there's a lot more to talk\n

you want to do is just play around with modeling\n

book. So I created a book data type, but you\n

create a like a keyboard data type, you can\n

just taking a real world entity, breaking\n

author, and pages, and then you can represent\n

going to teach you guys how to use constructors\n

is a basically a special function that is\n

object of a class. So let me show you guys,\n

actually up here, I have this class, it's\n

the course, we created this class in the last\n

just sort of a blueprint or a specification\n

So you know, a book has a title, has an author\n

we actually created some book objects. And\n

So we have book one, and book one has a title.\n

pages, and all that stuff. So I'm going to\n

play. So a constructor, like I said, it's\n

get called whenever we create one of these\n

to go ahead and create a constructor. And\n

is just by essentially creating a function\n

And I'm gonna make an open and close parentheses\n

what we have here is a constructor. So this\n

to get called whenever we create a book object.\n

going to print something out. And I'll just\n

to print a new line. So down here, I'm creating\n

creating Book Two, whenever I create a new\n

function up here is going to get called. So\n

here, it says, creating object twice. So it\n

made this line of code. And then down here,\n

when we created this second object. So we\n

function got called twice. Hopefully that\n

this book function is that it can accept parameters.\n

this is going to accept a parameter like name.\n

whatever the user passed it. And so now down\n

pass values in so I could pass in like Harry\n

we could pass in like, Lord of the Rings.\n

when I run my program, it's going to actually\n

of printing out like, creating object, it's\n

the constructor. Pretty cool, right? And constructors\n

we create objects. So let me point something\n

to get rid of this stuff up here. So only\n

these objects, right. And when I wanted to\n

so when I created book one, and Book Two,\n

going to be, what the author was going to\n

it kind of took up a lot of time, right, it\n

out book one dot title, book, one dot author.\n

that I create. Well, that gets really, really\n

two objects, I wanted to create like 100 or\n

lines of code, I mean, just to create one\n

We can actually use these constructors in\n

So like when I create this book, one instead\n

author and the pages. Instead, I could just\n

the constructor could initialize the values\n

do that up here. In our constructor, I'm going\n

to take three values. So this book constructor\n

we're just going to call this a title, it's\n

call it a author. And it's going to take an\n

And I'm putting this a here, you don't have\n

of easy for us to see what's going on, a is\n

will be like the title, that's an argument.\n

can actually assign the values of title, author\n

So down here, we're assigning the values of\n

But instead of having to do it down here,\n

So I could say that the title is going to\n

title of the object, the title that we want\n

to be equal to the title that gets passed\n

So I could say, author is going to be equal\n

to A pages. And again, you don't have to name\n

whatever you want. I'm just kind of doing\n

going on. So down here, what I can do now\n

it a title and author and a number of pages.\n

you'll see we're getting an error, we're basically\n

these values. So what I can do is I can actually\n

I can take the number of pages, so 500, and\n

I can just get rid of all this code, because\n

same thing for the Lord of the Rings book.\n

pages. And so now we can get rid of all this\n

of code to create two objects. So now we just\n

my program, we should be able to essentially\n

So let's go ahead and print out this stuff.\n

just going to see out while we see our book,\n

So we should get Harry Potter, which we do.\n

except we're able to do it a lot easier and\n

So this was a very, very powerful tool for\n

we can still modify these. So I could still\n

the title. So I can change the title to whatever\n

doing with this constructor here is we're\n

just making it easier for us to initialize\n

sort of the basics of using constructors.\n

do, you can actually create multiple constructors.\n

essentially just allow us to take in a title\n

say that for some books, we wouldn't want\n

make another constructor over here. And this\n

parameters. And I can just give these values\n

say like title is equal to no title. Author\n

like pages is equal to zero. So this is basically\n

information if we don't pass anything it and\n

here and I can create another book. So I can\n

And I now I don't have to pass in this information.\n

print out like Book Three dot title, and it's\n

this needs to be capital whoops. So now you\n

will create multiple constructors, you're\n

they can create your objects. But I'd say\n

where you pass in all of the attributes, and\n

that's the basics of constructors. Hopefully\n

so you're definitely going to want to use\n

I'm going to talk to you guys about object\n

refer to these sometimes as like instance\n

it's a function that we can put inside of\n

objects of that class can use that function\n

about themselves, or modify information about\n

a sort of introduction into how to do this.\n

up a class. And this class is called student.\n

like what a student is going to be in our\n

is going to have a name, a student is going\n

to have a GPA. So that information is sort\n

And then down here, I created a constructor,\n

these objects owner to pass in some initial\n

of major and then also the GPA. So I'm essentially\n

would any other constructor. So this is our\n

method, you'll see that I actually have a\n

student one, his name is Jim, he's a business\n

another student student two, her name is Pam.\n

So these are now two students that I'm working\n

of my programs. That's awesome. So let me\n

object functions. Let's say that we wanted\n

these students was on the honor roll. Right.\n

students attend, there's an honor roll, right,\n

the honor roll as you need to have a GPA of\n

or greater, that means that you're on the\n

have an easy way to figure out whether or\n

Well, what I could do is I could actually\n

which each of the objects can use to tell\n

what I'm going to do is I'm going to go down\n

just create a function like I normally would,\n

going to give this a Boolean return type.\n

and this function is basically going to return\n

if the student has honors right? No return\n

If they don't, it's going to return false.\n

in any information, we don't need any parameters,\n

bracket. Now down here inside of this function,\n

So I can just use an if statement, I'm just\n

say if GPA is greater than 3.5. Or actually,\n

we're gonna come down here, and we can just\n

that means that they have a GPA of 3.5 or\n

the case, we can just return false. So that's\n

to do. It's very simple if they have a GPA\n

false. Now, what's cool about this function\n

this function, and depending on their specific\n

So for example, let's go ahead and call this\n

C out I just want to print out the answer.\n

So now if I want to figure out whether or\n

I can say student one dot has honors. And\n

not Jim has honors. So you'll see over here,\n

Whenever you print out Boolean values, if\n

as a zero. If it's a true, it's going to get\n

seeing a zero here means that student one\n

thing for Pam. So we can do the same thing\n

to dot has honors. And now this should be\n

is going to have honors. What's cool about\n

to be using different information depending\n

gym object calls it, the GPA is Jim's GPA.\n

GPA. So we can define a general function over\n

that calls it, it's going to be giving or\n

to be different, depending on if Jim's calling\n

of why these are cool so you can make awesome\n

will make these to get information about the\n

or not they have honors, or modify values.\n

at functions which are going to be modifying\n

kind of gives you an idea of what you can\n

cases, you're going to want to have different\n

going to do stuff. Now I do want to just point\n

let's say that I have this program written.\n

students. And maybe I have a program that\n

something. Well, let's say that one day, the\n

Hey, Mike, we're going to change the qualification\n

a 3.5, and greater is going to have honors,\n

and greater is going to have honors, in order\n

In other words, in order for me to update\n

here and change this to 2.0. And now all of\n

And these has honors are still going to work.\n

to be lowered. So I can say student one has\n

because we changed the qualification. So now\n

are powerful, you can kind of adjust different\n

things about the overall class and about every\n

So hopefully that is clear. Hopefully, you\n

different objects functions. In this tutorial,\n

and setters in c++ classes. Now, getters and\n

they allow you to control the access to the\n

inside of your c++ classes. So I'm going to\n

order to do that, we're going to use a little\n

created, it's called movie. And this is basically\n

inside of our program. So I have a few different\n

it's going to have a director, it's also going\n

attributes of a movie, right, we can basically\n

it's going to be, that's what it's going to\n

So I'm just passing in the title, the director,\n

we're assigning those values to the values\n

stuff. And if you've been following along\n

kind of make sense. You know what I'm doing\n

class, movie data type. And down here, I actually\n

it's called Avengers and the title is The\n

rating is pG 13. So um, I'm creating an actual\n

out the rating. So why don't we run our program,\n

So over here, I have pG 13. So it's printing\n

looks good. Now, here's the thing, a lot of\n

like a class up here, like this movie, we're\n

can be stored for a particular movie. And\n

I have this rating as pG 13. Right. And generally\n

of ratings that you can have, so it'd be like\n

rated. So just for our purposes, let's say\n

give to move PG, PG, PG, 13, Rn, nr, right?\n

of. But let's just say that those are the\n

for a movie, those are the ratings that are\n

Well, over here, I'm inserting pG 13. But\n

else. There's nothing stopping me from just\n

nothing that's stopping me from just typing\n

the program and being able to store it inside\n

set the rating equal to dog, even though that's\n

that we can have. And there's a lot of circumstances\n

for example, you know, valid ratings that\n

words, like when you're writing this program,\n

want a movie object to be created. That's\n

want this to be able to happen down here.\n

rating in as dogs. So I'm gonna show you guys\n

how we could make it so that the user can\n

a valid rating. And to do that, we can use\n

the first thing that I'm going to do, after\n

here into my class. So up here in my movie\n

you'll see up here, I have this keyword public.\n

put all this stuff underneath public, what\n

And basically, when something's public, it\n

can access it. So essentially, any code outside\n

of the movie, the director of the rating and\n

print out Avengers dot rating, because rating\n

because it's underneath this little public\n

we can use in c++, which is called private.\n

public, I can just say private, and any attributes,\n

I put underneath this private keyword, is\n

if I was to take this string rating, and I\n

what this means is now only code inside of\n

attribute, only code that's inside the movie\n

down here now and try to print out Avengers\n

that anymore. And you're going to see that\n

this highlights in red basically telling us\n

because it's private, so I no longer have\n

Now one thing I will point out is I have access\n

because the rating variable, the rating attribute\n

so it's able to access it. But this main function\n

the main function can't, because it's not\n

the difference between public and private.\n

order to control what ratings are able to\n

guys how we can do this, the first thing I\n

I'm going to create a public function, and\n

this is going to be void. And I'm just going\n

take as a parameter, it's going to take one\n

So this is going to take a rating as a parameter\n

I'm basically going to say rating is equal\n

a value to the rating, I'm going to make it\n

So over here, instead of saying rating is\n

to say, set rating, and I'm going to pass\n

rating, it's going to go through this set\n

to modify the rating down here, so if I wanted\n

dog, I'm not going to be able to do this again,\n

it over here. But if I want to modify the\n

function, because it's public. So over here,\n

of saying Avengers dot rating, I could say\n

this as a parameter, dog. Alright, so now\n

here in the constructor, or down here in the\n

set rating function. And that's going to be\n

do now is we can set up some rules. So I can\n

function for what ratings are going to be\n

Essentially, what I'll do is I'll create an\n

passed in is one of the valid ratings like\n

it. Otherwise, we'll be able to essentially\n

like, Hey, this is an invalid rating. So down\n

And I'm just gonna say if. And I'm basically\n

one of the valid rating so we can check to\n

is equal to P And I can keep doing this for\n

this over here. And I'm just gonna say, or\n

equal to R. And then there's one more, which\n

So basically, what I'm doing is I'm creating\n

all of these conditions. So it's checking\n

to PG, or if it's equal to pG 13, or R or\n

those, right, if it's equal to one of those\n

set it normally. So I could say like rating\n

entered in a valid rating, so it's going to\n

enter in a valid rating, that means that we're\n

that they entered, so I can say else. And\n

set rating equal to an R. So we'll say that\n

they tried to set an invalid rating, for the\n

go ahead and set it to nr because they didn't\n

to be not rated. So here's the thing. Now\n

to go through this set rating function. So\n

say Avengers, set rating and dog. And then\n

gonna say nr, because they entered in an invalid\n

But here's the other problem is when I can't\n

Access Avengers dot rating, because it's private,\n

another function up here, and this one is\n

a string. And I'm just going to call it get\n

it's just going to return rating, so it'll\n

to print this out, I could say Avengers dot\n

So let's go ahead and see what happens. So\n

dog. That's an invalid rating. So now when\n

just print out nr. And actually looks like\n

equals in there. Let me see if I did that\n

able to run this now. Yeah, so down here,\n

I tried to set the rating u equal to dog,\n

to get it, it's just giving me an R. And that's\n

over here, when I just first created this,\n

that is one of the official ratings that we\n

have that it'll have a rating of pG 13. But\n

that's not a valid rating, right. So when\n

say that it's not rated because we didn't\n

can essentially do whatever you wanted there.\n

is that there's going to be certain times\n

you know how the user can interact with the\n

our case, we wanted to be able to restrict\n

inside of a movie. So I was able to set the\n

could access it directly. They couldn't just\n

or the ratings equal to that. Instead, if\n

through the set rating function. And they\n

here. And that is an awesome way to control\n

individual attributes in a specific object.\n

guys about inheritance in c++. inheritance\n

And then we can define other classes. And\n

or they can inherit all the functionality,\n

So the easiest way for me to explain this\n

So over here in my program, I created a class\n

this class is like modeling like a chef in\n

functions that the chef class can perform.\n

salad and the chef can make a special dish.\n

out like what it's doing. So this one says\n

Chef makes barbecue ribs. Very simple class.\n

an instance of this Chef class, and called\n

make chicken. So let's run the program. And\n

program, you'll see, it prints out the chef\n

class. And let's say that I'm running my program.\n

in addition to representing just a normal\n

Italian chef. So what I'm going to do is I'm\n

another class. So I'm just going to say class.\n

going to create an Italian chef class. So\n

our purposes, when we're creating this Italian\n

able to do everything that the normal chef\n

can also make salad and can also make a special\n

chef will be able to do a bunch of other stuff,\n

to build this Italian chef. Because the Italian\n

that the normal chef could do, like make chicken,\n

actually inherit all of these functions. From\n

I'll show you guys how to do that, it's actually\n

here. And I'm just going to make a colon.\n

this is referring to the class that I want\n

this is this Italian chef is going to have\n

in this chef class. So it's basically going\n

show you if I was to come down here and create\n

chef, we'll just call it Italian chef. I could\n

even though I didn't specify anything up here,\n

even though I didn't specify a make chicken\n

function up here, I'm still able to call make\n

this program, now, you'll see it says the\n

function on the normal chef and the Italian\n

Italian chef down here is inheriting all of\n

of demonstrate this even further, if I came\n

yummy chicken. Now when I run my program,\n

also going to be able to make yummy chicken.\n

from the chef class. And what's cool about\n

all that in functionality, but we could extend\n

to be able to do everything the chef does.\n

Italian chef could also like make pasta. And\n

like the chef makes pasta. So in addition\n

normal chef can make, this Italian chef can\n

say make pasta. But it's important to note\n

if I tried to call pop make pasta on the normal\n

So you'll see over here, it's not going to\n

it looks like I had an error up here. So this\n

get an error down by the other chef. Yeah,\n

basically saying this, this chef can't make\n

now that you'll see the Italian chef is gonna\n

chicken. And actually one more thing I forgot,\n

to do that. So I'm gonna say public. And then\n

function is going to be public. So now we\n

see it says the chef makes yummy chicken and\n

are able to do different things. And that's\n

do with inheritance is I can actually override\n

the normal chef has this make special dish\n

ribs as a special dish. But let's say that\n

special dish. Well, I can do something called\n

this function from up here. And I can paste\n

now this is going to override the function\n

ribs we could have him make like chicken parm.\n

chicken parm while the normal chef will make\n

I said make special dish on the normal chef\n

Italian chef. Now these are going to be two\n

overrode that original function. So chef makes\n

So that's kind of how overriding can be useful.\n

want to change, like what it's doing, or modify\n

do that. Now, just a quick terminology. So\n

And then we would call this Italian chef class\n

from the chef class, which is the superclass\n

is you're essentially creating a class and\n

another class inside of it. And then you can\n

add on to it, or you can override the functions\n

If you enjoyed the video, please leave a like\nand subscribe.

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