well hello internet and welcome to my
well hello internet and welcome to my C++ programming tutorial in this
C++ programming tutorial in this
C++ programming tutorial in this tutorial I’m going to teach the entire
tutorial I’m going to teach the entire
tutorial I’m going to teach the entire C++ programming language in one video in
C++ programming language in one video in
C++ programming language in one video in the description underneath the video
the description underneath the video
the description underneath the video you’re going to see links to all the
you’re going to see links to all the
you’re going to see links to all the individual parts so that should help you
individual parts so that should help you
individual parts so that should help you get it to exactly what you want and I’m
get it to exactly what you want and I’m
get it to exactly what you want and I’m not going to waste any time covering
not going to waste any time covering
not going to waste any time covering installation if you guys want me to
installation if you guys want me to
installation if you guys want me to cover that just leave a comment down
cover that just leave a comment down
cover that just leave a comment down below and I’ll do that later so I have a
below and I’ll do that later so I have a
below and I’ll do that later so I have a lot to do so let’s get into it
lot to do so let’s get into it
lot to do so let’s get into it okay so what I have here on the left
okay so what I have here on the left
okay so what I have here on the left side of the screen is a basic TextEdit
side of the screen is a basic TextEdit
side of the screen is a basic TextEdit or what I have here on the right side of
or what I have here on the right side of
or what I have here on the right side of screen is a terminal everything is going
screen is a terminal everything is going
screen is a terminal everything is going to be exactly the same as long as you
to be exactly the same as long as you
to be exactly the same as long as you use G plus plus to compile your programs
use G plus plus to compile your programs
use G plus plus to compile your programs no matter if you’re on Mac Windows or on
no matter if you’re on Mac Windows or on
no matter if you’re on Mac Windows or on a Linux operating system so the very
a Linux operating system so the very
a Linux operating system so the very first thing we’re going to do here is
first thing we’re going to do here is
first thing we’re going to do here is cover comments this is a comment just
cover comments this is a comment just
cover comments this is a comment just like many other languages you can create
like many other languages you can create
like many other languages you can create a comment just by putting two dashes and
a comment just by putting two dashes and
a comment just by putting two dashes and then whatever you want and if you want a
then whatever you want and if you want a
then whatever you want and if you want a multi-line comment you can just type in
multi-line comment you can just type in
multi-line comment you can just type in multi-line and then close that off
multi-line and then close that off
multi-line and then close that off though there is commenting and c++ first
though there is commenting and c++ first
though there is commenting and c++ first thing we’re going to do here is include
thing we’re going to do here is include
thing we’re going to do here is include some outside libraries I’m going to have
some outside libraries I’m going to have
some outside libraries I’m going to have some functions that we’re going to want
some functions that we’re going to want
some functions that we’re going to want to use so this one’s going to allow us
to use so this one’s going to allow us
to use so this one’s going to allow us to use function called C out and a whole
to use function called C out and a whole
to use function called C out and a whole bunch of other different things you’re
bunch of other different things you’re
bunch of other different things you’re going to see here in a second that’ll be
going to see here in a second that’ll be
going to see here in a second that’ll be used for vectors this will be used for
used for vectors this will be used for
used for vectors this will be used for strings and then this will be used for
strings and then this will be used for
strings and then this will be used for file i/o now all of your code is going
file i/o now all of your code is going
file i/o now all of your code is going to be contained inside of a main
to be contained inside of a main
to be contained inside of a main function like this and then you’re going
function like this and then you’re going
function like this and then you’re going to have a curly bracket and then you
to have a curly bracket and then you
to have a curly bracket and then you have a closing curly bracket now inside
have a closing curly bracket now inside
have a closing curly bracket now inside of here you could call the function C
of here you could call the function C
of here you could call the function C out either using C out or STD C out like
out either using C out or STD C out like
out either using C out or STD C out like this what I want to do is get rid of
this what I want to do is get rid of
this what I want to do is get rid of this part and how I get rid of that is
this part and how I get rid of that is
this part and how I get rid of that is right here right after the include
right here right after the include
right here right after the include statement so I’m going to type in using
statement so I’m going to type in using
statement so I’m going to type in using namespace STD keep me from having to
namespace STD keep me from having to
namespace STD keep me from having to type that out every single time now if
type that out every single time now if
type that out every single time now if you wanted to do a basic hello world
you wanted to do a basic hello world
you wanted to do a basic hello world type of statement here all we’re going
type of statement here all we’re going
type of statement here all we’re going to have to do is type in hello world
to have to do is type in hello world
to have to do is type in hello world using C out which outputs the text that
using C out which outputs the text that
using C out which outputs the text that we have here and a carriage return
we have here and a carriage return
we have here and a carriage return whenever we type in the same brackets
whenever we type in the same brackets
whenever we type in the same brackets you see right there and ndele that’s for
you see right there and ndele that’s for
you see right there and ndele that’s for the carriage return and this right here
the carriage return and this right here
the carriage return and this right here saying we went out to put this on our
saying we went out to put this on our
saying we went out to put this on our screen the other thing we need to do
screen the other thing we need to do
screen the other thing we need to do here is call return zero you’re always
here is call return zero you’re always
here is call return zero you’re always going to do this and zero stands for the
going to do this and zero stands for the
going to do this and zero stands for the execution went through
execution went through
execution went through perfectly fine so just to keep
perfectly fine so just to keep
perfectly fine so just to keep everything simple jump over here in the
everything simple jump over here in the
everything simple jump over here in the terminal and this is the command I’m
terminal and this is the command I’m
terminal and this is the command I’m going to use to run this it’s called see
going to use to run this it’s called see
going to use to run this it’s called see Tut and make sure with your C++ programs
Tut and make sure with your C++ programs
Tut and make sure with your C++ programs you always end them with CP pxz
you always end them with CP pxz
you always end them with CP pxz extension then right here I’m saying
extension then right here I’m saying
extension then right here I’m saying that I want to use the version 11 of C++
that I want to use the version 11 of C++
that I want to use the version 11 of C++ then I’m going to compile that and then
then I’m going to compile that and then
then I’m going to compile that and then to run it I’m going to put period for it
to run it I’m going to put period for it
to run it I’m going to put period for it slash a dot out if you’re on Windows you
slash a dot out if you’re on Windows you
slash a dot out if you’re on Windows you would just type in a and you can see
would just type in a and you can see
would just type in a and you can see hello world prints out red like that so
hello world prints out red like that so
hello world prints out red like that so the next thing we want to discuss here
the next thing we want to discuss here
the next thing we want to discuss here are variables and datatypes
are variables and datatypes
are variables and datatypes now variables start with a letter and
now variables start with a letter and
now variables start with a letter and can contain of course additional letters
can contain of course additional letters
can contain of course additional letters numbers or underscores but they must
numbers or underscores but they must
numbers or underscores but they must start off with the letter and here we’re
start off with the letter and here we’re
start off with the letter and here we’re going to actually create a constant
going to actually create a constant
going to actually create a constant variable which is going to be of type
variable which is going to be of type
variable which is going to be of type datatype double which means that it
datatype double which means that it
datatype double which means that it contains floating-point numbers or
contains floating-point numbers or
contains floating-point numbers or decimal places and here we’re going to
decimal places and here we’re going to
decimal places and here we’re going to give it the value of 3.14159265 35 and
give it the value of 3.14159265 35 and
give it the value of 3.14159265 35 and once again constant being here just
once again constant being here just
once again constant being here just means that this value cannot be changed
means that this value cannot be changed
means that this value cannot be changed and normally whenever you define
and normally whenever you define
and normally whenever you define constant variables you make their names
constant variables you make their names
constant variables you make their names in all upper cases other data types that
in all upper cases other data types that
in all upper cases other data types that are available to you are characters
are available to you are characters
are available to you are characters which contain just one character and
which contain just one character and
which contain just one character and they are going to be surrounded by
they are going to be surrounded by
they are going to be surrounded by single quotes so let’s say I have a
single quotes so let’s say I have a
single quotes so let’s say I have a grade equal to and a write like that and
grade equal to and a write like that and
grade equal to and a write like that and there you go and a character very
there you go and a character very
there you go and a character very specifically is going to take up one
specifically is going to take up one
specifically is going to take up one byte inside of memory boolean s– which
byte inside of memory boolean s– which
byte inside of memory boolean s– which normally start with is whenever you’re
normally start with is whenever you’re
normally start with is whenever you’re defining the variable name can contain
defining the variable name can contain
defining the variable name can contain true which is going to be countable to 1
true which is going to be countable to 1
true which is going to be countable to 1 or false which is going to be comparable
or false which is going to be comparable
or false which is going to be comparable to 0 in Saur integers are just whole
to 0 in Saur integers are just whole
to 0 in Saur integers are just whole numbers without decimal places floats
numbers without decimal places floats
numbers without decimal places floats are floating-point numbers just like
are floating-point numbers just like
are floating-point numbers just like doubles and they normally are accurate
doubles and they normally are accurate
doubles and they normally are accurate up to 6 decimal places let’s just say
up to 6 decimal places let’s just say
up to 6 decimal places let’s just say favorite number and just copy this guy
favorite number and just copy this guy
favorite number and just copy this guy and doubles of course like I said before
and doubles of course like I said before
and doubles of course like I said before are also floating-point numbers but they
are also floating-point numbers but they
are also floating-point numbers but they tend to be accurate up to around 15
tend to be accurate up to around 15
tend to be accurate up to around 15 digits in length and then of course if I
digits in length and then of course if I
digits in length and then of course if I want to output one of these variables on
want to output one of these variables on
want to output one of these variables on the screen I’m going to use C out again
the screen I’m going to use C out again
the screen I’m going to use C out again and then I could say favorite number
and then I could say favorite number
and then I could say favorite number inside of double quotes and then to
inside of double quotes and then to
inside of double quotes and then to output it
output it
output it I just put another bracket inside of
I just put another bracket inside of
I just put another bracket inside of there face
there face
there face nom and then of course and L for a
nom and then of course and L for a
nom and then of course and L for a character turn in there you can see
character turn in there you can see
character turn in there you can see favorite number 3.14159 now of course
favorite number 3.14159 now of course
favorite number 3.14159 now of course there are other data types that are
there are other data types that are
there are other data types that are available we have short ends which are
available we have short ends which are
available we have short ends which are going to be at least 16 bits in size
going to be at least 16 bits in size
going to be at least 16 bits in size long int which are going to be at least
long int which are going to be at least
long int which are going to be at least 32 bits long long int that are going to
32 bits long long int that are going to
32 bits long long int that are going to be at least 64 unsigned int which are
be at least 64 unsigned int which are
be at least 64 unsigned int which are going to be the same size as the signed
going to be the same size as the signed
going to be the same size as the signed version and long doubles which are not
version and long doubles which are not
version and long doubles which are not less in size than regular old doubles if
less in size than regular old doubles if
less in size than regular old doubles if you want to find out the number of bytes
you want to find out the number of bytes
you want to find out the number of bytes for a data type we could come in here
for a data type we could come in here
for a data type we could come in here and go to C out and say something like
and go to C out and say something like
and go to C out and say something like size of int we could then call up size
size of int we could then call up size
size of int we could then call up size of and put my age inside of there since
of and put my age inside of there since
of and put my age inside of there since it is an int and inside of C++ all
it is an int and inside of C++ all
it is an int and inside of C++ all statements end with a semicolon so we
statements end with a semicolon so we
statements end with a semicolon so we could just jump down here keep
could just jump down here keep
could just jump down here keep everything on the screen and go like
everything on the screen and go like
everything on the screen and go like that compile and execute you can see
that compile and execute you can see
that compile and execute you can see right here size of an int is 4 bytes if
right here size of an int is 4 bytes if
right here size of an int is 4 bytes if I would then go in do exactly the same
I would then go in do exactly the same
I would then go in do exactly the same things for characters bullying’s floats
things for characters bullying’s floats
things for characters bullying’s floats and doubles and execute you can see how
and doubles and execute you can see how
and doubles and execute you can see how many bytes are in each one of those as
many bytes are in each one of those as
many bytes are in each one of those as well if you’re wondering how big a
well if you’re wondering how big a
well if you’re wondering how big a number can be based off of bytes and so
number can be based off of bytes and so
number can be based off of bytes and so forth and so on let’s go in here and
forth and so on let’s go in here and
forth and so on let’s go in here and let’s create the largest int that we can
let’s create the largest int that we can
let’s create the largest int that we can possibly create and whenever we know the
possibly create and whenever we know the
possibly create and whenever we know the fact how many bytes an INT can contain
fact how many bytes an INT can contain
fact how many bytes an INT can contain we can then go in and define exactly how
we can then go in and define exactly how
we can then go in and define exactly how large that number would be and you can
large that number would be and you can
large that number would be and you can see right here this is the biggest
see right here this is the biggest
see right here this is the biggest integer we could possibly have and if we
integer we could possibly have and if we
integer we could possibly have and if we went down here and said hey let’s go and
went down here and said hey let’s go and
went down here and said hey let’s go and up with that like this and you can see
up with that like this and you can see
up with that like this and you can see it prints out exactly the way that you
it prints out exactly the way that you
it prints out exactly the way that you would expect it to however if we go one
would expect it to however if we go one
would expect it to however if we go one over and put an 8 in there and said save
over and put an 8 in there and said save
over and put an 8 in there and said save that and recompile you’re going to see
that and recompile you’re going to see
that and recompile you’re going to see that you get completely different
that you get completely different
that you get completely different results see it comes back as a negative
results see it comes back as a negative
results see it comes back as a negative number that’s just the demonstration of
number that’s just the demonstration of
number that’s just the demonstration of what happens whenever you go outside of
what happens whenever you go outside of
what happens whenever you go outside of the bounds using your different data
the bounds using your different data
the bounds using your different data types when it comes to arithmetic you’re
types when it comes to arithmetic you’re
types when it comes to arithmetic you’re going to be able to use plus and minus
going to be able to use plus and minus
going to be able to use plus and minus and multiplication and division as well
and multiplication and division as well
and multiplication and division as well as modulus which is going to return the
as modulus which is going to return the
as modulus which is going to return the remainder of a division we’re also going
remainder of a division we’re also going
remainder of a division we’re also going to be able to use shorthand incremental
to be able to use shorthand incremental
to be able to use shorthand incremental notation as well as decremental give you
notation as well as decremental give you
notation as well as decremental give you an example of what that looks like
an example of what that looks like
an example of what that looks like you can see right there on your screen
you can see right there on your screen
you can see right there on your screen and exactly how you would perform
and exactly how you would perform
and exactly how you would perform addition if you wanted output that on
addition if you wanted output that on
addition if you wanted output that on the screen like this and to demonstrate
the screen like this and to demonstrate
the screen like this and to demonstrate the shortcuts for increments and
the shortcuts for increments and
the shortcuts for increments and decrements let’s say that we have an int
decrements let’s say that we have an int
decrements let’s say that we have an int and I’m just going to give call it 5 and
and I’m just going to give call it 5 and
and I’m just going to give call it 5 and give it the value of 5 then output on
give it the value of 5 then output on
give it the value of 5 then output on our screen 5 plus plus is equal to and
our screen 5 plus plus is equal to and
our screen 5 plus plus is equal to and then take the variable 5 5 and increment
then take the variable 5 5 and increment
then take the variable 5 5 and increment it I’ll then increment it from the left
it I’ll then increment it from the left
it I’ll then increment it from the left side and then I’ll decrement it from the
side and then I’ll decrement it from the
side and then I’ll decrement it from the right side and then I will decrement it
right side and then I will decrement it
right side and then I will decrement it from the left side and you see what’s
from the left side and you see what’s
from the left side and you see what’s going on right here in this situation
going on right here in this situation
going on right here in this situation whenever you increment from the right
whenever you increment from the right
whenever you increment from the right side it is going to actually perform
side it is going to actually perform
side it is going to actually perform that action after it gets the current
that action after it gets the current
that action after it gets the current value of 5 that’s the reason why you see
value of 5 that’s the reason why you see
value of 5 that’s the reason why you see 5 here then over here whenever you
5 here then over here whenever you
5 here then over here whenever you increment it on the left side it is
increment it on the left side it is
increment it on the left side it is going to increment it first it’s
going to increment it first it’s
going to increment it first it’s remember it currently has a value of 6
remember it currently has a value of 6
remember it currently has a value of 6 because that’s what happened up here and
because that’s what happened up here and
because that’s what happened up here and that’s the reason why you get a 7 over
that’s the reason why you get a 7 over
that’s the reason why you get a 7 over here and likewise whenever you have
here and likewise whenever you have
here and likewise whenever you have decrement on the right side it occurs
decrement on the right side it occurs
decrement on the right side it occurs after the value is taken here and then
after the value is taken here and then
after the value is taken here and then here you see that both of them are
here you see that both of them are
here you see that both of them are decremented or we’re back at 5 again
decremented or we’re back at 5 again
decremented or we’re back at 5 again we’d also be able to come in here and
we’d also be able to come in here and
we’d also be able to come in here and use another form of shorthand assignment
use another form of shorthand assignment
use another form of shorthand assignment notation by going 5 plus or equal to and
notation by going 5 plus or equal to and
notation by going 5 plus or equal to and let’s say 5 in this situation that right
let’s say 5 in this situation that right
let’s say 5 in this situation that right there is going to be equivalent to if
there is going to be equivalent to if
there is going to be equivalent to if you had 5 is equal to 5 plus 5 right
you had 5 is equal to 5 plus 5 right
you had 5 is equal to 5 plus 5 right like that or let’s change this into 6 so
like that or let’s change this into 6 so
like that or let’s change this into 6 so it’s not quite so confusing and yes you
it’s not quite so confusing and yes you
it’s not quite so confusing and yes you could put multiple statements here on
could put multiple statements here on
could put multiple statements here on the same line just as long as you have
the same line just as long as you have
the same line just as long as you have semicolons that’s how C++ defines that a
semicolons that’s how C++ defines that a
semicolons that’s how C++ defines that a statement has ended another thing that’s
statement has ended another thing that’s
statement has ended another thing that’s important is to understand order of
important is to understand order of
important is to understand order of operation which basically it states that
operation which basically it states that
operation which basically it states that if you have some calculation that’s
if you have some calculation that’s
if you have some calculation that’s being performed the multiplication and
being performed the multiplication and
being performed the multiplication and division are going to be performed
division are going to be performed
division are going to be performed before any addition or subtraction and
before any addition or subtraction and
before any addition or subtraction and you can see right here exactly what
you can see right here exactly what
you can see right here exactly what we’re doing here I have braces around
we’re doing here I have braces around
we’re doing here I have braces around the additions and subtractions and up
the additions and subtractions and up
the additions and subtractions and up here I do not and here if I execute you
here I do not and here if I execute you
here I do not and here if I execute you can see I get dramatically different
can see I get dramatically different
can see I get dramatically different results why is that well in this
results why is that well in this
results why is that well in this situation we are going to have the
situation we are going to have the
situation we are going to have the multiplication occur first that’s where
multiplication occur first that’s where
multiplication occur first that’s where you’re going to get 6 right here then
you’re going to get 6 right here then
you’re going to get 6 right here then we’re going to jump in and have this add
we’re going to jump in and have this add
we’re going to jump in and have this add up to 3 which comes to negative 3 in
up to 3 which comes to negative 3 in
up to 3 which comes to negative 3 in this situation we’re going to perform
this situation we’re going to perform
this situation we’re going to perform addition and subtraction first which is
addition and subtraction first which is
addition and subtraction first which is going to give you a value of 0 so when
going to give you a value of 0 so when
going to give you a value of 0 so when that’s multiplied times 2 you’re going
that’s multiplied times 2 you’re going
that’s multiplied times 2 you’re going to get 0 so use braces all the time it’s
to get 0 so use braces all the time it’s
to get 0 so use braces all the time it’s going to save you a lot of hassle now
going to save you a lot of hassle now
going to save you a lot of hassle now let’s say we come in here
let’s say we come in here
let’s say we come in here and we want to show some division here
and we want to show some division here
and we want to show some division here on our screen and this is exactly how we
on our screen and this is exactly how we
on our screen and this is exactly how we do that 4/5 well if we execute that
do that 4/5 well if we execute that
do that 4/5 well if we execute that might not get the result we were looking
might not get the result we were looking
might not get the result we were looking for which into this situation comes out
for which into this situation comes out
for which into this situation comes out to zero what happens whenever we want to
to zero what happens whenever we want to
to zero what happens whenever we want to actually show a floating-point number
actually show a floating-point number
actually show a floating-point number here with decimal places instead of
here with decimal places instead of
here with decimal places instead of basically just coming out to zero it’s
basically just coming out to zero it’s
basically just coming out to zero it’s actually very simple just come in here
actually very simple just come in here
actually very simple just come in here and we’re going to perform what is
and we’re going to perform what is
and we’re going to perform what is called casting to cast from any of the
called casting to cast from any of the
called casting to cast from any of the different data types you’re going to
different data types you’re going to
different data types you’re going to take the type that you want to cast to
take the type that you want to cast to
take the type that you want to cast to put it between these parentheses and you
put it between these parentheses and you
put it between these parentheses and you can see here we now compile and execute
can see here we now compile and execute
can see here we now compile and execute you’re going to get exactly what you
you’re going to get exactly what you
you’re going to get exactly what you wanted and of course these can be
wanted and of course these can be
wanted and of course these can be performed by putting int in side of here
performed by putting int in side of here
performed by putting int in side of here to cast to an integer even though that’s
to cast to an integer even though that’s
to cast to an integer even though that’s exactly what it is
exactly what it is
exactly what it is characters as well as doubles right like
characters as well as doubles right like
characters as well as doubles right like that now you can get rid of all this
that now you can get rid of all this
that now you can get rid of all this stuff here so we can focus in on the if
stuff here so we can focus in on the if
stuff here so we can focus in on the if statement now the if statements just
statement now the if statements just
statement now the if statements just basically going to execute different
basically going to execute different
basically going to execute different code depending upon different conditions
code depending upon different conditions
code depending upon different conditions you’re going to have comparison
you’re going to have comparison
you’re going to have comparison operators which are going to be equal to
operators which are going to be equal to
operators which are going to be equal to not equal to greater than less than
not equal to greater than less than
not equal to greater than less than greater than or equal to or less than an
greater than or equal to or less than an
greater than or equal to or less than an equal to you’re also going to have
equal to you’re also going to have
equal to you’re also going to have logical operators which are going to be
logical operators which are going to be
logical operators which are going to be and or or not and they’re going to come
and or or not and they’re going to come
and or or not and they’re going to come in the form of and or or not let’s go
in the form of and or or not let’s go
in the form of and or or not let’s go and take a look at some examples of how
and take a look at some examples of how
and take a look at some examples of how we could use these let’s say that we
we could use these let’s say that we
we could use these let’s say that we create an age which is equal to 70 years
create an age which is equal to 70 years
create an age which is equal to 70 years old and another age at last exam let’s
old and another age at last exam let’s
old and another age at last exam let’s say we want to set up a little program
say we want to set up a little program
say we want to set up a little program here that it’s going to define if a
here that it’s going to define if a
here that it’s going to define if a person is going to be able to drive or
person is going to be able to drive or
person is going to be able to drive or not and then we have is not intoxicated
not and then we have is not intoxicated
not and then we have is not intoxicated and we’re going to set that to true
and we’re going to set that to true
and we’re going to set that to true always a good thing if you’re going to
always a good thing if you’re going to
always a good thing if you’re going to drive now we’re going to come in here
drive now we’re going to come in here
drive now we’re going to come in here with our if statements we’re going to
with our if statements we’re going to
with our if statements we’re going to say something like if the age is greater
say something like if the age is greater
say something like if the age is greater than or equal to one and there’s the
than or equal to one and there’s the
than or equal to one and there’s the logical operator make sure you close all
logical operator make sure you close all
logical operator make sure you close all the brackets off the right way age is
the brackets off the right way age is
the brackets off the right way age is less than 16 in this situation Oh in
less than 16 in this situation Oh in
less than 16 in this situation Oh in that situation we’re going to say that
that situation we’re going to say that
that situation we’re going to say that they cannot drive now if we want to
they cannot drive now if we want to
they cannot drive now if we want to check another condition we’re just going
check another condition we’re just going
check another condition we’re just going to type in else if in this situation
to type in else if in this situation
to type in else if in this situation let’s check to see if they’re
let’s check to see if they’re
let’s check to see if they’re intoxicated in this situation we’re
intoxicated in this situation we’re
intoxicated in this situation we’re going to use the not symbol and we’re
going to use the not symbol and we’re
going to use the not symbol and we’re going to say is not intoxicated and all
going to say is not intoxicated and all
going to say is not intoxicated and all that’s going to do is take this true
that’s going to do is take this true
that’s going to do is take this true right here the not in this situation and
right here the not in this situation and
right here the not in this situation and turn it into false and in that situation
turn it into false and in that situation
turn it into false and in that situation where say you can’t try
where say you can’t try
where say you can’t try again I could also come in here and do
again I could also come in here and do
again I could also come in here and do an even more convoluted thing if and it
an even more convoluted thing if and it
an even more convoluted thing if and it could say something like age is greater
could say something like age is greater
could say something like age is greater than or equal to 80 and then do another
than or equal to 80 and then do another
than or equal to 80 and then do another completely different comparison age is
completely different comparison age is
completely different comparison age is greater than 100 or more brackets here
greater than 100 or more brackets here
greater than 100 or more brackets here age – age at last exam and then close
age – age at last exam and then close
age – age at last exam and then close that off greater than five and then
that off greater than five and then
that off greater than five and then close these off so what I’m basically
close these off so what I’m basically
close these off so what I’m basically saying here is if the person is over the
saying here is if the person is over the
saying here is if the person is over the age of 100 we’re not going to allow them
age of 100 we’re not going to allow them
age of 100 we’re not going to allow them to drive if they are going to be over
to drive if they are going to be over
to drive if they are going to be over the age of 80 or equal to we’re
the age of 80 or equal to we’re
the age of 80 or equal to we’re basically going to require them to take
basically going to require them to take
basically going to require them to take an exam every five years to verify that
an exam every five years to verify that
an exam every five years to verify that they are actually still able to drive
they are actually still able to drive
they are actually still able to drive it’s kind of a convoluted example but
it’s kind of a convoluted example but
it’s kind of a convoluted example but I’m just trying to find a reason to be
I’m just trying to find a reason to be
I’m just trying to find a reason to be able to come in here and show you how
able to come in here and show you how
able to come in here and show you how all these different things work and in
all these different things work and in
all these different things work and in that situation we’re going to say that
that situation we’re going to say that
that situation we’re going to say that they can’t drive and then finally where
they can’t drive and then finally where
they can’t drive and then finally where everything else that isn’t checked if we
everything else that isn’t checked if we
everything else that isn’t checked if we want them to have the ability to drive
want them to have the ability to drive
want them to have the ability to drive if they make it the hallway down here
if they make it the hallway down here
if they make it the hallway down here we’re going to just type in else and
we’re going to just type in else and
we’re going to just type in else and there you go you’re going to see that
there you go you’re going to see that
there you go you’re going to see that that works for you and here if we
that works for you and here if we
that works for you and here if we execute it you’re going to see that yes
execute it you’re going to see that yes
execute it you’re going to see that yes indeed this person can drive so that’s a
indeed this person can drive so that’s a
indeed this person can drive so that’s a pretty convoluted example of how to use
pretty convoluted example of how to use
pretty convoluted example of how to use if statements as well as else and else
if statements as well as else and else
if statements as well as else and else if now let’s take a look at switch
if now let’s take a look at switch
if now let’s take a look at switch statement which is basically going to be
statement which is basically going to be
statement which is basically going to be used whenever you have a limited number
used whenever you have a limited number
used whenever you have a limited number of possible options so let’s say we have
of possible options so let’s say we have
of possible options so let’s say we have int greeting option and let’s say they
int greeting option and let’s say they
int greeting option and let’s say they chose two then what we’re going to be
chose two then what we’re going to be
chose two then what we’re going to be able to do is check the versions or the
able to do is check the versions or the
able to do is check the versions or the values of greeting option with our
values of greeting option with our
values of greeting option with our switch statement put it inside of curly
switch statement put it inside of curly
switch statement put it inside of curly brackets again we’re going to say case
brackets again we’re going to say case
brackets again we’re going to say case if the value of greeting option is equal
if the value of greeting option is equal
if the value of greeting option is equal to 1 well then we’re going to say that
to 1 well then we’re going to say that
to 1 well then we’re going to say that we want to print out on the screen
we want to print out on the screen
we want to print out on the screen Bonjour then to jump out of the switch
Bonjour then to jump out of the switch
Bonjour then to jump out of the switch statement all together we’re going to
statement all together we’re going to
statement all together we’re going to type in break and if you didn’t check
type in break and if you didn’t check
type in break and if you didn’t check that it’s going to continue to check all
that it’s going to continue to check all
that it’s going to continue to check all of the other possible values like it
of the other possible values like it
of the other possible values like it will jump down here if you don’t have
will jump down here if you don’t have
will jump down here if you don’t have break inside and check to see if it has
break inside and check to see if it has
break inside and check to see if it has the value of 2 so you want to make sure
the value of 2 so you want to make sure
the value of 2 so you want to make sure the breaks in there
the breaks in there
the breaks in there they could have hola and all these other
they could have hola and all these other
they could have hola and all these other different options and then finally with
different options and then finally with
different options and then finally with the switch statement if you want to have
the switch statement if you want to have
the switch statement if you want to have a default thing that it’s going to do if
a default thing that it’s going to do if
a default thing that it’s going to do if none of the other things match you just
none of the other things match you just
none of the other things match you just type in default and then see out and
type in default and then see out and
type in default and then see out and hello right like that
hello right like that
hello right like that need break here in this situation and
need break here in this situation and
need break here in this situation and you can see based off the fact that they
you can see based off the fact that they
you can see based off the fact that they did enter a to hear that Jolla prints
did enter a to hear that Jolla prints
did enter a to hear that Jolla prints out on the screen that’s basically
out on the screen that’s basically
out on the screen that’s basically everything you need to know about the
everything you need to know about the
everything you need to know about the switch statement I will take a look at
switch statement I will take a look at
switch statement I will take a look at the ternary operator which is going to
the ternary operator which is going to
the ternary operator which is going to perform an assignment based off of a
perform an assignment based off of a
perform an assignment based off of a condition and its basic formats going to
condition and its basic formats going to
condition and its basic formats going to be variable is equal to there’s going to
be variable is equal to there’s going to
be variable is equal to there’s going to be a condition here followed by a
be a condition here followed by a
be a condition here followed by a question mark and this is the value it’s
question mark and this is the value it’s
question mark and this is the value it’s going to be assigned if it is true and
going to be assigned if it is true and
going to be assigned if it is true and this is going to be the value that’s
this is going to be the value that’s
this is going to be the value that’s assigned if it’s false and to show you a
assigned if it’s false and to show you a
assigned if it’s false and to show you a real example let’s say we have integer
real example let’s say we have integer
real example let’s say we have integer largest num and in this situation I’m
largest num and in this situation I’m
largest num and in this situation I’m going to use real numbers we’re going to
going to use real numbers we’re going to
going to use real numbers we’re going to have our condition is 5 greater than to
have our condition is 5 greater than to
have our condition is 5 greater than to put our question mark if it’s true then
put our question mark if it’s true then
put our question mark if it’s true then we’re going to assign the value of 5 to
we’re going to assign the value of 5 to
we’re going to assign the value of 5 to largest number and if it’s false we’re
largest number and if it’s false we’re
largest number and if it’s false we’re going to assign the value of 2 to that
going to assign the value of 2 to that
going to assign the value of 2 to that number and then of course we could print
number and then of course we could print
number and then of course we could print that out on the screen it’s that simple
that out on the screen it’s that simple
that out on the screen it’s that simple ternary operator and now let’s take a
ternary operator and now let’s take a
ternary operator and now let’s take a look at arrays now rays are just going
look at arrays now rays are just going
look at arrays now rays are just going to store multiple values of the same
to store multiple values of the same
to store multiple values of the same data type so let’s come in here and
data type so let’s come in here and
data type so let’s come in here and provide our data type for our array just
provide our data type for our array just
provide our data type for our array just think of a raise like boxes because
think of a raise like boxes because
think of a raise like boxes because that’s basically what they are in memory
that’s basically what they are in memory
that’s basically what they are in memory so let’s have an array here and you have
so let’s have an array here and you have
so let’s have an array here and you have to define inside of arrays how many
to define inside of arrays how many
to define inside of arrays how many boxes you need or how many pieces of
boxes you need or how many pieces of
boxes you need or how many pieces of data you want to store in them at the
data you want to store in them at the
data you want to store in them at the very beginning and then this cannot be
very beginning and then this cannot be
very beginning and then this cannot be changed we’ll look at vectors later
changed we’ll look at vectors later
changed we’ll look at vectors later whenever we want to look at a way to
whenever we want to look at a way to
whenever we want to look at a way to change those values could also come in
change those values could also come in
change those values could also come in here and let’s say we want a array full
here and let’s say we want a array full
here and let’s say we want a array full of bad numbers and it’s also going to
of bad numbers and it’s also going to
of bad numbers and it’s also going to need 5 spaces to hold these numbers this
need 5 spaces to hold these numbers this
need 5 spaces to hold these numbers this situation we could come in here and type
situation we could come in here and type
situation we could come in here and type in all these numbers we want to store
in all these numbers we want to store
in all these numbers we want to store right like that you’re going to be able
right like that you’re going to be able
right like that you’re going to be able to get the first item in the array with
to get the first item in the array with
to get the first item in the array with a label and the labels for all of these
a label and the labels for all of these
a label and the labels for all of these array items are going to start with 0 so
array items are going to start with 0 so
array items are going to start with 0 so this is going to have an index or label
this is going to have an index or label
this is going to have an index or label of 0 this is 1 2 3 4 and if we want the
of 0 this is 1 2 3 4 and if we want the
of 0 this is 1 2 3 4 and if we want the very first bad number in this array
very first bad number in this array
very first bad number in this array we’re going to type in 0 just like I
we’re going to type in 0 just like I
we’re going to type in 0 just like I said and change this to bad nums compile
said and change this to bad nums compile
said and change this to bad nums compile and execute you’re going to see the four
and execute you’re going to see the four
and execute you’re going to see the four pops up because that has the index of 0
pops up because that has the index of 0
pops up because that has the index of 0 we’re also going to be able to come in
we’re also going to be able to come in
we’re also going to be able to come in here and create multi-dimensional arrays
here and create multi-dimensional arrays
here and create multi-dimensional arrays which is just going to be boxes of boxes
which is just going to be boxes of boxes
which is just going to be boxes of boxes so let’s say I wanted to have a
so let’s say I wanted to have a
so let’s say I wanted to have a character array that’s going to be
character array that’s going to be
character array that’s going to be multi-dimensional and I’m going to have
multi-dimensional and I’m going to have
multi-dimensional and I’m going to have 5 spaces in the first array that’s
5 spaces in the first array that’s
5 spaces in the first array that’s created here
created here
created here and five in the second read that’s
and five in the second read that’s
and five in the second read that’s created here I could then come in and
created here I could then come in and
created here I could then come in and define that I want to store the letters
define that I want to store the letters
define that I want to store the letters for my name we’re going to use two curly
for my name we’re going to use two curly
for my name we’re going to use two curly brackets in this situation then we’re
brackets in this situation then we’re
brackets in this situation then we’re going to close off that first with a
going to close off that first with a
going to close off that first with a closing curly brace and then open it up
closing curly brace and then open it up
closing curly brace and then open it up again and here I can put my last name we
again and here I can put my last name we
again and here I can put my last name we jump down to the next line so it’s a
jump down to the next line so it’s a
jump down to the next line so it’s a little bit easier to see and we’re using
little bit easier to see and we’re using
little bit easier to see and we’re using characters here characters always use
characters here characters always use
characters here characters always use single quotes strings as you’re going to
single quotes strings as you’re going to
single quotes strings as you’re going to see later on always use double quotes
see later on always use double quotes
see later on always use double quotes and then finally after we have all those
and then finally after we have all those
and then finally after we have all those in put two curly braces in there closing
in put two curly braces in there closing
in put two curly braces in there closing and there you go that’s a
and there you go that’s a
and there you go that’s a multi-dimensional array if you would
multi-dimensional array if you would
multi-dimensional array if you would then want to get hold of and print out
then want to get hold of and print out
then want to get hold of and print out the let’s say the second letter in the
the let’s say the second letter in the
the let’s say the second letter in the second array you see out again second
second array you see out again second
second array you see out again second letter in second array we would go my
letter in second array we would go my
letter in second array we would go my name in this situation and we want to
name in this situation and we want to
name in this situation and we want to get the second one well in that
get the second one well in that
get the second one well in that situation second is equal to one and
situation second is equal to one and
situation second is equal to one and then the second letter in the second
then the second letter in the second
then the second letter in the second array go right like that and there you
array go right like that and there you
array go right like that and there you can see right there a pops up which is
can see right there a pops up which is
can see right there a pops up which is exactly the right one
exactly the right one
exactly the right one you could also come in and change the
you could also come in and change the
you could also come in and change the value in the array just by using its
value in the array just by using its
value in the array just by using its index
index
index so we’ll say my name and let’s say we
so we’ll say my name and let’s say we
so we’ll say my name and let’s say we want to get the first array which is
want to get the first array which is
want to get the first array which is zero in this situation and the second
zero in this situation and the second
zero in this situation and the second letter inside of it or the third letter
letter inside of it or the third letter
letter inside of it or the third letter in it in this situation and we want to
in it in this situation and we want to
in it in this situation and we want to change that to e no problem then come in
change that to e no problem then come in
change that to e no problem then come in here and change this to exactly the same
here and change this to exactly the same
here and change this to exactly the same place POW and execute and you can see
place POW and execute and you can see
place POW and execute and you can see here the new value is e just like we set
here the new value is e just like we set
here the new value is e just like we set it right there now I’m going to leave
it right there now I’m going to leave
it right there now I’m going to leave everything here because I’m going to use
everything here because I’m going to use
everything here because I’m going to use it while I demonstrate exactly how the
it while I demonstrate exactly how the
it while I demonstrate exactly how the for loop works now the for loop just
for loop works now the for loop just
for loop works now the for loop just allows you to continue executing code as
allows you to continue executing code as
allows you to continue executing code as long as the condition is true and you’re
long as the condition is true and you’re
long as the condition is true and you’re going to define it with for here I’m
going to define it with for here I’m
going to define it with for here I’m going to give the datatype for the value
going to give the datatype for the value
going to give the datatype for the value that I’m going to increment and we give
that I’m going to increment and we give
that I’m going to increment and we give it the initial value of one I’m going to
it the initial value of one I’m going to
it the initial value of one I’m going to say that we’re going to continue
say that we’re going to continue
say that we’re going to continue incrementing as long as I is less than
incrementing as long as I is less than
incrementing as long as I is less than or equal to ten and then we’ll have to
or equal to ten and then we’ll have to
or equal to ten and then we’ll have to increment it right here curly brackets
increment it right here curly brackets
increment it right here curly brackets and inside of the for loop we could go
and inside of the for loop we could go
and inside of the for loop we could go see out and just print all of these on
see out and just print all of these on
see out and just print all of these on our screen and there you can see it
our screen and there you can see it
our screen and there you can see it print it out one through ten
print it out one through ten
print it out one through ten now we could also come in here and use
now we could also come in here and use
now we could also come in here and use our multi-dimensional array by stacking
our multi-dimensional array by stacking
our multi-dimensional array by stacking inner for loops and we’ll just go for
inner for loops and we’ll just go for
inner for loops and we’ll just go for and integer J is equal to zero we’re
and integer J is equal to zero we’re
and integer J is equal to zero we’re going to use zero here because arrays
going to use zero here because arrays
going to use zero here because arrays start off with the zero index so we’re
start off with the zero index so we’re
start off with the zero index so we’re going to say wow J is less than five
going to say wow J is less than five
going to say wow J is less than five we’re going to continue to cycle through
we’re going to continue to cycle through
we’re going to continue to cycle through here and then inside of here we’re going
here and then inside of here we’re going
here and then inside of here we’re going to
to
to another for loop let’s have this BK is
another for loop let’s have this BK is
another for loop let’s have this BK is equal to zero okay is less than five
equal to zero okay is less than five
equal to zero okay is less than five increment the value of K now we can come
increment the value of K now we can come
increment the value of K now we can come in here and print out my whole entire
in here and print out my whole entire
in here and print out my whole entire name by just putting J okay inside of
name by just putting J okay inside of
name by just putting J okay inside of there and then finally see I didn’t put
there and then finally see I didn’t put
there and then finally see I didn’t put the end L in there after it’s done going
the end L in there after it’s done going
the end L in there after it’s done going through the for loop I could then come
through the for loop I could then come
through the for loop I could then come in here and put the carriage return in
in here and put the carriage return in
in here and put the carriage return in and execute and there you can see it
and execute and there you can see it
and execute and there you can see it printed out my name remember I changed
printed out my name remember I changed
printed out my name remember I changed the e here and then it went and printed
the e here and then it went and printed
the e here and then it went and printed the last name and that’s what it’s
the last name and that’s what it’s
the last name and that’s what it’s simply going to do it’s going to go to
simply going to do it’s going to go to
simply going to do it’s going to go to the first array cycle through everything
the first array cycle through everything
the first array cycle through everything using this for loop right here let’s
using this for loop right here let’s
using this for loop right here let’s come down here and then J is going to
come down here and then J is going to
come down here and then J is going to come up here and it’s going to print
come up here and it’s going to print
come up here and it’s going to print everything out so that’s how for loops
everything out so that’s how for loops
everything out so that’s how for loops work now let’s take a look at while
work now let’s take a look at while
work now let’s take a look at while loops now you’re going to use while
loops now you’re going to use while
loops now you’re going to use while loops instead of for loops when you
loops instead of for loops when you
loops instead of for loops when you don’t know ahead of time when your loop
don’t know ahead of time when your loop
don’t know ahead of time when your loop is going to end so let’s say we have a
is going to end so let’s say we have a
is going to end so let’s say we have a random number and this is how you would
random number and this is how you would
random number and this is how you would generate random numbers inside of C++ we
generate random numbers inside of C++ we
generate random numbers inside of C++ we go Rand and let’s say that I wanted to
go Rand and let’s say that I wanted to
go Rand and let’s say that I wanted to get random numbers between 1 and 100
get random numbers between 1 and 100
get random numbers between 1 and 100 modulus 100 like like that now this guy
modulus 100 like like that now this guy
modulus 100 like like that now this guy alone is going to generate random
alone is going to generate random
alone is going to generate random numbers between 0 and 99 so if I want 1
numbers between 0 and 99 so if I want 1
numbers between 0 and 99 so if I want 1 to 100 I’m going to put a 1 right here
to 100 I’m going to put a 1 right here
to 100 I’m going to put a 1 right here now with a while loop I can say that I
now with a while loop I can say that I
now with a while loop I can say that I want to continue cycling through this
want to continue cycling through this
want to continue cycling through this loop as long as random number is not
loop as long as random number is not
loop as long as random number is not equal to 100 and we could print out on
equal to 100 and we could print out on
equal to 100 and we could print out on the screen the random number every
the screen the random number every
the screen the random number every single time and in this situation let’s
single time and in this situation let’s
single time and in this situation let’s say we want to put a comma between there
say we want to put a comma between there
say we want to put a comma between there close that off but of course you’re
close that off but of course you’re
close that off but of course you’re going to need a way to get out of this
going to need a way to get out of this
going to need a way to get out of this while loop so the random number is going
while loop so the random number is going
while loop so the random number is going to have to change so go and generate
to have to change so go and generate
to have to change so go and generate another random number make sure we use
another random number make sure we use
another random number make sure we use the same thing again and then after we
the same thing again and then after we
the same thing again and then after we are done with our while loop put a
are done with our while loop put a
are done with our while loop put a carriage return in there but don’t
carriage return in there but don’t
carriage return in there but don’t forget to put the equal sign in there
forget to put the equal sign in there
forget to put the equal sign in there now let’s go and see how long it takes
now let’s go and see how long it takes
now let’s go and see how long it takes us to get to 100 there you can see it
us to get to 100 there you can see it
us to get to 100 there you can see it printed all those out right there on our
printed all those out right there on our
printed all those out right there on our screen and I don’t know I’m not going to
screen and I don’t know I’m not going to
screen and I don’t know I’m not going to count how many of those are let then
count how many of those are let then
count how many of those are let then take that long to come up with a random
take that long to come up with a random
take that long to come up with a random number of 100 another thing that’s kind
number of 100 another thing that’s kind
number of 100 another thing that’s kind of interesting is you can basically
of interesting is you can basically
of interesting is you can basically simulate exactly what a for loop does
simulate exactly what a for loop does
simulate exactly what a for loop does using a while loop the only thing is
using a while loop the only thing is
using a while loop the only thing is we’re going to have to have something
we’re going to have to have something
we’re going to have to have something that’s going to increment for us this
that’s going to increment for us this
that’s going to increment for us this index right here will do fine and in
index right here will do fine and in
index right here will do fine and in this situation of course keep it outside
this situation of course keep it outside
this situation of course keep it outside of your while loop just like we did with
of your while loop just like we did with
of your while loop just like we did with our random number before we’re going to
our random number before we’re going to
our random number before we’re going to say that we want to cycle through row as
say that we want to cycle through row as
say that we want to cycle through row as long as index is less than or equal to
long as index is less than or equal to
long as index is less than or equal to ten then inside of your output value of
ten then inside of your output value of
ten then inside of your output value of index and then of course increment your
index and then of course increment your
index and then of course increment your index right here and you can sing do
index right here and you can sing do
index right here and you can sing do pretty much exactly the same thing you
pretty much exactly the same thing you
pretty much exactly the same thing you can do with a for loop with while loop
can do with a for loop with while loop
can do with a for loop with while loop and that brings us to do while loops and
and that brings us to do while loops and
and that brings us to do while loops and they’re going to be used whenever you
they’re going to be used whenever you
they’re going to be used whenever you want to execute whatever is in the loop
want to execute whatever is in the loop
want to execute whatever is in the loop at the very least one time and I’m also
at the very least one time and I’m also
at the very least one time and I’m also going to talk about strings here for a
going to talk about strings here for a
going to talk about strings here for a second because we’re now going to also
second because we’re now going to also
second because we’re now going to also cover how to get user input we create a
cover how to get user input we create a
cover how to get user input we create a string which is just a series of
string which is just a series of
string which is just a series of characters
characters
characters that’s all string is int int number
that’s all string is int int number
that’s all string is int int number guests give this value of 0 start off
guests give this value of 0 start off
guests give this value of 0 start off and then the do-while loops just going
and then the do-while loops just going
and then the do-while loops just going to start off with do and then in the
to start off with do and then in the
to start off with do and then in the very end of it we’re going to have a
very end of it we’re going to have a
very end of it we’re going to have a while part so you know everything is
while part so you know everything is
while part so you know everything is going to be executed that is in the loop
going to be executed that is in the loop
going to be executed that is in the loop at least once even if it number guests
at least once even if it number guests
at least once even if it number guests is not equal to 4 so it number guests
is not equal to 4 so it number guests
is not equal to 4 so it number guests it’s not equal to 4 and this is going to
it’s not equal to 4 and this is going to
it’s not equal to 4 and this is going to be a basic like guessing game and you
be a basic like guessing game and you
be a basic like guessing game and you have to put a semicolon here at the end
have to put a semicolon here at the end
have to put a semicolon here at the end don’t forget that now inside of this
don’t forget that now inside of this
don’t forget that now inside of this we’re going to get some user input we’re
we’re going to get some user input we’re
we’re going to get some user input we’re going to start off by saying that the
going to start off by saying that the
going to start off by saying that the user of our program is to guess a number
user of our program is to guess a number
user of our program is to guess a number between 1 and 10 we want to allow our
between 1 and 10 we want to allow our
between 1 and 10 we want to allow our user to enter some input and to do that
user to enter some input and to do that
user to enter some input and to do that we’re going to type in get line we’re
we’re going to type in get line we’re
we’re going to type in get line we’re going to type in c i n which is going to
going to type in c i n which is going to
going to type in c i n which is going to be the source of the user input which is
be the source of the user input which is
be the source of the user input which is going to be the keyboard in this
going to be the keyboard in this
going to be the keyboard in this situation and then we’re going to have
situation and then we’re going to have
situation and then we’re going to have to say where we want that value to be
to say where we want that value to be
to say where we want that value to be stored in this situation we want to
stored in this situation we want to
stored in this situation we want to store it in the string number guest if
store it in the string number guest if
store it in the string number guest if we want to convert the string into an
we want to convert the string into an
we want to convert the string into an integer we can then go int number guest
integer we can then go int number guest
integer we can then go int number guest we need to do this because this guy
we need to do this because this guy
we need to do this because this guy right here we’re not going to be able to
right here we’re not going to be able to
right here we’re not going to be able to compare a string to an integer of 4 it’s
compare a string to an integer of 4 it’s
compare a string to an integer of 4 it’s easy enough to change we’re just going
easy enough to change we’re just going
easy enough to change we’re just going to type in s TOI
to type in s TOI
to type in s TOI which is going to convert a string into
which is going to convert a string into
which is going to convert a string into an integer and then we’ll pass in number
an integer and then we’ll pass in number
an integer and then we’ll pass in number guest which is our string and then we
guest which is our string and then we
guest which is our string and then we could print int number guest if we would
could print int number guest if we would
could print int number guest if we would like and this is going to continue to
like and this is going to continue to
like and this is going to continue to cycle until they enter the number of
cycle until they enter the number of
cycle until they enter the number of four and then if they get out of our
four and then if they get out of our
four and then if they get out of our do-while loop we could come in and go
do-while loop we could come in and go
do-while loop we could come in and go see out you win otherwise it’s going to
see out you win otherwise it’s going to
see out you win otherwise it’s going to continue to ask them as you’ll see guess
continue to ask them as you’ll see guess
continue to ask them as you’ll see guess between 1 and 10 I’ll type in 1 ask me
between 1 and 10 I’ll type in 1 ask me
between 1 and 10 I’ll type in 1 ask me again
again
again 2 now for you can see I want right so
2 now for you can see I want right so
2 now for you can see I want right so there’s user input converting from
there’s user input converting from
there’s user input converting from strings into integers do-while and a
strings into integers do-while and a
strings into integers do-while and a whole bunch of other different things
whole bunch of other different things
whole bunch of other different things let’s take a deeper look at straw
let’s take a deeper look at straw
let’s take a deeper look at straw now in C++ in comparison to C C++ is
now in C++ in comparison to C C++ is
now in C++ in comparison to C C++ is going to provide us with string objects
going to provide us with string objects
going to provide us with string objects and you’re like I said before they are
and you’re like I said before they are
and you’re like I said before they are always going to be surrounded with
always going to be surrounded with
always going to be surrounded with double quotes and just to cover this
double quotes and just to cover this
double quotes and just to cover this real briefly inside of C you would have
real briefly inside of C you would have
real briefly inside of C you would have previously made strings by saying
previously made strings by saying
previously made strings by saying something like copy array six like this
something like copy array six like this
something like copy array six like this is equal to and then created a character
is equal to and then created a character
is equal to and then created a character array so I’ll just type it happy and
array so I’ll just type it happy and
array so I’ll just type it happy and then you had to always end it with a
then you had to always end it with a
then you had to always end it with a backslash and then a zero with closing
backslash and then a zero with closing
backslash and then a zero with closing curly bracket and that’s how we were
curly bracket and that’s how we were
curly bracket and that’s how we were using strings inside of C the C++ way is
using strings inside of C the C++ way is
using strings inside of C the C++ way is much better and easier so we’re going to
much better and easier so we’re going to
much better and easier so we’re going to say string birthday string is equal to
say string birthday string is equal to
say string birthday string is equal to space in their birthday and there we are
space in their birthday and there we are
space in their birthday and there we are we’re done now we could of course
we’re done now we could of course
we’re done now we could of course combine these guys and how we’re going
combine these guys and how we’re going
combine these guys and how we’re going to combine them is with the
to combine them is with the
to combine them is with the concatenation operator or just the plus
concatenation operator or just the plus
concatenation operator or just the plus sign or you can just call it combined
sign or you can just call it combined
sign or you can just call it combined you can call it whatever you want
you can call it whatever you want
you can call it whatever you want so birthday string and there you can see
so birthday string and there you can see
so birthday string and there you can see it printed happy birthday combine both
it printed happy birthday combine both
it printed happy birthday combine both of those printing them out the screen
of those printing them out the screen
of those printing them out the screen and perform a couple other different
and perform a couple other different
and perform a couple other different operations let’s say let’s call this
operations let’s say let’s call this
operations let’s say let’s call this your name always need to define your
your name always need to define your
your name always need to define your variables before you use them and then
variables before you use them and then
variables before you use them and then I’m going to have it come in and print
I’m going to have it come in and print
I’m going to have it come in and print out the screen to get you some user
out the screen to get you some user
out the screen to get you some user input what is your name get line it’s
input what is your name get line it’s
input what is your name get line it’s going to get the user input get it from
going to get the user input get it from
going to get the user input get it from the keyboard store whatever they enter
the keyboard store whatever they enter
the keyboard store whatever they enter into your name and then I could go see
into your name and then I could go see
into your name and then I could go see out hello put your name inside of there
out hello put your name inside of there
out hello put your name inside of there what’s your name type in Derrick hello
what’s your name type in Derrick hello
what’s your name type in Derrick hello Derrick talks to me could then come in
Derrick talks to me could then come in
Derrick talks to me could then come in and create let’s say double in this
and create let’s say double in this
and create let’s say double in this situation there’s constant you don’t
situation there’s constant you don’t
situation there’s constant you don’t know what this is don’t worry about it’s
know what this is don’t worry about it’s
know what this is don’t worry about it’s just a random number of thought of or
just a random number of thought of or
just a random number of thought of or Euler thought of actually I could then
Euler thought of actually I could then
Euler thought of actually I could then go string Euler guess we want to do like
go string Euler guess we want to do like
go string Euler guess we want to do like a little quiz application uppercase
a little quiz application uppercase
a little quiz application uppercase letter right there just makes it easier
letter right there just makes it easier
letter right there just makes it easier to be able to read the variable names
to be able to read the variable names
to be able to read the variable names and then I’ll go Euler guess double and
and then I’ll go Euler guess double and
and then I’ll go Euler guess double and now come in here ask them what is those
now come in here ask them what is those
now come in here ask them what is those constants I could then get whatever they
constants I could then get whatever they
constants I could then get whatever they enter inside of here don’t worry about
enter inside of here don’t worry about
enter inside of here don’t worry about it I’m going to show you how to convert
it I’m going to show you how to convert
it I’m going to show you how to convert from doubles and or from strings to
from doubles and or from strings to
from doubles and or from strings to doubles we need to do to convert from a
doubles we need to do to convert from a
doubles we need to do to convert from a string to a double and we’re going to
string to a double and we’re going to
string to a double and we’re going to store it in Euler guess double is type
store it in Euler guess double is type
store it in Euler guess double is type in instead of sto I sto D
in instead of sto I sto D
in instead of sto I sto D right like that and you’ll learn guess
right like that and you’ll learn guess
right like that and you’ll learn guess is the string value they entered and
is the string value they entered and
is the string value they entered and then I’ll say if you older guess double
then I’ll say if you older guess double
then I’ll say if you older guess double is equal to Euler constant which you can
is equal to Euler constant which you can
is equal to Euler constant which you can see all those on the screen curly
see all those on the screen curly
see all those on the screen curly brackets again see out you are right and
brackets again see out you are right and
brackets again see out you are right and then else you are wrong up make sure you
then else you are wrong up make sure you
then else you are wrong up make sure you come in here and put it s inside of
come in here and put it s inside of
come in here and put it s inside of there Euler’s constant Euler’s constant
there Euler’s constant Euler’s constant
there Euler’s constant Euler’s constant execute what’s your name Derek what’s
execute what’s your name Derek what’s
execute what’s your name Derek what’s Euler’s constant 0.577 21 you are right
Euler’s constant 0.577 21 you are right
Euler’s constant 0.577 21 you are right you can see exactly how that works
you can see exactly how that works
you can see exactly how that works couple other things we can do with
couple other things we can do with
couple other things we can do with strings you want to get this size or the
strings you want to get this size or the
strings you want to get this size or the number of characters in a string see out
number of characters in a string see out
number of characters in a string see out size of string could you use Euler guess
size of string could you use Euler guess
size of string could you use Euler guess in this situation and then just call
in this situation and then just call
in this situation and then just call size so it’s basically exactly what you
size so it’s basically exactly what you
size so it’s basically exactly what you thought it would be when to check if a
thought it would be when to check if a
thought it would be when to check if a string is empty Euler guess again and
string is empty Euler guess again and
string is empty Euler guess again and just type in empty great to use whenever
just type in empty great to use whenever
just type in empty great to use whenever you want to test input from a user could
you want to test input from a user could
you want to test input from a user could use append also to be able to add
use append also to be able to add
use append also to be able to add strings together
strings together
strings together so we could get Euler guess and call
so we could get Euler guess and call
so we could get Euler guess and call append and then add something like was
append and then add something like was
append and then add something like was your guests bounced out of there there
your guests bounced out of there there
your guests bounced out of there there you go
you go
you go Turk point five let’s type that in you
Turk point five let’s type that in you
Turk point five let’s type that in you were wrong didn’t matter size of string
were wrong didn’t matter size of string
were wrong didn’t matter size of string is equal to three see right there
is equal to three see right there
is equal to three see right there decimal five five that’s the three is
decimal five five that’s the three is
decimal five five that’s the three is string empty 0 comes back or false
string empty 0 comes back or false
string empty 0 comes back or false it’s obviously not empty and it prints
it’s obviously not empty and it prints
it’s obviously not empty and it prints out my guests there on the screen come
out my guests there on the screen come
out my guests there on the screen come in here and create another string let’s
in here and create another string let’s
in here and create another string let’s call this dog string give it the value
call this dog string give it the value
call this dog string give it the value of dog and cat string give it the value
of dog and cat string give it the value
of dog and cat string give it the value of cat we can compare numbers so let’s
of cat we can compare numbers so let’s
of cat we can compare numbers so let’s say when we see out or compare strings
say when we see out or compare strings
say when we see out or compare strings them in with the comparison function and
them in with the comparison function and
them in with the comparison function and let’s change this to dog and this the
let’s change this to dog and this the
let’s change this to dog and this the cat and change this the dog and you can
cat and change this the dog and you can
cat and change this the dog and you can see in this situation whenever a value
see in this situation whenever a value
see in this situation whenever a value is equal like it is here dog string and
is equal like it is here dog string and
is equal like it is here dog string and dog string you’re going to get a return
dog string you’re going to get a return
dog string you’re going to get a return value of 0 you’re going to receive a 1
value of 0 you’re going to receive a 1
value of 0 you’re going to receive a 1 in this situation if it’s less than and
in this situation if it’s less than and
in this situation if it’s less than and a negative one if it’s greater than and
a negative one if it’s greater than and
a negative one if it’s greater than and this is all based off of alphabetical so
this is all based off of alphabetical so
this is all based off of alphabetical so we could also come in here and sign
we could also come in here and sign
we could also come in here and sign copies of a value to another string we
copies of a value to another string we
copies of a value to another string we go whole name is equal to and go your
go whole name is equal to and go your
go whole name is equal to and go your name a sign and I could say your name
name a sign and I could say your name
name a sign and I could say your name and there you go
and there you go
and there you go I could then get a substring so let’s
I could then get a substring so let’s
I could then get a substring so let’s say that I wanted to get the first name
say that I wanted to get the first name
say that I wanted to get the first name while ago
while ago
while ago like that dot a son and I would pass in
like that dot a son and I would pass in
like that dot a son and I would pass in the string I want to work with then the
the string I want to work with then the
the string I want to work with then the starting index from which I want to
starting index from which I want to
starting index from which I want to first start pulling characters and then
first start pulling characters and then
first start pulling characters and then the number of characters I want which is
the number of characters I want which is
the number of characters I want which is five I could then come down here change
five I could then come down here change
five I could then come down here change this to first name if I typed in my full
this to first name if I typed in my full
this to first name if I typed in my full name then you’re going to say that it
name then you’re going to say that it
name then you’re going to say that it just grabbed the substring up Derrick I
just grabbed the substring up Derrick I
just grabbed the substring up Derrick I could then perform a search on a string
could then perform a search on a string
could then perform a search on a string so let’s say that I wanted to find the
so let’s say that I wanted to find the
so let’s say that I wanted to find the index of my last name get the last name
index of my last name get the last name
index of my last name get the last name index if we did not know it I could type
index if we did not know it I could type
index if we did not know it I could type in your name and then find followed by
in your name and then find followed by
in your name and then find followed by the substring that I want to find inside
the substring that I want to find inside
the substring that I want to find inside of there and the index that I want to
of there and the index that I want to
of there and the index that I want to start searching from and then I could
start searching from and then I could
start searching from and then I could say index for last name last name index
say index for last name last name index
say index for last name last name index is my full name dot data and you can see
is my full name dot data and you can see
is my full name dot data and you can see the index starts at six and if you count
the index starts at six and if you count
the index starts at six and if you count over you’re going to see that B actually
over you’re going to see that B actually
over you’re going to see that B actually is six and also insert is going to allow
is six and also insert is going to allow
is six and also insert is going to allow me to put in a string at the index that
me to put in a string at the index that
me to put in a string at the index that I tell it to put it in so I’ll go insert
I tell it to put it in so I’ll go insert
I tell it to put it in so I’ll go insert five so starting in index five I want to
five so starting in index five I want to
five so starting in index five I want to put in the word Justin change this to
put in the word Justin change this to
put in the word Justin change this to your name just so you can see that here
your name just so you can see that here
your name just so you can see that here in a second I could also erase or delete
in a second I could also erase or delete
in a second I could also erase or delete six characters starting at the index of
six characters starting at the index of
six characters starting at the index of seven and I would just go your name
seven and I would just go your name
seven and I would just go your name again the string want to work with a
again the string want to work with a
again the string want to work with a race starting at six
race starting at six
race starting at six I want to delete six characters starting
I want to delete six characters starting
I want to delete six characters starting at the seventh index and then print it
at the seventh index and then print it
at the seventh index and then print it out there again and then finally I could
out there again and then finally I could
out there again and then finally I could also come in and replace let’s say I
also come in and replace let’s say I
also come in and replace let’s say I want to replace five characters starting
want to replace five characters starting
want to replace five characters starting at index six well there’s the index 6 so
at index six well there’s the index 6 so
at index six well there’s the index 6 so I want to replace five characters and
I want to replace five characters and
I want to replace five characters and let’s say that I want to change it to
let’s say that I want to change it to
let’s say that I want to change it to Maximus
Maximus
Maximus so my new name will be Maximus and make
so my new name will be Maximus and make
so my new name will be Maximus and make sure that is named your name and here’s
sure that is named your name and here’s
sure that is named your name and here’s my name you can see all the changes that
my name you can see all the changes that
my name you can see all the changes that are made to it right there I inserted
are made to it right there I inserted
are made to it right there I inserted just and inside of there right there I
just and inside of there right there I
just and inside of there right there I got rid of it and then right here I’ve
got rid of it and then right here I’ve
got rid of it and then right here I’ve performed a replace to change my last
performed a replace to change my last
performed a replace to change my last name to Maximus so there is a lot of
name to Maximus so there is a lot of
name to Maximus so there is a lot of stuff about strings okay now let’s talk
stuff about strings okay now let’s talk
stuff about strings okay now let’s talk about vectors now vectors are just like
about vectors now vectors are just like
about vectors now vectors are just like a raise the only real difference is that
a raise the only real difference is that
a raise the only real difference is that their size can change and how you create
their size can change and how you create
their size can change and how you create a vector is type in vector and then the
a vector is type in vector and then the
a vector is type in vector and then the datatype you want to store then then
datatype you want to store then then
datatype you want to store then then let’s say that I’m going to store or
let’s say that I’m going to store or
let’s say that I’m going to store or lottery numbers in my vector I’m going
lottery numbers in my vector I’m going
lottery numbers in my vector I’m going to decide that the initial size should
to decide that the initial size should
to decide that the initial size should be 10 I could then create an array to
be 10 I could then create an array to
be 10 I could then create an array to show you how to
show you how to
show you how to put an array in a vector and let’s say
put an array in a vector and let’s say
put an array in a vector and let’s say it has a size of five and then we’ll
it has a size of five and then we’ll
it has a size of five and then we’ll initialize it just like we did before 14
initialize it just like we did before 14
initialize it just like we did before 14 24 and 34 like that we can then go and
24 and 34 like that we can then go and
24 and 34 like that we can then go and take our vector and insert our array and
take our vector and insert our array and
take our vector and insert our array and how we’re going to do that is go lottery
how we’re going to do that is go lottery
how we’re going to do that is go lottery number
number
number effect and say that we want to start
effect and say that we want to start
effect and say that we want to start inserting at the beginning of our vector
inserting at the beginning of our vector
inserting at the beginning of our vector and then we’ll say the array that we
and then we’ll say the array that we
and then we’ll say the array that we want to insert into it and then let’s
want to insert into it and then let’s
want to insert into it and then let’s say that we only want to take the first
say that we only want to take the first
say that we only want to take the first three numbers from our array right like
three numbers from our array right like
three numbers from our array right like that we could then go see out and just
that we could then go see out and just
that we could then go see out and just print lottery number like that and at
print lottery number like that and at
print lottery number like that and at and let’s say we want what’s the third
and let’s say we want what’s the third
and let’s say we want what’s the third item which would be second index whoops
item which would be second index whoops
item which would be second index whoops like this
like this
like this we went out put that on the screen
we went out put that on the screen
we went out put that on the screen because remember it didn’t take the
because remember it didn’t take the
because remember it didn’t take the whole array just took these first three
whole array just took these first three
whole array just took these first three numbers and there you can see 14 popped
numbers and there you can see 14 popped
numbers and there you can see 14 popped up now if you would want to also come in
up now if you would want to also come in
up now if you would want to also come in here and let’s say we want to add
here and let’s say we want to add
here and let’s say we want to add another value into the fifth index
another value into the fifth index
another value into the fifth index lottery number dot insert we could then
lottery number dot insert we could then
lottery number dot insert we could then go lottery num vector
go lottery num vector
go lottery num vector begin which is the beginning of the
begin which is the beginning of the
begin which is the beginning of the vector plus five to get to the fifth
vector plus five to get to the fifth
vector plus five to get to the fifth index and then put 44 inside of there we
index and then put 44 inside of there we
index and then put 44 inside of there we could then jump down here to five and
could then jump down here to five and
could then jump down here to five and see the 44 pop dot pushback is going to
see the 44 pop dot pushback is going to
see the 44 pop dot pushback is going to add a value at the end of our vector so
add a value at the end of our vector so
add a value at the end of our vector so push back and let’s say we want to put
push back and let’s say we want to put
push back and let’s say we want to put 64 in there we then want to defined as
64 in there we then want to defined as
64 in there we then want to defined as you can see the vector resizes we then
you can see the vector resizes we then
you can see the vector resizes we then wanted to find that final value we can
wanted to find that final value we can
wanted to find that final value we can call back and it would get it for us as
call back and it would get it for us as
call back and it would get it for us as you can see right there pop back it’s
you can see right there pop back it’s
you can see right there pop back it’s going to remove the final value well is
going to remove the final value well is
going to remove the final value well is no point in doing that which in this
no point in doing that which in this
no point in doing that which in this situation would be 64 and then we could
situation would be 64 and then we could
situation would be 64 and then we could get the first value in the vector by
get the first value in the vector by
get the first value in the vector by calling front step back we could get the
calling front step back we could get the
calling front step back we could get the last element by calling back of course
last element by calling back of course
last element by calling back of course empty is going to return zero if the
empty is going to return zero if the
empty is going to return zero if the vector is not empty and a 1 or true
vector is not empty and a 1 or true
vector is not empty and a 1 or true whenever it is empty and then finally if
whenever it is empty and then finally if
whenever it is empty and then finally if we wanted to get the size of our vector
we wanted to get the size of our vector
we wanted to get the size of our vector we can do that with sighs there’s a
we can do that with sighs there’s a
we can do that with sighs there’s a rundown of all we can do with vectors
rundown of all we can do with vectors
rundown of all we can do with vectors now let’s take a look at what we can do
now let’s take a look at what we can do
now let’s take a look at what we can do with functions inside a C++ now your
with functions inside a C++ now your
with functions inside a C++ now your functions are
functions are
functions are actually going to appear before your
actually going to appear before your
actually going to appear before your main function and it basically just has
main function and it basically just has
main function and it basically just has the return type so let’s say that we
the return type so let’s say that we
the return type so let’s say that we wanted to have a function that added
wanted to have a function that added
wanted to have a function that added numbers we would have our return type
numbers we would have our return type
numbers we would have our return type for our function if it didn’t have a
for our function if it didn’t have a
for our function if it didn’t have a return type it would have void instead
return type it would have void instead
return type it would have void instead of integer and then we’re going to
of integer and then we’re going to
of integer and then we’re going to define the data types for our attributes
define the data types for our attributes
define the data types for our attributes that are going to be received by our
that are going to be received by our
that are going to be received by our function so I can um we could also set
function so I can um we could also set
function so I can um we could also set it up so that this function would have a
it up so that this function would have a
it up so that this function would have a default value which means actually you
default value which means actually you
default value which means actually you wouldn’t have to send a second attribute
wouldn’t have to send a second attribute
wouldn’t have to send a second attribute in that situation the only thing that
in that situation the only thing that
in that situation the only thing that you have to do is if you do this is all
you have to do is if you do this is all
you have to do is if you do this is all of your functions that have a default
of your functions that have a default
of your functions that have a default value or all of your attributes that
value or all of your attributes that
value or all of your attributes that have a default value have to come last
have a default value have to come last
have a default value have to come last so this has to come before that so
so this has to come before that so
so this has to come before that so that’s the only rule there and this is
that’s the only rule there and this is
that’s the only rule there and this is also known as a function prototype we
also known as a function prototype we
also known as a function prototype we could then go and type in combined value
could then go and type in combined value
could then go and type in combined value is equal to first num plus second num
is equal to first num plus second num
is equal to first num plus second num store that in there and then return the
store that in there and then return the
store that in there and then return the combined value and I did it this way so
combined value and I did it this way so
combined value and I did it this way so that I could demonstrate something else
that I could demonstrate something else
that I could demonstrate something else you could take this right here and put
you could take this right here and put
you could take this right here and put it right down here in the return part
it right down here in the return part
it right down here in the return part right there you don’t have to create a
right there you don’t have to create a
right there you don’t have to create a new variable just to perform that
new variable just to perform that
new variable just to perform that another thing I want to demonstrate
another thing I want to demonstrate
another thing I want to demonstrate since I’m up here and not inside of main
since I’m up here and not inside of main
since I’m up here and not inside of main is that you are able to overload
is that you are able to overload
is that you are able to overload functions which basically means you can
functions which basically means you can
functions which basically means you can use exactly the same name but different
use exactly the same name but different
use exactly the same name but different attributes so I could come in here even
attributes so I could come in here even
attributes so I could come in here even though I have add numbers already
though I have add numbers already
though I have add numbers already actually it’s just copy the whole thing
actually it’s just copy the whole thing
actually it’s just copy the whole thing paste it in there so there’s add numbers
paste it in there so there’s add numbers
paste it in there so there’s add numbers twice it’s okay to have add numbers the
twice it’s okay to have add numbers the
twice it’s okay to have add numbers the only problem is we have to have
only problem is we have to have
only problem is we have to have different attributes inside of here
different attributes inside of here
different attributes inside of here so let’s say we have second num and we
so let’s say we have second num and we
so let’s say we have second num and we also have another integer which is going
also have another integer which is going
also have another integer which is going to be third num and like I said before
to be third num and like I said before
to be third num and like I said before we don’t need all that we could just go
we don’t need all that we could just go
we don’t need all that we could just go return and perform our addition right
return and perform our addition right
return and perform our addition right inside of here
inside of here
inside of here second num third num and return that now
second num third num and return that now
second num third num and return that now let’s jump down inside of main and
let’s jump down inside of main and
let’s jump down inside of main and actually call these functions if I
actually call these functions if I
actually call these functions if I didn’t mention before functions
didn’t mention before functions
didn’t mention before functions basically allow you to reuse code and
basically allow you to reuse code and
basically allow you to reuse code and also add a certain level of organization
also add a certain level of organization
also add a certain level of organization to your code so here add nums I’m
to your code so here add nums I’m
to your code so here add nums I’m passing in one I’m going to use the
passing in one I’m going to use the
passing in one I’m going to use the default value of zero they’re not going
default value of zero they’re not going
default value of zero they’re not going to pass anything and just to demonstrate
to pass anything and just to demonstrate
to pass anything and just to demonstrate it and then I’ll show the other one as
it and then I’ll show the other one as
it and then I’ll show the other one as well at numbers one five
well at numbers one five
well at numbers one five five and six and though you can see if I
five and six and though you can see if I
five and six and though you can see if I execute that right there you got one and
execute that right there you got one and
execute that right there you got one and twelve pop back on the screen let’s go
twelve pop back on the screen let’s go
twelve pop back on the screen let’s go and create a little bit more complicated
and create a little bit more complicated
and create a little bit more complicated function here and this is basically what
function here and this is basically what
function here and this is basically what they call a recursive function and this
they call a recursive function and this
they call a recursive function and this is normally demonstrated using the
is normally demonstrated using the
is normally demonstrated using the getting of factorial so that’s what I’ll
getting of factorial so that’s what I’ll
getting of factorial so that’s what I’ll do
do
do get factorial int number and this is
get factorial int number and this is
get factorial int number and this is going to be a function that calls itself
going to be a function that calls itself
going to be a function that calls itself from inside of itself sounds way more
from inside of itself sounds way more
from inside of itself sounds way more complicated than this so I’m going to go
complicated than this so I’m going to go
complicated than this so I’m going to go and create an integer called sum then
and create an integer called sum then
and create an integer called sum then I’m going to say if number which is
I’m going to say if number which is
I’m going to say if number which is going to be passed inside of here is
going to be passed inside of here is
going to be passed inside of here is equal to one then I want to have some
equal to one then I want to have some
equal to one then I want to have some equal to one LS sum is going to be equal
equal to one LS sum is going to be equal
equal to one LS sum is going to be equal to get factorial save call on itself
to get factorial save call on itself
to get factorial save call on itself from inside of itself and here I’m going
from inside of itself and here I’m going
from inside of itself and here I’m going to get a number minus one times number
to get a number minus one times number
to get a number minus one times number this is going to get our factorial
this is going to get our factorial
this is going to get our factorial because here we’re then going to return
because here we’re then going to return
because here we’re then going to return sum so very quick way to get the
sum so very quick way to get the
sum so very quick way to get the factorial of a number and basically what
factorial of a number and basically what
factorial of a number and basically what is going on here is right here we’ll
is going on here is right here we’ll
is going on here is right here we’ll come down to this part this is the first
come down to this part this is the first
come down to this part this is the first time through this function and let’s say
time through this function and let’s say
time through this function and let’s say number is equal to three well in that
number is equal to three well in that
number is equal to three well in that situation get factorial is called with
situation get factorial is called with
situation get factorial is called with the value of three would actually be two
the value of three would actually be two
the value of three would actually be two let’s just focus in on this one right
let’s just focus in on this one right
let’s just focus in on this one right here so three minus one is equal to two
here so three minus one is equal to two
here so three minus one is equal to two in that situation it’s going to return a
in that situation it’s going to return a
in that situation it’s going to return a value of two and then we’re going to
value of two and then we’re going to
value of two and then we’re going to multiply that times three so right here
multiply that times three so right here
multiply that times three so right here whenever we’re going through your the
whenever we’re going through your the
whenever we’re going through your the second time this time we’re going to be
second time this time we’re going to be
second time this time we’re going to be passing two into the get factorial so
passing two into the get factorial so
passing two into the get factorial so there we are and two minus one is going
there we are and two minus one is going
there we are and two minus one is going to be equal to one and in this situation
to be equal to one and in this situation
to be equal to one and in this situation this is going to return the value of one
this is going to return the value of one
this is going to return the value of one and get factorial in this situation
and get factorial in this situation
and get factorial in this situation whenever it comes in here the third time
whenever it comes in here the third time
whenever it comes in here the third time number is going to be equal to one so
number is going to be equal to one so
number is going to be equal to one so sum is going to be equal to one and
sum is going to be equal to one and
sum is going to be equal to one and that’s going to end that functions
that’s going to end that functions
that’s going to end that functions execution and then soon as sort of
execution and then soon as sort of
execution and then soon as sort of ricochet back up to the beginning so
ricochet back up to the beginning so
ricochet back up to the beginning so what we’re going to be left with in this
what we’re going to be left with in this
what we’re going to be left with in this situation is this is going to return one
situation is this is going to return one
situation is this is going to return one which is going to be multiplied times
which is going to be multiplied times
which is going to be multiplied times two that to right here actually goes
two that to right here actually goes
two that to right here actually goes right here and then we’ll multiply that
right here and then we’ll multiply that
right here and then we’ll multiply that 2 times three which is going to give us
2 times three which is going to give us
2 times three which is going to give us our final value of six and let’s go
our final value of six and let’s go
our final value of six and let’s go through here and let’s actually run it
through here and let’s actually run it
through here and let’s actually run it to make sure that that’s what it does
to make sure that that’s what it does
to make sure that that’s what it does and how to find out is to go factorial
and how to find out is to go factorial
and how to find out is to go factorial of 3 is and then call the phone
of 3 is and then call the phone
of 3 is and then call the phone get factorial passing the value of three
get factorial passing the value of three
get factorial passing the value of three and I’ll make sure I come up here and
and I’ll make sure I come up here and
and I’ll make sure I come up here and have the return value be an integer
have the return value be an integer
have the return value be an integer right there and then also come in here
right there and then also come in here
right there and then also come in here and remove this little parenthesis I put
and remove this little parenthesis I put
and remove this little parenthesis I put in there by accident if we execute it
in there by accident if we execute it
in there by accident if we execute it you can see factorial three is six
you can see factorial three is six
you can see factorial three is six exactly like we demonstrated up here
exactly like we demonstrated up here
exactly like we demonstrated up here there’s a rundown of functions inside of
there’s a rundown of functions inside of
there’s a rundown of functions inside of C++ now I want to cover file i/o or how
C++ now I want to cover file i/o or how
C++ now I want to cover file i/o or how to read and write files using either
to read and write files using either
to read and write files using either text or machine readable binary so I’m
text or machine readable binary so I’m
text or machine readable binary so I’m going to create a string here I’m going
going to create a string here I’m going
going to create a string here I’m going to call this Steve quote it’s equal to
to call this Steve quote it’s equal to
to call this Steve quote it’s equal to and say a day without sunshine is like
and say a day without sunshine is like
and say a day without sunshine is like you know night now what I’m gonna have
you know night now what I’m gonna have
you know night now what I’m gonna have to do is create an output file stream to
to do is create an output file stream to
to do is create an output file stream to create this file if it doesn’t exist or
create this file if it doesn’t exist or
create this file if it doesn’t exist or what it will do is create a function or
what it will do is create a function or
what it will do is create a function or create a file if it doesn’t exist I’m
create a file if it doesn’t exist I’m
create a file if it doesn’t exist I’m going to call it writer and I’m going to
going to call it writer and I’m going to
going to call it writer and I’m going to define the name that I want to save this
define the name that I want to save this
define the name that I want to save this text into and I’m going to call it Steve
text into and I’m going to call it Steve
text into and I’m going to call it Steve quote dot txt and then going to verify
quote dot txt and then going to verify
quote dot txt and then going to verify that the file stream was created so that
that the file stream was created so that
that the file stream was created so that I’ll be able to write to the file if not
I’ll be able to write to the file if not
I’ll be able to write to the file if not I’m going to put out an error message
I’m going to put out an error message
I’m going to put out an error message and then if we want to signal that an
and then if we want to signal that an
and then if we want to signal that an error has occurred we can return a
error has occurred we can return a
error has occurred we can return a negative one in this situation else if
negative one in this situation else if
negative one in this situation else if the file stream is open that means we
the file stream is open that means we
the file stream is open that means we can write to the file and it’s very
can write to the file and it’s very
can write to the file and it’s very simple to write text to the file just go
simple to write text to the file just go
simple to write text to the file just go writer and the string you want to write
writer and the string you want to write
writer and the string you want to write and then I’ll throw a new line on there
and then I’ll throw a new line on there
and then I’ll throw a new line on there at the end and then very importantly you
at the end and then very importantly you
at the end and then very importantly you also want to come in and close that file
also want to come in and close that file
also want to come in and close that file stream at the end I’m going to continue
stream at the end I’m going to continue
stream at the end I’m going to continue going here because we’ve got to read
going here because we’ve got to read
going here because we’ve got to read from it let’s say that you also wanted
from it let’s say that you also wanted
from it let’s say that you also wanted to come in here our file stream is
to come in here our file stream is
to come in here our file stream is closed we’re going to create another one
closed we’re going to create another one
closed we’re going to create another one and I’ll just call this writer too and
and I’ll just call this writer too and
and I’ll just call this writer too and then in this situation what we’re going
then in this situation what we’re going
then in this situation what we’re going to do is we’re going to define that we
to do is we’re going to define that we
to do is we’re going to define that we want to write to the Steve quote text
want to write to the Steve quote text
want to write to the Steve quote text file and then here we’re going to say
file and then here we’re going to say
file and then here we’re going to say that we want to append what we’re going
that we want to append what we’re going
that we want to append what we’re going to do next to the end of what’s already
to do next to the end of what’s already
to do next to the end of what’s already there now there’s a whole bunch of
there now there’s a whole bunch of
there now there’s a whole bunch of different symbols we can use use here to
different symbols we can use use here to
different symbols we can use use here to do different things with files like I
do different things with files like I
do different things with files like I just said with iOS app we’re going to be
just said with iOS app we’re going to be
just said with iOS app we’re going to be able to append to the end of the file
able to append to the end of the file
able to append to the end of the file with iOS binary we’re going to be able
with iOS binary we’re going to be able
with iOS binary we’re going to be able to treat the file as if it’s binary iOS
to treat the file as if it’s binary iOS
to treat the file as if it’s binary iOS in is going to open a file to read input
in is going to open a file to read input
in is going to open a file to read input what you’re going to see here a minute
what you’re going to see here a minute
what you’re going to see here a minute iOS trunk is the default what happens
iOS trunk is the default what happens
iOS trunk is the default what happens whenever you don’t use one of these
whenever you don’t use one of these
whenever you don’t use one of these symbols and then iOS out is going to
symbols and then iOS out is going to
symbols and then iOS out is going to open
open
open off to write output but in this
off to write output but in this
off to write output but in this situation we’re going to be a pending
situation we’re going to be a pending
situation we’re going to be a pending and once again we’re going to need to
and once again we’re going to need to
and once again we’re going to need to come in here and check that this file
come in here and check that this file
come in here and check that this file stream is already open and I’m just
stream is already open and I’m just
stream is already open and I’m just going to copy this paste that in there
going to copy this paste that in there
going to copy this paste that in there but make sure this is right or up here
but make sure this is right or up here
but make sure this is right or up here instead of right there you go and this
instead of right there you go and this
instead of right there you go and this is going to be writer 2 we’re going to
is going to be writer 2 we’re going to
is going to be writer 2 we’re going to spit out an error again if the file
spit out an error again if the file
spit out an error again if the file stream was not opened and then to append
stream was not opened and then to append
stream was not opened and then to append in this situation we’re going to go
in this situation we’re going to go
in this situation we’re going to go writer and then let’s say that we want
writer and then let’s say that we want
writer and then let’s say that we want to put on a new line backslash N and
to put on a new line backslash N and
to put on a new line backslash N and then a dash and then type in Steve
then a dash and then type in Steve
then a dash and then type in Steve Martin we then could come in and say
Martin we then could come in and say
Martin we then could come in and say write or close and there that is alright
write or close and there that is alright
write or close and there that is alright so we wrote and we appended and we
so we wrote and we appended and we
so we wrote and we appended and we created the file and did all that now
created the file and did all that now
created the file and did all that now I’m going to create a character that’s
I’m going to create a character that’s
I’m going to create a character that’s going to hold each of the individual
going to hold each of the individual
going to hold each of the individual characters we’re going to read from our
characters we’re going to read from our
characters we’re going to read from our file and we’re going to read these
file and we’re going to read these
file and we’re going to read these characters using an input file stream so
characters using an input file stream so
characters using an input file stream so input file stream and I’m going to call
input file stream and I’m going to call
input file stream and I’m going to call this reader and you need to tell it
this reader and you need to tell it
this reader and you need to tell it exactly what file you’re going to be
exactly what file you’re going to be
exactly what file you’re going to be reading from and then I’m going to check
reading from and then I’m going to check
reading from and then I’m going to check if that stream is going to be open just
if that stream is going to be open just
if that stream is going to be open just like we did before with the reader
like we did before with the reader
like we did before with the reader inside of there come in here and print
inside of there come in here and print
inside of there come in here and print error again turn Erica negative one else
error again turn Erica negative one else
error again turn Erica negative one else we know that we got our stream open and
we know that we got our stream open and
we know that we got our stream open and we’ll be able to read from that file and
we’ll be able to read from that file and
we’ll be able to read from that file and we’re going to use a for loop in this
we’re going to use a for loop in this
we’re going to use a for loop in this situation to read each character from
situation to read each character from
situation to read each character from the stream until we get to the end of
the stream until we get to the end of
the stream until we get to the end of the line so I’m going to go in I is
the line so I’m going to go in I is
the line so I’m going to go in I is equal to zero then I’m going to go while
equal to zero then I’m going to go while
equal to zero then I’m going to go while the reader does not get to the end of
the reader does not get to the end of
the reader does not get to the end of the file we’re going to continue reading
the file we’re going to continue reading
the file we’re going to continue reading characters and then we’ll call reader
characters and then we’ll call reader
characters and then we’ll call reader get to get the next letter of output
get to get the next letter of output
get to get the next letter of output that we want and then in this situation
that we want and then in this situation
that we want and then in this situation let’s just say that we want to print
let’s just say that we want to print
let’s just say that we want to print that out to the screen type in letter
that out to the screen type in letter
that out to the screen type in letter then after the for loops all done with
then after the for loops all done with
then after the for loops all done with you go see out until and then once again
you go see out until and then once again
you go see out until and then once again close the reader if we did that all
close the reader if we did that all
close the reader if we did that all right day without sunshine is like you
right day without sunshine is like you
right day without sunshine is like you know night so you can see it worked out
know night so you can see it worked out
know night so you can see it worked out and those are all the different things
and those are all the different things
and those are all the different things you can do and in regards to reading and
you can do and in regards to reading and
you can do and in regards to reading and writing data using C++ I’m going to
writing data using C++ I’m going to
writing data using C++ I’m going to briefly touch on exception handling and
briefly touch on exception handling and
briefly touch on exception handling and exception handling basically allows you
exception handling basically allows you
exception handling basically allows you to avoid potential problems in this
to avoid potential problems in this
to avoid potential problems in this situation I’m just going to focus on one
situation I’m just going to focus on one
situation I’m just going to focus on one which is a division by zero error that
which is a division by zero error that
which is a division by zero error that could cause all kinds problem now
could cause all kinds problem now
could cause all kinds problem now whenever you want to cover something
whenever you want to cover something
whenever you want to cover something that could cause an exception or an
that could cause an exception or an
that could cause an exception or an error that you want to be able to catch
error that you want to be able to catch
error that you want to be able to catch you’re going to surround the code that
you’re going to surround the code that
you’re going to surround the code that could potentially cause that air inside
could potentially cause that air inside
could potentially cause that air inside of what’s called a try block and then
of what’s called a try block and then
of what’s called a try block and then what we’re
what we’re
what we’re to do is going to set an if statement
to do is going to set an if statement
to do is going to set an if statement inside here that says if the number is
inside here that says if the number is
inside here that says if the number is not equal to zero well in that situation
not equal to zero well in that situation
not equal to zero well in that situation we can say C out and divide by number
we can say C out and divide by number
we can say C out and divide by number like we have there but as we can see
like we have there but as we can see
like we have there but as we can see that is going to cause an error and
that is going to cause an error and
that is going to cause an error and we’re never going to get there
we’re never going to get there
we’re never going to get there else we’re going to say throw number now
else we’re going to say throw number now
else we’re going to say throw number now this throw is going to look for a catch
this throw is going to look for a catch
this throw is going to look for a catch and the catch area is where we are going
and the catch area is where we are going
and the catch area is where we are going to catch the number that was entered
to catch the number that was entered
to catch the number that was entered don’t have to do this but it helps so
don’t have to do this but it helps so
don’t have to do this but it helps so that we have the error message makes
that we have the error message makes
that we have the error message makes sense and then we could do something
sense and then we could do something
sense and then we could do something like number is not valid and then maybe
like number is not valid and then maybe
like number is not valid and then maybe have the mask or ask them for it again
have the mask or ask them for it again
have the mask or ask them for it again you can see here if we run zero is not
you can see here if we run zero is not
you can see here if we run zero is not valid so instead of causing an error
valid so instead of causing an error
valid so instead of causing an error right here by putting this inside of a
right here by putting this inside of a
right here by putting this inside of a try block and then throwing if they
try block and then throwing if they
try block and then throwing if they would actually enter a 0 which causes
would actually enter a 0 which causes
would actually enter a 0 which causes potential errors we’re instead going to
potential errors we’re instead going to
potential errors we’re instead going to catch it down in this area right here
catch it down in this area right here
catch it down in this area right here and solve it and keep our program from
and solve it and keep our program from
and solve it and keep our program from crashing so that’s a brief explanation
crashing so that’s a brief explanation
crashing so that’s a brief explanation of exceptions ok now let’s talk about
of exceptions ok now let’s talk about
of exceptions ok now let’s talk about pointers now when data is stored it is
pointers now when data is stored it is
pointers now when data is stored it is stored in an appropriately sized box
stored in an appropriately sized box
stored in an appropriately sized box that is based off of its data type just
that is based off of its data type just
that is based off of its data type just like we covered previously here we have
like we covered previously here we have
like we covered previously here we have an integer and here we have a character
an integer and here we have a character
an integer and here we have a character now like we did before we’re going to be
now like we did before we’re going to be
now like we did before we’re going to be able to come in here and use sizeof to
able to come in here and use sizeof to
able to come in here and use sizeof to determine how many bytes that data is
determine how many bytes that data is
determine how many bytes that data is going to take up and we can see here
going to take up and we can see here
going to take up and we can see here whenever we run the program that the
whenever we run the program that the
whenever we run the program that the integer is going to take up 4 bytes and
integer is going to take up 4 bytes and
integer is going to take up 4 bytes and the character is going to take up 1 byte
the character is going to take up 1 byte
the character is going to take up 1 byte now you’re going to be able to reference
now you’re going to be able to reference
now you’re going to be able to reference this box or this memory address where
this box or this memory address where
this box or this memory address where all of your data is stored with what is
all of your data is stored with what is
all of your data is stored with what is called the reference operator which is
called the reference operator which is
called the reference operator which is an M purse and so we could come in here
an M purse and so we could come in here
an M purse and so we could come in here and go see out and my age is located at
and go see out and my age is located at
and go see out and my age is located at and then use the reference operator
and then use the reference operator
and then use the reference operator followed by my age and when we execute
followed by my age and when we execute
followed by my age and when we execute that you can see the memory address
that you can see the memory address
that you can see the memory address right here now what’s really cool about
right here now what’s really cool about
right here now what’s really cool about this is whenever we don’t use pointers
this is whenever we don’t use pointers
this is whenever we don’t use pointers or we don’t use reference operators and
or we don’t use reference operators and
or we don’t use reference operators and we change a value of a variable in a
we change a value of a variable in a
we change a value of a variable in a regular old function that change of
regular old function that change of
regular old function that change of value does not carry on it is lost and
value does not carry on it is lost and
value does not carry on it is lost and the reason why is whenever we use
the reason why is whenever we use
the reason why is whenever we use regular functions what we are in essence
regular functions what we are in essence
regular functions what we are in essence doing is passing a value into that
doing is passing a value into that
doing is passing a value into that function so even if we had the same and
function so even if we had the same and
function so even if we had the same and these and we passed in some as a
these and we passed in some as a
these and we passed in some as a variable into a function called add
variable into a function called add
variable into a function called add these just like this what’s going to
these just like this what’s going to
these just like this what’s going to happen is the value of sums so let’s say
happen is the value of sums so let’s say
happen is the value of sums so let’s say we have an integer here integer sum is
we have an integer here integer sum is
we have an integer here integer sum is equal to 5 and we pass some into the add
equal to 5 and we pass some into the add
equal to 5 and we pass some into the add these function well if we change the
these function well if we change the
these function well if we change the value of sum and we do not pass it back
value of sum and we do not pass it back
value of sum and we do not pass it back sum is still going to be equal to 5
sum is still going to be equal to 5
sum is still going to be equal to 5 because we are passing a value with
because we are passing a value with
because we are passing a value with reference operator and with pointers in
reference operator and with pointers in
reference operator and with pointers in general what we’re going to be able to
general what we’re going to be able to
general what we’re going to be able to do instead is pass by reference and any
do instead is pass by reference and any
do instead is pass by reference and any change that is made inside of there is
change that is made inside of there is
change that is made inside of there is going to show now a pointer is going to
going to show now a pointer is going to
going to show now a pointer is going to be able to store a memory address to
be able to store a memory address to
be able to store a memory address to recreate my age to demonstrate this and
recreate my age to demonstrate this and
recreate my age to demonstrate this and whenever you’re defining a pointer you
whenever you’re defining a pointer you
whenever you’re defining a pointer you just have to use the same data type
just have to use the same data type
just have to use the same data type followed by a star and we’ll say age
followed by a star and we’ll say age
followed by a star and we’ll say age pointer like this is equal to and then
pointer like this is equal to and then
pointer like this is equal to and then you’re going to use the reference
you’re going to use the reference
you’re going to use the reference operator to pass that over just like
operator to pass that over just like
operator to pass that over just like before we’re going to be able to access
before we’re going to be able to access
before we’re going to be able to access the memory address with this pointer of
the memory address with this pointer of
the memory address with this pointer of pointer by just typing in age PTR but
pointer by just typing in age PTR but
pointer by just typing in age PTR but we’ll also be able to dereference to get
we’ll also be able to dereference to get
we’ll also be able to dereference to get the data at that memory address so we’ll
the data at that memory address so we’ll
the data at that memory address so we’ll say data at memory address and how you
say data at memory address and how you
say data at memory address and how you dereference is to put star in front of
dereference is to put star in front of
dereference is to put star in front of age pointer right like that you’ll see
age pointer right like that you’ll see
age pointer right like that you’ll see here with this pointer will now be able
here with this pointer will now be able
here with this pointer will now be able to get the memory address as well as the
to get the memory address as well as the
to get the memory address as well as the data that is stored at that memory
data that is stored at that memory
data that is stored at that memory address let’s take a look at arrays as
address let’s take a look at arrays as
address let’s take a look at arrays as well let’s say we have our bad numbers
well let’s say we have our bad numbers
well let’s say we have our bad numbers array just like we used previously we
array just like we used previously we
array just like we used previously we can then go int star to create a pointer
can then go int star to create a pointer
can then go int star to create a pointer and we’ll call this number array pointer
and we’ll call this number array pointer
and we’ll call this number array pointer is equal to bad nums
is equal to bad nums
is equal to bad nums what’s neat here is we’re going to
what’s neat here is we’re going to
what’s neat here is we’re going to actually be able to increment through
actually be able to increment through
actually be able to increment through our array just using shorthand notation
our array just using shorthand notation
our array just using shorthand notation like plus plus and minus minus so we can
like plus plus and minus minus so we can
like plus plus and minus minus so we can go see out address number array pointer
go see out address number array pointer
go see out address number array pointer and value and then to get the actual
and value and then to get the actual
and value and then to get the actual value in the array we can go numb array
value in the array we can go numb array
value in the array we can go numb array pointer and then close that off and then
pointer and then close that off and then
pointer and then close that off and then come in and go numb array pointer plus
come in and go numb array pointer plus
come in and go numb array pointer plus plus to get the next value in our array
plus to get the next value in our array
plus to get the next value in our array bounce that in there and there you can
bounce that in there and there you can
bounce that in there and there you can see jumped in there grabbed 4 and 13 as
see jumped in there grabbed 4 and 13 as
see jumped in there grabbed 4 and 13 as well as the memory addresses and as we
well as the memory addresses and as we
well as the memory addresses and as we saw previously an integer takes up 4
saw previously an integer takes up 4
saw previously an integer takes up 4 bytes you can see the difference
bytes you can see the difference
bytes you can see the difference the memory addresses right there so
the memory addresses right there so
the memory addresses right there so you’re learning about how this stuff is
you’re learning about how this stuff is
you’re learning about how this stuff is stored inside of here and something else
stored inside of here and something else
stored inside of here and something else that is interesting is an array name is
that is interesting is an array name is
that is interesting is an array name is just a pointer to the array so we could
just a pointer to the array so we could
just a pointer to the array so we could come in and go address and put the array
come in and go address and put the array
come in and go address and put the array name by itself inside of there at gnomes
name by itself inside of there at gnomes
name by itself inside of there at gnomes to get the value that’s stored there and
to get the value that’s stored there and
to get the value that’s stored there and you can see that it works also see same
you can see that it works also see same
you can see that it works also see same memory address same value so something
memory address same value so something
memory address same value so something interesting think about like I said
interesting think about like I said
interesting think about like I said previously whenever we pass a variable
previously whenever we pass a variable
previously whenever we pass a variable to function you’re passing by value
to function you’re passing by value
to function you’re passing by value however whenever you pass a pointer to a
however whenever you pass a pointer to a
however whenever you pass a pointer to a function you are actually passing a
function you are actually passing a
function you are actually passing a reference that can be changed so let’s
reference that can be changed so let’s
reference that can be changed so let’s jump up here and let’s create a function
jump up here and let’s create a function
jump up here and let’s create a function to demonstrate exactly how this works
to demonstrate exactly how this works
to demonstrate exactly how this works this isn’t going to return anything so
this isn’t going to return anything so
this isn’t going to return anything so I’m going to pull it up void inside of
I’m going to pull it up void inside of
I’m going to pull it up void inside of there and I’m going to say make me young
there and I’m going to say make me young
there and I’m going to say make me young and this is going to receive a pointer
and this is going to receive a pointer
and this is going to receive a pointer so I’m going to put int with a star
so I’m going to put int with a star
so I’m going to put int with a star after it and then age like that and then
after it and then age like that and then
after it and then age like that and then let’s pull up out here on the screen the
let’s pull up out here on the screen the
let’s pull up out here on the screen the previous age I used to be like that and
previous age I used to be like that and
previous age I used to be like that and to get the value of age I put a star and
to get the value of age I put a star and
to get the value of age I put a star and age because otherwise it’s memory
age because otherwise it’s memory
age because otherwise it’s memory address have to put that store in there
address have to put that store in there
address have to put that store in there but then I can also go in and change
but then I can also go in and change
but then I can also go in and change that value by putting star and age is
that value by putting star and age is
that value by putting star and age is equal to 21 don’t return anything don’t
equal to 21 don’t return anything don’t
equal to 21 don’t return anything don’t have to do anything otherwise then I can
have to do anything otherwise then I can
have to do anything otherwise then I can come down here and call make me young if
come down here and call make me young if
come down here and call make me young if I want to pass a reference to that guy
I want to pass a reference to that guy
I want to pass a reference to that guy passing by reference that’s all that
passing by reference that’s all that
passing by reference that’s all that means I can do that and then I could put
means I can do that and then I could put
means I can do that and then I could put I’m and then just a check or verify that
I’m and then just a check or verify that
I’m and then just a check or verify that it actually changed that age you can do
it actually changed that age you can do
it actually changed that age you can do this and you can see I used to be 39
this and you can see I used to be 39
this and you can see I used to be 39 that came from the function then we
that came from the function then we
that came from the function then we changed it to 21 inside of the function
changed it to 21 inside of the function
changed it to 21 inside of the function and then you can see here that it
and then you can see here that it
and then you can see here that it changed globally can also come in here
changed globally can also come in here
changed globally can also come in here and once again this ampersand is going
and once again this ampersand is going
and once again this ampersand is going to denote that age reference will be a
to denote that age reference will be a
to denote that age reference will be a reference to the assigned variable so
reference to the assigned variable so
reference to the assigned variable so there’s reference difference between a
there’s reference difference between a
there’s reference difference between a reference and a pointer which I’m going
reference and a pointer which I’m going
reference and a pointer which I’m going to get more into when you should use one
to get more into when you should use one
to get more into when you should use one when you should use another one I’m
when you should use another one I’m
when you should use another one I’m going to be able to go see out you’re
going to be able to go see out you’re
going to be able to go see out you’re actually going to use references more
actually going to use references more
actually going to use references more than you use pointers like I said that’s
than you use pointers like I said that’s
than you use pointers like I said that’s coming in a second another thing that’s
coming in a second another thing that’s
coming in a second another thing that’s interesting is we could take this
interesting is we could take this
interesting is we could take this reference and increment it and see that
reference and increment it and see that
reference and increment it and see that that also changed my
that also changed my
that also changed my right like this you can see here’s my
right like this you can see here’s my
right like this you can see here’s my age 21 here’s my age of 22 again
age 21 here’s my age of 22 again
age 21 here’s my age of 22 again globally we’re changing all those then
globally we’re changing all those then
globally we’re changing all those then let’s create another function this one’s
let’s create another function this one’s
let’s create another function this one’s going to be called act your age just to
going to be called act your age just to
going to be called act your age just to pass the reference and show the
pass the reference and show the
pass the reference and show the difference between passing that
difference between passing that
difference between passing that reference and dealing with pointers come
reference and dealing with pointers come
reference and dealing with pointers come up here and create another function it’s
up here and create another function it’s
up here and create another function it’s also not going to return anything just
also not going to return anything just
also not going to return anything just to prove that nothing’s exchanging hands
to prove that nothing’s exchanging hands
to prove that nothing’s exchanging hands act your age except we’re passing a
act your age except we’re passing a
act your age except we’re passing a reference this time so we’re going to
reference this time so we’re going to
reference this time so we’re going to put the ampersand inside of there and
put the ampersand inside of there and
put the ampersand inside of there and I’m just going to put age there again
I’m just going to put age there again
I’m just going to put age there again doesn’t matter what I put and here I’m
doesn’t matter what I put and here I’m
doesn’t matter what I put and here I’m just going to say age is equal to 39
just going to say age is equal to 39
just going to say age is equal to 39 back down here again just demonstrating
back down here again just demonstrating
back down here again just demonstrating a difference between passing by
a difference between passing by
a difference between passing by reference and passing by pointer and we
reference and passing by pointer and we
reference and passing by pointer and we could go ahead and prove that it’s still
could go ahead and prove that it’s still
could go ahead and prove that it’s still change age is equal to ndele and there
change age is equal to ndele and there
change age is equal to ndele and there you can see it did indeed change so
you can see it did indeed change so
you can see it did indeed change so basically you might ask yourself well
basically you might ask yourself well
basically you might ask yourself well whenever you’re deciding whether you
whenever you’re deciding whether you
whenever you’re deciding whether you want to use pointers or references when
want to use pointers or references when
want to use pointers or references when should you use which well basically you
should you use which well basically you
should you use which well basically you should use pointers if you don’t want to
should use pointers if you don’t want to
should use pointers if you don’t want to have to initialize at declaration what
have to initialize at declaration what
have to initialize at declaration what that means is you can see right here I
that means is you can see right here I
that means is you can see right here I am defining we’re initializing what I’m
am defining we’re initializing what I’m
am defining we’re initializing what I’m referencing whenever I am using the
referencing whenever I am using the
referencing whenever I am using the reference option whenever I am dealing
reference option whenever I am dealing
reference option whenever I am dealing with pointers I do not need to
with pointers I do not need to
with pointers I do not need to immediately initialize and then on top
immediately initialize and then on top
immediately initialize and then on top of that with a pointer I’m going to be
of that with a pointer I’m going to be
of that with a pointer I’m going to be able to assign another variable to it so
able to assign another variable to it so
able to assign another variable to it so a pointer is going to be able to deal
a pointer is going to be able to deal
a pointer is going to be able to deal with more than one while a reference is
with more than one while a reference is
with more than one while a reference is going to get this one reference to this
going to get this one reference to this
going to get this one reference to this one variable and be stuck with it so if
one variable and be stuck with it so if
one variable and be stuck with it so if you don’t need to be able to change
you don’t need to be able to change
you don’t need to be able to change whatever you’re going to be pointing at
whatever you’re going to be pointing at
whatever you’re going to be pointing at use a reference that’s pretty much the
use a reference that’s pretty much the
use a reference that’s pretty much the ironclad rule so and that’s the basis of
ironclad rule so and that’s the basis of
ironclad rule so and that’s the basis of pointers we’re going to get more into
pointers we’re going to get more into
pointers we’re going to get more into them here in a second but now I’m going
them here in a second but now I’m going
them here in a second but now I’m going to jump over and talk about classes now
to jump over and talk about classes now
to jump over and talk about classes now now in object-oriented programming what
now in object-oriented programming what
now in object-oriented programming what we’re trying to do is model real world
we’re trying to do is model real world
we’re trying to do is model real world objects like an animal in code and how
objects like an animal in code and how
objects like an animal in code and how you do that is you think about well what
you do that is you think about well what
you do that is you think about well what makes a specific object an object well
makes a specific object an object well
makes a specific object an object well each object has attributes such as
each object has attributes such as
each object has attributes such as height and weight and whatever and it
height and weight and whatever and it
height and weight and whatever and it also has capabilities so it can run and
also has capabilities so it can run and
also has capabilities so it can run and it can eat just to be really simple
it can eat just to be really simple
it can eat just to be really simple there well these attributes are going to
there well these attributes are going to
there well these attributes are going to be modeled in the variables and these
be modeled in the variables and these
be modeled in the variables and these capabilities are going to be modeled in
capabilities are going to be modeled in
capabilities are going to be modeled in the functions or
the functions or
the functions or the methods same thing just a different
the methods same thing just a different
the methods same thing just a different name so what I’m going to do here inside
name so what I’m going to do here inside
name so what I’m going to do here inside of my class is I’m going to have some of
of my class is I’m going to have some of
of my class is I’m going to have some of these things be private and by private
these things be private and by private
these things be private and by private what I’m saying is that anything that is
what I’m saying is that anything that is
what I’m saying is that anything that is marked private in regards to attributes
marked private in regards to attributes
marked private in regards to attributes or variables is only going to be able to
or variables is only going to be able to
or variables is only going to be able to be changed by functions inside of my
be changed by functions inside of my
be changed by functions inside of my class and we do that just to keep them
class and we do that just to keep them
class and we do that just to keep them protected and this is called
protected and this is called
protected and this is called encapsulation so I’m going to have my
encapsulation so I’m going to have my
encapsulation so I’m going to have my name height and weight all be private
name height and weight all be private
name height and weight all be private and while I’m in here I might as well
and while I’m in here I might as well
and while I’m in here I might as well talk about static variables basically if
talk about static variables basically if
talk about static variables basically if you put static in front of something all
you put static in front of something all
you put static in front of something all that means is that this variables value
that means is that this variables value
that means is that this variables value is going to be shared by every object of
is going to be shared by every object of
is going to be shared by every object of type animal that is ever created so
type animal that is ever created so
type animal that is ever created so let’s say that I want to also keep track
let’s say that I want to also keep track
let’s say that I want to also keep track of the number of animals that are
of the number of animals that are
of the number of animals that are created from my class well it wouldn’t
created from my class well it wouldn’t
created from my class well it wouldn’t make sense that an animal would count
make sense that an animal would count
make sense that an animal would count that’s another reason why we have static
that’s another reason why we have static
that’s another reason why we have static here because static variables also
here because static variables also
here because static variables also normally are attributes that the class
normally are attributes that the class
normally are attributes that the class object would not have so we want to be
object would not have so we want to be
object would not have so we want to be able to count the number of animals that
able to count the number of animals that
able to count the number of animals that are created but we do not want to
are created but we do not want to
are created but we do not want to actually have the animal type defined to
actually have the animal type defined to
actually have the animal type defined to be able to do it and that brings us to
be able to do it and that brings us to
be able to do it and that brings us to public well if we have variables that
public well if we have variables that
public well if we have variables that are private we’re going to have to have
are private we’re going to have to have
are private we’re going to have to have public methods that are going to be able
public methods that are going to be able
public methods that are going to be able to access the values inside of there so
to access the values inside of there so
to access the values inside of there so we’re going to have something like get
we’re going to have something like get
we’re going to have something like get height there we go and I’m actually
height there we go and I’m actually
height there we go and I’m actually going to just create this here on one
going to just create this here on one
going to just create this here on one line and whenever this is called it is
line and whenever this is called it is
line and whenever this is called it is going to return the value that is stored
going to return the value that is stored
going to return the value that is stored for my animal object to whoever calls
for my animal object to whoever calls
for my animal object to whoever calls for it and we can also do the same thing
for it and we can also do the same thing
for it and we can also do the same thing with weight and this is also
with weight and this is also
with weight and this is also encapsulation we’re keeping all of our
encapsulation we’re keeping all of our
encapsulation we’re keeping all of our data protected and this is going to
data protected and this is going to
data protected and this is going to return a string
return a string
return a string whenever the get name function is called
whenever the get name function is called
whenever the get name function is called and we can just go return and name and
and we can just go return and name and
and we can just go return and name and there we go but what we really want to
there we go but what we really want to
there we go but what we really want to do whenever we’re dealing with
do whenever we’re dealing with
do whenever we’re dealing with encapsulation is protect the values that
encapsulation is protect the values that
encapsulation is protect the values that are going to be stored so they might
are going to be stored so they might
are going to be stored so they might want to come in here and set the height
want to come in here and set the height
want to come in here and set the height and let’s say that we decide that we
and let’s say that we decide that we
and let’s say that we decide that we only want them to be able to enter a
only want them to be able to enter a
only want them to be able to enter a reasonable height we could provide a
reasonable height we could provide a
reasonable height we could provide a check inside here to verify that the
check inside here to verify that the
check inside here to verify that the animal height makes sense and otherwise
animal height makes sense and otherwise
animal height makes sense and otherwise discard it but in this situation I’ll
discard it but in this situation I’ll
discard it but in this situation I’ll just
just
just that’s nice and simple also going to do
that’s nice and simple also going to do
that’s nice and simple also going to do the exactly the same thing here for the
the exactly the same thing here for the
the exactly the same thing here for the weight so weight and let’s have this
weight so weight and let’s have this
weight so weight and let’s have this video kilograms weight kilograms and of
video kilograms weight kilograms and of
video kilograms weight kilograms and of course it doesn’t matter if you put
course it doesn’t matter if you put
course it doesn’t matter if you put centimeters or kilograms or what you put
centimeters or kilograms or what you put
centimeters or kilograms or what you put inside of there and setname say animal
inside of there and setname say animal
inside of there and setname say animal name right now we have to have this be
name right now we have to have this be
name right now we have to have this be different from this but I’m going to
different from this but I’m going to
different from this but I’m going to show you how to change that here in a
show you how to change that here in a
show you how to change that here in a second animal name right there
second animal name right there
second animal name right there everything else looks perfectly fine and
everything else looks perfectly fine and
everything else looks perfectly fine and then we could also create another
then we could also create another
then we could also create another function inside of here let’s call this
function inside of here let’s call this
function inside of here let’s call this at all and here we’re creating a
at all and here we’re creating a
at all and here we’re creating a prototype of a function that we are
prototype of a function that we are
prototype of a function that we are going to declare here in a second you’re
going to declare here in a second you’re
going to declare here in a second you’re going to see it and that’s how we
going to see it and that’s how we
going to see it and that’s how we declare a prototype another thing we
declare a prototype another thing we
declare a prototype another thing we would want to have is a constructor and
would want to have is a constructor and
would want to have is a constructor and what a constructor is first off its name
what a constructor is first off its name
what a constructor is first off its name is going to start with whatever the
is going to start with whatever the
is going to start with whatever the class’s name is and then here we’re
class’s name is and then here we’re
class’s name is and then here we’re going to create a prototype of that and
going to create a prototype of that and
going to create a prototype of that and this is going to be the function that is
this is going to be the function that is
this is going to be the function that is going to be called whenever an object is
going to be called whenever an object is
going to be called whenever an object is created and so it’ll pass in the height
created and so it’ll pass in the height
created and so it’ll pass in the height the weight and the name and the
the weight and the name and the
the weight and the name and the constructor is going to handle creating
constructor is going to handle creating
constructor is going to handle creating every object if we have a constructor we
every object if we have a constructor we
every object if we have a constructor we all show should have a destructor and it
all show should have a destructor and it
all show should have a destructor and it just has that little tilde sign there
just has that little tilde sign there
just has that little tilde sign there once again this is going to be a
once again this is going to be a
once again this is going to be a prototype where I’m going to build the
prototype where I’m going to build the
prototype where I’m going to build the door declare the actual one down below
door declare the actual one down below
door declare the actual one down below and then let’s say that we want to have
and then let’s say that we want to have
and then let’s say that we want to have another constructor that doesn’t receive
another constructor that doesn’t receive
another constructor that doesn’t receive anything and this is an example of
anything and this is an example of
anything and this is an example of overloading and to overload a function
overloading and to overload a function
overloading and to overload a function like I talked about previously the name
like I talked about previously the name
like I talked about previously the name can be the same but the attributes need
can be the same but the attributes need
can be the same but the attributes need to be different so here we have two intz
to be different so here we have two intz
to be different so here we have two intz and a string here we are getting past
and a string here we are getting past
and a string here we are getting past nothing
nothing
nothing there’s also protected members when
there’s also protected members when
there’s also protected members when basically whenever we’re dealing with
basically whenever we’re dealing with
basically whenever we’re dealing with protected what we’re saying is that
protected what we’re saying is that
protected what we’re saying is that anything marked as protect is going to
anything marked as protect is going to
anything marked as protect is going to be available to members of the same
be available to members of the same
be available to members of the same class as well as subclasses but nothing
class as well as subclasses but nothing
class as well as subclasses but nothing else and we could also come in here and
else and we could also come in here and
else and we could also come in here and define a static method and a static
define a static method and a static
define a static method and a static method is set aside because they are
method is set aside because they are
method is set aside because they are attached to the class and not to the
attached to the class and not to the
attached to the class and not to the object as you’re going to see I’m going
object as you’re going to see I’m going
object as you’re going to see I’m going to show you in a second how to actually
to show you in a second how to actually
to show you in a second how to actually call for a static method and in this
call for a static method and in this
call for a static method and in this situation static methods also can only
situation static methods also can only
situation static methods also can only access static member variables like this
access static member variables like this
access static member variables like this guy we have up here right there so we
guy we have up here right there so we
guy we have up here right there so we are going to have this method
are going to have this method
are going to have this method specifically be able to return the
specifically be able to return the
specifically be able to return the number of animals
number of animals
number of animals that are created here we go and this
that are created here we go and this
that are created here we go and this time we’re not going to do a prototype
time we’re not going to do a prototype
time we’re not going to do a prototype we’ll just have it actually do what it’s
we’ll just have it actually do what it’s
we’ll just have it actually do what it’s supposed to do there it is and also
supposed to do there it is and also
supposed to do there it is and also finally we’ll create a two string which
finally we’ll create a two string which
finally we’ll create a two string which is going to print out all the
is going to print out all the
is going to print out all the information we have on our animals okay
information we have on our animals okay
information we have on our animals okay so we went and we declared our class
so we went and we declared our class
so we went and we declared our class it’s after this little curly bracket
it’s after this little curly bracket
it’s after this little curly bracket we’re going to put a semicolon and now
we’re going to put a semicolon and now
we’re going to put a semicolon and now we’re going to declare everything so the
we’re going to declare everything so the
we’re going to declare everything so the very first thing we’re going to declare
very first thing we’re going to declare
very first thing we’re going to declare is our static number of animals and how
is our static number of animals and how
is our static number of animals and how we refer to static variables is put the
we refer to static variables is put the
we refer to static variables is put the class name followed by these two colons
class name followed by these two colons
class name followed by these two colons right here and then whatever the name of
right here and then whatever the name of
right here and then whatever the name of it is say it’s tied to the class it has
it is say it’s tied to the class it has
it is say it’s tied to the class it has absolutely nothing to do with the object
absolutely nothing to do with the object
absolutely nothing to do with the object itself we can then define the prototype
itself we can then define the prototype
itself we can then define the prototype method for set all so set all is right
method for set all so set all is right
method for set all so set all is right here we’re going to go and define it
here we’re going to go and define it
here we’re going to go and define it there that was just a prototype and
there that was just a prototype and
there that was just a prototype and we’re going to do that by putting a void
we’re going to do that by putting a void
we’re going to do that by putting a void animal and then set all like that and
animal and then set all like that and
animal and then set all like that and then we have to define exactly what’s
then we have to define exactly what’s
then we have to define exactly what’s being passed in here so we’re going to
being passed in here so we’re going to
being passed in here so we’re going to have two inch for the height and the
have two inch for the height and the
have two inch for the height and the weight as well as the string name this
weight as well as the string name this
weight as well as the string name this basically does what the constructor does
basically does what the constructor does
basically does what the constructor does but just wanted to show you something
but just wanted to show you something
but just wanted to show you something now if you want to refer to an object
now if you want to refer to an object
now if you want to refer to an object specific height and not just a generic
specific height and not just a generic
specific height and not just a generic type of height you put this inside of
type of height you put this inside of
type of height you put this inside of here and the reason we have to do that
here and the reason we have to do that
here and the reason we have to do that is whenever the class is created there
is whenever the class is created there
is whenever the class is created there are no animal objects created so if we
are no animal objects created so if we
are no animal objects created so if we want to refer to the animals you know
want to refer to the animals you know
want to refer to the animals you know the specific animal objects version or
the specific animal objects version or
the specific animal objects version or value for height we have to put this in
value for height we have to put this in
value for height we have to put this in front of it and there we go and now we
front of it and there we go and now we
front of it and there we go and now we can also do the same thing for weight
can also do the same thing for weight
can also do the same thing for weight and also name just change this to weight
and also name just change this to weight
and also name just change this to weight and change this to weight and we could
and change this to weight and we could
and change this to weight and we could have also come up here and used this
have also come up here and used this
have also come up here and used this here see how we had to use centimeters
here see how we had to use centimeters
here see how we had to use centimeters instead of having height or weight or
instead of having height or weight or
instead of having height or weight or whatever inside of there if we would
whatever inside of there if we would
whatever inside of there if we would have used this we would have been able
have used this we would have been able
have used this we would have been able to get around that just a way to refer
to get around that just a way to refer
to get around that just a way to refer so that the you know the code actually
so that the you know the code actually
so that the you know the code actually knows what you’re trying to code or what
knows what you’re trying to code or what
knows what you’re trying to code or what you’re trying to do you can also come in
you’re trying to do you can also come in
you’re trying to do you can also come in here and change that static variable
here and change that static variable
here and change that static variable remember we are creating or changing the
remember we are creating or changing the
remember we are creating or changing the values here and then once again we’re
values here and then once again we’re
values here and then once again we’re basically going to do this with the
basically going to do this with the
basically going to do this with the constructor as well and remember the
constructor as well and remember the
constructor as well and remember the constructor is called every single time
constructor is called every single time
constructor is called every single time an animal object is created so there we
an animal object is created so there we
an animal object is created so there we go and it’s going to be called an
go and it’s going to be called an
go and it’s going to be called an I’m going to get this right here int
I’m going to get this right here int
I’m going to get this right here int wait string name and this is basically
wait string name and this is basically
wait string name and this is basically going to do exactly the same thing that
going to do exactly the same thing that
going to do exactly the same thing that this does let’s just go in there paste
this does let’s just go in there paste
this does let’s just go in there paste it in there and you can see that
it in there and you can see that
it in there and you can see that basically said all does exactly the same
basically said all does exactly the same
basically said all does exactly the same thing that constructor does so there’s
thing that constructor does so there’s
thing that constructor does so there’s no reason to put that in there I just
no reason to put that in there I just
no reason to put that in there I just did it just so I could show you another
did it just so I could show you another
did it just so I could show you another function inside of there so let’s just
function inside of there so let’s just
function inside of there so let’s just get rid of this to show you the regular
get rid of this to show you the regular
get rid of this to show you the regular functions and constructors all are the
functions and constructors all are the
functions and constructors all are the same for the D constructor we’re just
same for the D constructor we’re just
same for the D constructor we’re just going to go animal two colons ampersand
going to go animal two colons ampersand
going to go animal two colons ampersand animal doesn’t receive anything and then
animal doesn’t receive anything and then
animal doesn’t receive anything and then we could come in here and just put a
we could come in here and just put a
we could come in here and just put a message out animal we get this specific
message out animal we get this specific
message out animal we get this specific animal name put this in there again name
animal name put this in there again name
animal name put this in there again name and destroyed just so that we have a
and destroyed just so that we have a
and destroyed just so that we have a message on the screen to see what’s
message on the screen to see what’s
message on the screen to see what’s going on we have our overloaded
going on we have our overloaded
going on we have our overloaded constructor that’s going to be called
constructor that’s going to be called
constructor that’s going to be called whenever no attributes are passed in an
whenever no attributes are passed in an
whenever no attributes are passed in an animal animal it’s still constructor no
animal animal it’s still constructor no
animal animal it’s still constructor no attributes and in this situation we
attributes and in this situation we
attributes and in this situation we could also call that we have created
could also call that we have created
could also call that we have created another animal then we have the two
another animal then we have the two
another animal then we have the two string where’s that at
string where’s that at
string where’s that at there it is say just void to string
there it is say just void to string
there it is say just void to string let’s come down here and declare that
let’s come down here and declare that
let’s come down here and declare that void doesn’t get anything animal class
void doesn’t get anything animal class
void doesn’t get anything animal class name to string doesn’t receive
name to string doesn’t receive
name to string doesn’t receive attributes and here we could come in and
attributes and here we could come in and
attributes and here we could come in and just print out all the information we
just print out all the information we
just print out all the information we have on our animal is and get the height
have on our animal is and get the height
have on our animal is and get the height for our specific animal object jump down
for our specific animal object jump down
for our specific animal object jump down in the next slide just keep this neat
in the next slide just keep this neat
in the next slide just keep this neat centimeters tall and this get the wait
centimeters tall and this get the wait
centimeters tall and this get the wait for it kilograms in weight and just
for it kilograms in weight and just
for it kilograms in weight and just close that off then we’ll be able to go
close that off then we’ll be able to go
close that off then we’ll be able to go down in Maine and start creating animal
down in Maine and start creating animal
down in Maine and start creating animal object so to create this let’s say we
object so to create this let’s say we
object so to create this let’s say we want to create an animal named Fred we
want to create an animal named Fred we
want to create an animal named Fred we could then go into Fred and set his
could then go into Fred and set his
could then go into Fred and set his height to 33 set his weight to 10 and
height to 33 set his weight to 10 and
height to 33 set his weight to 10 and set his name of course to Fred I like
set his name of course to Fred I like
set his name of course to Fred I like that just create a new Fred animal we
that just create a new Fred animal we
that just create a new Fred animal we could then get the values back from it I
could then get the values back from it I
could then get the values back from it I going Fred dot get name is we’re not
going Fred dot get name is we’re not
going Fred dot get name is we’re not using this here just to show you the
using this here just to show you the
using this here just to show you the difference between trying to get the
difference between trying to get the
difference between trying to get the data from inside of the class itself and
data from inside of the class itself and
data from inside of the class itself and then trying to get it somewhere else
then trying to get it somewhere else
then trying to get it somewhere else centimeters tall and Fred get weight
centimeters tall and Fred get weight
centimeters tall and Fred get weight kilograms
kilograms
kilograms in fight there we are and we could also
in fight there we are and we could also
in fight there we are and we could also come in and use our constructor in this
come in and use our constructor in this
come in and use our constructor in this situation here we are using the default
situation here we are using the default
situation here we are using the default constructor that doesn’t get any
constructor that doesn’t get any
constructor that doesn’t get any attributes and here we’ll use the
attributes and here we’ll use the
attributes and here we’ll use the constructor that does get out your bids
constructor that does get out your bids
constructor that does get out your bids so we’ll pass in 3615 and Tom and then
so we’ll pass in 3615 and Tom and then
so we’ll pass in 3615 and Tom and then we’re going to be able to also print out
we’re going to be able to also print out
we’re going to be able to also print out all the differences between Tom and Fred
all the differences between Tom and Fred
all the differences between Tom and Fred let’s print that out and then just
let’s print that out and then just
let’s print that out and then just change this to Tom there’s Tom there’s
change this to Tom there’s Tom there’s
change this to Tom there’s Tom there’s Tom there’s Tom and made little error
Tom there’s Tom and made little error
Tom there’s Tom and made little error here let’s just jump up to set name and
here let’s just jump up to set name and
here let’s just jump up to set name and let’s make sure we change this to a
let’s make sure we change this to a
let’s make sure we change this to a string and on an integer move a little
string and on an integer move a little
string and on an integer move a little bit too fast here sometimes make little
bit too fast here sometimes make little
bit too fast here sometimes make little mistakes and there’s an animal name
mistakes and there’s an animal name
mistakes and there’s an animal name that’s also come down here and change
that’s also come down here and change
that’s also come down here and change this name and then change this to name
this name and then change this to name
this name and then change this to name all right so there you go now you saw
all right so there you go now you saw
all right so there you go now you saw that we created a Fred and a Tom object
that we created a Fred and a Tom object
that we created a Fred and a Tom object let’s go over and execute that and there
let’s go over and execute that and there
let’s go over and execute that and there you can see fred is 33 centimeters tall
you can see fred is 33 centimeters tall
you can see fred is 33 centimeters tall 10 kilograms in weight tom is 36
10 kilograms in weight tom is 36
10 kilograms in weight tom is 36 centimeters tall 15 kilograms in weight
centimeters tall 15 kilograms in weight
centimeters tall 15 kilograms in weight and here you can see the destructor was
and here you can see the destructor was
and here you can see the destructor was called to destroy both those objects
called to destroy both those objects
called to destroy both those objects since we no longer need them now we can
since we no longer need them now we can
since we no longer need them now we can also come in and inherit all of the
also come in and inherit all of the
also come in and inherit all of the attributes and the methods that are
attributes and the methods that are
attributes and the methods that are created from the animal object and
created from the animal object and
created from the animal object and instead use them in our dog class so
instead use them in our dog class so
instead use them in our dog class so there we go just new create a new dog
there we go just new create a new dog
there we go just new create a new dog class and to inherit all the animal
class and to inherit all the animal
class and to inherit all the animal classes we just put a colon and then
classes we just put a colon and then
classes we just put a colon and then public and animal and that’s all we need
public and animal and that’s all we need
public and animal and that’s all we need to do and we have everything that is
to do and we have everything that is
to do and we have everything that is defined in the animal class we could
defined in the animal class we could
defined in the animal class we could come in here of course and create some
come in here of course and create some
come in here of course and create some new ones so let’s say we wanted to have
new ones so let’s say we wanted to have
new ones so let’s say we wanted to have a sound string that is going to have the
a sound string that is going to have the
a sound string that is going to have the value of wolf and then we could also
value of wolf and then we could also
value of wolf and then we could also come in and create a bunch of public
come in and create a bunch of public
come in and create a bunch of public methods that do some different things
methods that do some different things
methods that do some different things one thing it’s going to have to do is
one thing it’s going to have to do is
one thing it’s going to have to do is get the sound and in this situation I’m
get the sound and in this situation I’m
get the sound and in this situation I’m just going to have that print out on our
just going to have that print out on our
just going to have that print out on our screen so sound there we go since we are
screen so sound there we go since we are
screen so sound there we go since we are going to have a sound in our dog class
going to have a sound in our dog class
going to have a sound in our dog class and our dog objects we’re going to have
and our dog objects we’re going to have
and our dog objects we’re going to have to declare a new constructor that’s also
to declare a new constructor that’s also
to declare a new constructor that’s also going to get the sound so int int string
going to get the sound so int int string
going to get the sound so int int string and string I like that with that
and string I like that with that
and string I like that with that prototype we could also come in here and
prototype we could also come in here and
prototype we could also come in here and declare a default constructor that’s not
declare a default constructor that’s not
declare a default constructor that’s not to receive anything and then on top of
to receive anything and then on top of
to receive anything and then on top of that call the default superclass
that call the default superclass
that call the default superclass constructor just like going like this
constructor just like going like this
constructor just like going like this and there we are and we could also
and there we are and we could also
and there we are and we could also decide to overwrite two strings since we
decide to overwrite two strings since we
decide to overwrite two strings since we are also going to be printing out the
are also going to be printing out the
are also going to be printing out the dog sound that’s all we’re going to do
dog sound that’s all we’re going to do
dog sound that’s all we’re going to do there and then put another semicolon
there and then put another semicolon
there and then put another semicolon here at the end of course very important
here at the end of course very important
here at the end of course very important for our class now we have to go in here
for our class now we have to go in here
for our class now we have to go in here and actually define everything that was
and actually define everything that was
and actually define everything that was is going to change so this is going to
is going to change so this is going to
is going to change so this is going to be the constructor for our dog and it’s
be the constructor for our dog and it’s
be the constructor for our dog and it’s going to get passed the in tight and the
going to get passed the in tight and the
going to get passed the in tight and the integer weights and the string name as
integer weights and the string name as
integer weights and the string name as well as the string mark now to reference
well as the string mark now to reference
well as the string mark now to reference the animal class here and put a colon in
the animal class here and put a colon in
the animal class here and put a colon in an animal and we’re going to say here
an animal and we’re going to say here
an animal and we’re going to say here that we want the animal constructor to
that we want the animal constructor to
that we want the animal constructor to handle the height and the weight since
handle the height and the weight since
handle the height and the weight since it handled it so well previously however
it handled it so well previously however
it handled it so well previously however I want in this constructor to be able to
I want in this constructor to be able to
I want in this constructor to be able to handle the sound part because sound
handle the sound part because sound
handle the sound part because sound doesn’t exist in the animal class and
doesn’t exist in the animal class and
doesn’t exist in the animal class and here we’re just going to have a theme
here we’re just going to have a theme
here we’re just going to have a theme park so that’s a great way to have the
park so that’s a great way to have the
park so that’s a great way to have the animal constructor handle height weight
animal constructor handle height weight
animal constructor handle height weight name because all those attributes are
name because all those attributes are
name because all those attributes are going to be shared and at the same time
going to be shared and at the same time
going to be shared and at the same time just change the thing that is different
just change the thing that is different
just change the thing that is different saves us some space also could come in
saves us some space also could come in
saves us some space also could come in here because to string also changed so
here because to string also changed so
here because to string also changed so let’s go in here and change it and
let’s go in here and change it and
let’s go in here and change it and because the attributes like name and
because the attributes like name and
because the attributes like name and height and weight were private in animal
height and weight were private in animal
height and weight were private in animal I’m going to have to use the get method
I’m going to have to use the get method
I’m going to have to use the get method to be able to access them so I’m going
to be able to access them so I’m going
to be able to access them so I’m going to say this get name right like that is
to say this get name right like that is
to say this get name right like that is this get height centimeters tall and
this get height centimeters tall and
this get height centimeters tall and this get weight kilograms in weight and
this get weight kilograms in weight and
this get weight kilograms in weight and says this is the thing that’s different
says this is the thing that’s different
says this is the thing that’s different jump down here this sound okay now I can
jump down here this sound okay now I can
jump down here this sound okay now I can demonstrate actually creating a dog
demonstrate actually creating a dog
demonstrate actually creating a dog object so let’s just go dog and let’s
object so let’s just go dog and let’s
object so let’s just go dog and let’s call him spot I’m going to pass in 38 16
call him spot I’m going to pass in 38 16
call him spot I’m going to pass in 38 16 his name is spot and the sound is going
his name is spot and the sound is going
his name is spot and the sound is going to be wolf if I also just want to
to be wolf if I also just want to
to be wolf if I also just want to demonstrate using static methods here go
demonstrate using static methods here go
demonstrate using static methods here go see out number of animals that
see out number of animals that
see out number of animals that created animal and to call a static
created animal and to call a static
created animal and to call a static method you go get numb of animals
method you go get numb of animals
method you go get numb of animals believe that’s what they called it find
believe that’s what they called it find
believe that’s what they called it find out in a second and now I’m also going
out in a second and now I’m also going
out in a second and now I’m also going to be able to go spot dot it sound and
to be able to go spot dot it sound and
to be able to go spot dot it sound and we could also go in and get Tom test to
we could also go in and get Tom test to
we could also go in and get Tom test to string which basically does with all
string which basically does with all
string which basically does with all that other stuff did up there spot dot
that other stuff did up there spot dot
that other stuff did up there spot dot to string and just to show you one other
to string and just to show you one other
to string and just to show you one other thing we could also call the superclass
thing we could also call the superclass
thing we could also call the superclass version of a method by going animal spot
version of a method by going animal spot
version of a method by going animal spot animal and then put in two colons and
animal and then put in two colons and
animal and then put in two colons and string and by the way I keep calling
string and by the way I keep calling
string and by the way I keep calling this two colons this is called the scope
this two colons this is called the scope
this two colons this is called the scope operator if you want to know what that’s
operator if you want to know what that’s
operator if you want to know what that’s really called and of course the end here
really called and of course the end here
really called and of course the end here make sure we put our return statement
make sure we put our return statement
make sure we put our return statement with zero and if we execute it you can
with zero and if we execute it you can
with zero and if we execute it you can say there is everything number of
say there is everything number of
say there is everything number of animals that were created you can see
animals that were created you can see
animals that were created you can see it’s three right there and that includes
it’s three right there and that includes
it’s three right there and that includes spot being the dog as well as Fred and
spot being the dog as well as Fred and
spot being the dog as well as Fred and also Tom so that’s the reason why that
also Tom so that’s the reason why that
also Tom so that’s the reason why that showed up and the reason why is the
showed up and the reason why is the
showed up and the reason why is the animal constructor was called every
animal constructor was called every
animal constructor was called every single time whether dog was created or
single time whether dog was created or
single time whether dog was created or animals were created you can see wolf
animals were created you can see wolf
animals were created you can see wolf right here is this guy right here
right here is this guy right here
right here is this guy right here calling get sound you can see we’re
calling get sound you can see we’re
calling get sound you can see we’re calling to string on tom to print out
calling to string on tom to print out
calling to string on tom to print out the information on that we can see here
the information on that we can see here
the information on that we can see here that spot also says wolf while the
that spot also says wolf while the
that spot also says wolf while the regular animal does not not
regular animal does not not
regular animal does not not automatically works and here we’re just
automatically works and here we’re just
automatically works and here we’re just demonstrating the use of calling to
demonstrating the use of calling to
demonstrating the use of calling to string and in this situation spot
string and in this situation spot
string and in this situation spot whether he has a sound or not doesn’t
whether he has a sound or not doesn’t
whether he has a sound or not doesn’t matter because we are calling the animal
matter because we are calling the animal
matter because we are calling the animal version of two string and the animal
version of two string and the animal
version of two string and the animal version of two string only prints out
version of two string only prints out
version of two string only prints out the height and the weight as well as the
the height and the weight as well as the
the height and the weight as well as the name and then finally you can see right
name and then finally you can see right
name and then finally you can see right here where the destructors are called
here where the destructors are called
here where the destructors are called and all of our objects are destroyed
and all of our objects are destroyed
and all of our objects are destroyed okay now it’s time to talk about virtual
okay now it’s time to talk about virtual
okay now it’s time to talk about virtual methods and polymorphism I’m gonna hold
methods and polymorphism I’m gonna hold
methods and polymorphism I’m gonna hold off on the definition for polymorphism
off on the definition for polymorphism
off on the definition for polymorphism here and instead create a new animal
here and instead create a new animal
here and instead create a new animal class and it’s going to have some public
class and it’s going to have some public
class and it’s going to have some public stuff that it does and what it’s going
stuff that it does and what it’s going
stuff that it does and what it’s going to do here first off is get family which
to do here first off is get family which
to do here first off is get family which I’m going to refer to as a family of
I’m going to refer to as a family of
I’m going to refer to as a family of objects and there’s just say we are
objects and there’s just say we are
objects and there’s just say we are animals close that off and then this is
animals close that off and then this is
animals close that off and then this is where we get two virtual methods I’m
where we get two virtual methods I’m
where we get two virtual methods I’m going to mark this as virtual and then
going to mark this as virtual and then
going to mark this as virtual and then I’m going to change it back
I’m going to change it back
I’m going to change it back from virtual basically we mark a method
from virtual basically we mark a method
from virtual basically we mark a method as virtual when we know that an animal
as virtual when we know that an animal
as virtual when we know that an animal in this situation will be a base class
in this situation will be a base class
in this situation will be a base class that may have this method overwritten by
that may have this method overwritten by
that may have this method overwritten by a subclass and you’re going to see it in
a subclass and you’re going to see it in
a subclass and you’re going to see it in action here it’ll make more sense when
action here it’ll make more sense when
action here it’ll make more sense when you see it in action so in this
you see it in action so in this
you see it in action so in this situation let’s say get class and then
situation let’s say get class and then
situation let’s say get class and then I’m gonna go I’m and and okay so these
I’m gonna go I’m and and okay so these
I’m gonna go I’m and and okay so these are all in the family of animals but the
are all in the family of animals but the
are all in the family of animals but the specific class for this is animal in
specific class for this is animal in
specific class for this is animal in this situation and close that off and
this situation and close that off and
this situation and close that off and now we’re going to need to create a
now we’re going to need to create a
now we’re going to need to create a subclass called dog of type and more
subclass called dog of type and more
subclass called dog of type and more it’s going to inherit from animal and
it’s going to inherit from animal and
it’s going to inherit from animal and it’s going to have public course it
it’s going to have public course it
it’s going to have public course it inherits everything get class in this
inherits everything get class in this
inherits everything get class in this case I’m a dog is going to get printed
case I’m a dog is going to get printed
case I’m a dog is going to get printed out and then close off that class now
out and then close off that class now
out and then close off that class now what we’re going to be able to do here
what we’re going to be able to do here
what we’re going to be able to do here is come down inside of here create an
is come down inside of here create an
is come down inside of here create an animal class is equal to new animal and
animal class is equal to new animal and
animal class is equal to new animal and dog in this situation new dog now in
dog in this situation new dog now in
dog in this situation new dog now in this situation it’s not going to matter
this situation it’s not going to matter
this situation it’s not going to matter if this is marked as virtual or not
if this is marked as virtual or not
if this is marked as virtual or not because these are both references to
because these are both references to
because these are both references to animals and dogs as you can see right
animals and dogs as you can see right
animals and dogs as you can see right here I can just go animal – get class
here I can just go animal – get class
here I can just go animal – get class and dog dot get class right like that
and dog dot get class right like that
and dog dot get class right like that here I got the virtual part off of there
here I got the virtual part off of there
here I got the virtual part off of there and here you can see if I execute this
and here you can see if I execute this
and here you can see if I execute this I’m a dog and I’m an animal both print
I’m a dog and I’m an animal both print
I’m a dog and I’m an animal both print they’re on the screen if I was however
they’re on the screen if I was however
they’re on the screen if I was however going to try and call get class from a
going to try and call get class from a
going to try and call get class from a function you’re going to see that we get
function you’re going to see that we get
function you’re going to see that we get some problems so here we’re going to say
some problems so here we’re going to say
some problems so here we’re going to say void what class are you and we pass in
void what class are you and we pass in
void what class are you and we pass in an animal object they’re both animal
an animal object they’re both animal
an animal object they’re both animal objects remember well you would think
objects remember well you would think
objects remember well you would think I’d be able to go animal get class and
I’d be able to go animal get class and
I’d be able to go animal get class and get the exactly the same results however
get the exactly the same results however
get the exactly the same results however as you’re going to see if I do that by
as you’re going to see if I do that by
as you’re going to see if I do that by passing in animal and dog we don’t get
passing in animal and dog we don’t get
passing in animal and dog we don’t get the results we expect instead what
the results we expect instead what
the results we expect instead what happens is I’m an animal gets passed in
happens is I’m an animal gets passed in
happens is I’m an animal gets passed in both times if we want to be able to call
both times if we want to be able to call
both times if we want to be able to call the proper get class for the dog and the
the proper get class for the dog and the
the proper get class for the dog and the proper get class for the animal all we
proper get class for the animal all we
proper get class for the animal all we need to do is come up here and type in
need to do is come up here and type in
need to do is come up here and type in virtual and all that means is it’s
virtual and all that means is it’s
virtual and all that means is it’s saying hey we expect this to change so
saying hey we expect this to change so
saying hey we expect this to change so if you get a dog whether it’s an animal
if you get a dog whether it’s an animal
if you get a dog whether it’s an animal or not why don’t you go take a chance
or not why don’t you go take a chance
or not why don’t you go take a chance and take a look at if get class resides
and take a look at if get class resides
and take a look at if get class resides in the dog class or dog
in the dog class or dog
in the dog class or dog and now you’re going to see everything
and now you’re going to see everything
and now you’re going to see everything prints out exactly the right way now
prints out exactly the right way now
prints out exactly the right way now we’re going to come up and create a
we’re going to come up and create a
we’re going to come up and create a couple more classes let’s say that we
couple more classes let’s say that we
couple more classes let’s say that we also want to create another class and
also want to create another class and
also want to create another class and let’s call this German Shepherd which is
let’s call this German Shepherd which is
let’s call this German Shepherd which is a little bit more specific and it is
a little bit more specific and it is
a little bit more specific and it is going to be of type dog and then we’ll
going to be of type dog and then we’ll
going to be of type dog and then we’ll go in and type in public void and
go in and type in public void and
go in and type in public void and overwrite get class with I’m a German
overwrite get class with I’m a German
overwrite get class with I’m a German Shepherd ndele closing curly bracket and
Shepherd ndele closing curly bracket and
Shepherd ndele closing curly bracket and void get derived I’m an animal and dog
void get derived I’m an animal and dog
void get derived I’m an animal and dog ndele closing curly bracket and now come
ndele closing curly bracket and now come
ndele closing curly bracket and now come down here and experiment a little bit
down here and experiment a little bit
down here and experiment a little bit more see basically polymorphism all it
more see basically polymorphism all it
more see basically polymorphism all it means is whenever a animal is passed in
means is whenever a animal is passed in
means is whenever a animal is passed in in this situation like it did right here
in this situation like it did right here
in this situation like it did right here we passed in an animal object it’s
we passed in an animal object it’s
we passed in an animal object it’s automatically going to find the right
automatically going to find the right
automatically going to find the right method to call so that’s that’s
method to call so that’s that’s
method to call so that’s that’s basically it now there’s many ways you
basically it now there’s many ways you
basically it now there’s many ways you can apply polymorphism but polymorphism
can apply polymorphism but polymorphism
can apply polymorphism but polymorphism on its own looks like that so let’s
on its own looks like that so let’s
on its own looks like that so let’s create a dog object and then let’s
create a dog object and then let’s
create a dog object and then let’s create a German Shepherd and call him
create a German Shepherd and call him
create a German Shepherd and call him max the base class can also call derived
max the base class can also call derived
max the base class can also call derived class methods as long as they exist in
class methods as long as they exist in
class methods as long as they exist in the base class so we’re going to come up
the base class so we’re going to come up
the base class so we’re going to come up here create an animal it’s a pointer to
here create an animal it’s a pointer to
here create an animal it’s a pointer to the dog and to get a reference to spot
the dog and to get a reference to spot
the dog and to get a reference to spot we just put that little inverse and in
we just put that little inverse and in
we just put that little inverse and in there create another one and point this
there create another one and point this
there create another one and point this to the German Shepherd get a reference
to the German Shepherd get a reference
to the German Shepherd get a reference to that with Max we can now call the
to that with Max we can now call the
to that with Max we can now call the method that was not overwritten by any
method that was not overwritten by any
method that was not overwritten by any of the other classes get family that’s
of the other classes get family that’s
of the other classes get family that’s the same an animal we could also call
the same an animal we could also call
the same an animal we could also call get class which was overwritten and then
get class which was overwritten and then
get class which was overwritten and then come in here change this deployed sorry
come in here change this deployed sorry
come in here change this deployed sorry about that and then of course also close
about that and then of course also close
about that and then of course also close off our class the curly bracket and
off our class the curly bracket and
off our class the curly bracket and execute it and there you can see we are
execute it and there you can see we are
execute it and there you can see we are dogs we were able to call this guy
dogs we were able to call this guy
dogs we were able to call this guy properly and then I’m a dog see this is
properly and then I’m a dog see this is
properly and then I’m a dog see this is a reference to dog spot and we were able
a reference to dog spot and we were able
a reference to dog spot and we were able to call the proper get family because
to call the proper get family because
to call the proper get family because this was listed as an animal and also
this was listed as an animal and also
this was listed as an animal and also we’re able to call the very specific
we’re able to call the very specific
we’re able to call the very specific class that resides in dog even though
class that resides in dog even though
class that resides in dog even though these were listed as animals another
these were listed as animals another
these were listed as animals another example of polymorphism another thing
example of polymorphism another thing
example of polymorphism another thing that’s neat is we can actually call the
that’s neat is we can actually call the
that’s neat is we can actually call the superclass German Shepherd because
superclass German Shepherd because
superclass German Shepherd because everything is inherited so we can call
everything is inherited so we can call
everything is inherited so we can call get family that resides in the animal
get family that resides in the animal
get family that resides in the animal class and of course we can also call the
class and of course we can also call the
class and of course we can also call the overwritten German Shepherd version
overwritten German Shepherd version
overwritten German Shepherd version shepherd and it’s automatically going to
shepherd and it’s automatically going to
shepherd and it’s automatically going to go and get the right thing as you can
go and get the right thing as you can
go and get the right thing as you can see right there we’re animals and I’m a
see right there we’re animals and I’m a
see right there we’re animals and I’m a German Shepherd so there’s an example of
German Shepherd so there’s an example of
German Shepherd so there’s an example of using virtual methods as well as a whole
using virtual methods as well as a whole
using virtual methods as well as a whole bunch of different examples on how
bunch of different examples on how
bunch of different examples on how polymorphism works and then to finally
polymorphism works and then to finally
polymorphism works and then to finally get polymorphism hundred percent in your
get polymorphism hundred percent in your
get polymorphism hundred percent in your head let’s go and create an animal
head let’s go and create an animal
head let’s go and create an animal object as well as a dog object and a cat
object as well as a dog object and a cat
object as well as a dog object and a cat object that all inherit from the animal
object that all inherit from the animal
object that all inherit from the animal class now the animal is going to be a
class now the animal is going to be a
class now the animal is going to be a virtual method again because we’re going
virtual method again because we’re going
virtual method again because we’re going to override it and we’re going to treat
to override it and we’re going to treat
to override it and we’re going to treat them as animals because they are curly
them as animals because they are curly
them as animals because they are curly bracket and we’ll say the animal says
bracket and we’ll say the animal says
bracket and we’ll say the animal says ger basically going to do exactly make
ger basically going to do exactly make
ger basically going to do exactly make sure you put that closing curly bracket
sure you put that closing curly bracket
sure you put that closing curly bracket on there and then we’re not going to
on there and then we’re not going to
on there and then we’re not going to copy the virtual part in this situation
copy the virtual part in this situation
copy the virtual part in this situation in the dog here we’re going to say the
in the dog here we’re going to say the
in the dog here we’re going to say the dog says woof and then the cat says meow
dog says woof and then the cat says meow
dog says woof and then the cat says meow as homework you could look into how you
as homework you could look into how you
as homework you could look into how you would actually set up an animal class as
would actually set up an animal class as
would actually set up an animal class as a capability class that exists only to
a capability class that exists only to
a capability class that exists only to be derived from so look into that that
be derived from so look into that that
be derived from so look into that that is your homework because you guys asked
is your homework because you guys asked
is your homework because you guys asked for homework all the time and now I’m
for homework all the time and now I’m
for homework all the time and now I’m going to also jump in here and give you
going to also jump in here and give you
going to also jump in here and give you an example of what an abstract data type
an example of what an abstract data type
an example of what an abstract data type looks like so let’s say we have a car
looks like so let’s say we have a car
looks like so let’s say we have a car and this is more for completionists
and this is more for completionists
and this is more for completionists reasons than anything else we could come
reasons than anything else we could come
reasons than anything else we could come in here and public again virtual int get
in here and public again virtual int get
in here and public again virtual int get numb wheels the value 0 and virtual int
numb wheels the value 0 and virtual int
numb wheels the value 0 and virtual int get numb doors and then you’d be able to
get numb doors and then you’d be able to
get numb doors and then you’d be able to derive this by coming in here and
derive this by coming in here and
derive this by coming in here and creating a new class called stationwagon
creating a new class called stationwagon
creating a new class called stationwagon inherit from car even though car doesn’t
inherit from car even though car doesn’t
inherit from car even though car doesn’t do anything closing bracket move that up
do anything closing bracket move that up
do anything closing bracket move that up and then come in and define everything
and then come in and define everything
and then come in and define everything that we saw in the generic car or the
that we saw in the generic car or the
that we saw in the generic car or the generic car abstract data type get numb
generic car abstract data type get numb
generic car abstract data type get numb wheels as for wheels like that close
wheels as for wheels like that close
wheels as for wheels like that close that off and then we could go int get
that off and then we could go int get
that off and then we could go int get numb doors just like we defined up here
numb doors just like we defined up here
numb doors just like we defined up here in this abstract data type for car stage
in this abstract data type for car stage
in this abstract data type for car stage wagon has four doors and then we could
wagon has four doors and then we could
wagon has four doors and then we could also come in here and go station wagon
also come in here and go station wagon
also come in here and go station wagon create an empty constructor and a
create an empty constructor and a
create an empty constructor and a destructor right like that now let’s
destructor right like that now let’s
destructor right like that now let’s jump down in Maine and play around with
jump down in Maine and play around with
jump down in Maine and play around with these guys so we’re going to create
these guys so we’re going to create
these guys so we’re going to create another animal here for our cat and to
another animal here for our cat and to
another animal here for our cat and to do that we just call cat and animal dog
do that we just call cat and animal dog
do that we just call cat and animal dog new dog and we can see that if we call
new dog and we can see that if we call
new dog and we can see that if we call the cat specifically saying we want it
the cat specifically saying we want it
the cat specifically saying we want it to make a sound and then we do the same
to make a sound and then we do the same
to make a sound and then we do the same thing with the dog you can see that the
thing with the dog you can see that the
thing with the dog you can see that the cat says meow and the dog says wolf even
cat says meow and the dog says wolf even
cat says meow and the dog says wolf even though they’re both set up as animals
though they’re both set up as animals
though they’re both set up as animals now let’s go in and test our abstract
now let’s go in and test our abstract
now let’s go in and test our abstract data type with the car let’s create a
data type with the car let’s create a
data type with the car let’s create a stationwagon
stationwagon
stationwagon of type car it’s equal to new station
of type car it’s equal to new station
of type car it’s equal to new station wagon
wagon
wagon I like this and even though is a car
I like this and even though is a car
I like this and even though is a car object get numb wheels you can see that
object get numb wheels you can see that
object get numb wheels you can see that station wagon has four wheels shows up
station wagon has four wheels shows up
station wagon has four wheels shows up there on the screen there’s a whole
there on the screen there’s a whole
there on the screen there’s a whole bunch of different examples of
bunch of different examples of
bunch of different examples of polymorphism and a whole lot of
polymorphism and a whole lot of
polymorphism and a whole lot of information on C++ hope you guys enjoyed
information on C++ hope you guys enjoyed
information on C++ hope you guys enjoyed this video if you actually watch the
this video if you actually watch the
this video if you actually watch the whole entire thing please leave a
whole entire thing please leave a
whole entire thing please leave a comment telling me so I would really
comment telling me so I would really
comment telling me so I would really appreciate that and please leave your
appreciate that and please leave your
appreciate that and please leave your questions and comments below otherwise
questions and comments below otherwise
questions and comments below otherwise till next time
Be First to Comment