00:00:01
hi everyone what hi everyone welcome to
00:00:09
my channel welcome tragic
00:00:12
[Music]
00:00:18
[Music]
00:00:31
hi everyone welcome to my channel
00:00:34
welcome to another video of C++ for
00:00:36
beginners in this video I want to show
00:00:38
you how you can draw shapes using C++ so
00:00:41
before we start make sure to subscribe
00:00:43
to my channel and also hit that Bell
00:00:45
icon as well so that you are notified
00:00:47
when I publish my next video and let me
00:00:51
show you now what we are going to do in
00:00:53
this video so here where is it
00:00:57
here I have image of the task that we
00:01:00
are going to do today and that is going
00:01:03
to be really to draw this rectangle
00:01:05
shape with the desired height and width
00:01:09
and a symbol that our user enters okay
00:01:13
so that is the task that we are going to
00:01:15
do in this video and let's very quickly
00:01:18
analyze this problem and see how we are
00:01:21
going to solve it so the first thing
00:01:23
that we need is for our user to enter
00:01:25
height width and that symbol and after
00:01:30
dot we will really need to figure out a
00:01:32
way so figure out the algorithm on how
00:01:35
we are going to draw this rectangle
00:01:38
shape here so if you look at this
00:01:40
rectangle shape you can really notice
00:01:42
that it has the height that is going to
00:01:46
be three of these symbols that our user
00:01:48
has entered and that it has the width
00:01:51
that is going to take four of these
00:01:53
symbols that our user has entered for
00:01:55
width okay so we are going to use nested
00:02:00
for loop in order to solve this problem
00:02:02
here and if you're not familiar with
00:02:04
nested for loop I am going to link that
00:02:07
video here because I have already made
00:02:08
one video with nested for-loops so make
00:02:11
sure to watch that video and in this
00:02:14
video I am going to really use that
00:02:17
nested for loop in order to control
00:02:19
height and width of our rectangle shape
00:02:23
so we are going to have outer for loop
00:02:26
which is going to really control this
00:02:28
height and then for each iteration of
00:02:32
our outer for loop we are
00:02:34
really going to control this wit with
00:02:38
another loop and we are going to count
00:02:40
from 1 up to 4 because 4 is the width
00:02:45
that our user has entered and throw that
00:02:47
shape in each iteration of our inner for
00:02:51
loop ok so that is what we are going to
00:02:54
do so let's now translate that into code
00:02:57
I'm going to say here first thing that
00:03:00
we need is going to be from our user to
00:03:02
enter width and height so I'm going to
00:03:04
declare two variables the first one is
00:03:07
going to be height like this and then
00:03:11
with okay so let's write out a message
00:03:17
to our user so that he knows that he
00:03:19
should enter height okay now let's
00:03:25
accept that height value in our height
00:03:29
variable and after that let's really
00:03:32
copy this and do the same thing for our
00:03:34
width like this and accept that value in
00:03:40
our width variable so that is the first
00:03:43
step the second step is going to be to
00:03:45
declare another variable which is going
00:03:47
to hold the symbol that our user wants
00:03:49
to use for drawing that shape so I'm
00:03:52
going to declare a variable of type char
00:03:54
and I'm going to call it symbol like
00:03:58
this and let's write out a message to
00:04:01
the user so that he knows that he should
00:04:03
enter that symbol like this and let's
00:04:08
say C in symbol so after we have
00:04:15
acquired all the necessary inputs from
00:04:17
our user which are height width and
00:04:20
symbol that we are going to use to draw
00:04:23
our shape now we are left to write the
00:04:26
algorithm that is going to draw that
00:04:28
rectangle shape so as I already said for
00:04:31
that we are going to use nested for loop
00:04:34
so I am going to setup my outer loop the
00:04:38
first loop and I'm going to say for and
00:04:41
then I'm going to declare the counter
00:04:43
which is going to count the iterations
00:04:45
of my outer loop since
00:04:48
that outer loop is going to control the
00:04:50
height of our rectangle I'm going to say
00:04:52
int age so I'm going to give the age
00:04:56
name to our outer counter and I'm going
00:04:59
to set its initial value to zero like
00:05:02
this and then we are going to put the
00:05:04
condition how long our outer loop is
00:05:07
going to run it so while our age is less
00:05:11
than height that our user has entered
00:05:14
like this and then after each iteration
00:05:17
of my outer loop we have to increment
00:05:20
the value of our age counter so that
00:05:24
would be the setup of our outer loop and
00:05:27
let's now set up our inner loop so I'm
00:05:30
going to write for and for this inner
00:05:34
loop I'm going to declare another
00:05:35
counter which I'm going to call W like
00:05:39
this because this inner loop is going to
00:05:41
control the width of rectangle shape so
00:05:44
I'm going to set its initial value to
00:05:46
zero as well and then I'm going to say
00:05:49
that it is going to run while this w is
00:05:52
less than what that our user has entered
00:05:57
like this and also after each iteration
00:06:00
we really need to increment the value of
00:06:03
this W okay so what we are going to do
00:06:08
in this loop so in this inner loop if
00:06:12
you look at this image here where is it
00:06:14
okay here you can really notice that in
00:06:19
each iteration of our inner loop it just
00:06:22
draws this symbol that our user has
00:06:24
entered so I am going to very quickly
00:06:27
just see out so right that symbol out
00:06:30
I'm going say C out and then write out
00:06:33
that symbol like this and there is
00:06:37
really one more thing that we need to
00:06:38
put and there is going to be after this
00:06:41
for loop so this outer for loop finishes
00:06:44
single iteration we really need to put
00:06:47
something else at the end so here at the
00:06:50
end of our outer for loop and let's look
00:06:53
at our image so as you can see here
00:06:55
after each iteration of our outer for
00:06:59
loop because it is controlling high
00:07:01
and it is really iterating through this
00:07:04
inner for loop in each iteration of our
00:07:07
outer for loop at the end of that
00:07:10
iteration of outer for loop we really
00:07:12
need to put empty space so here I need
00:07:16
to put empty space and that corresponds
00:07:19
to this line here so here I'm going to
00:07:23
write out C out and line like this and
00:07:28
now if I run my program we should really
00:07:32
expect to see the shape that rectangle
00:07:36
shape off dimensions that our user
00:07:38
defines so let's say for height four and
00:07:41
then for width let's say for example six
00:07:43
and the symbol that we want to use to
00:07:46
draw that shape let's say that that is
00:07:47
going to be this plus symbol okay so as
00:07:52
you can see our rectangle has the height
00:07:55
of four and then it has the width of two
00:08:00
four six so it has the width of six of
00:08:02
these symbols that our user has entered
00:08:04
okay so there is one more thing that I
00:08:07
notice here and that is going to be
00:08:09
really to format this shape to be a bit
00:08:14
more pretty so for that we are going to
00:08:17
use the library which is called IO manop
00:08:21
so I am going to include that library
00:08:24
here I have to say include IO map like
00:08:31
this and this library here really
00:08:34
contains a function that is that is
00:08:37
called set W which means set width which
00:08:41
is really going to set the width of the
00:08:43
field that comes after it so I'm going
00:08:46
to put here that function I'm going to
00:08:49
say I'm going to put these redirection
00:08:52
signs here and then in this space here
00:08:55
I'm going to write out set V so set W
00:08:59
actually and then here I want to put
00:09:02
what is the width of the field that
00:09:05
comes after this function so what is
00:09:07
going to be the width of our symbol
00:09:09
field and let's use three for a dot for
00:09:12
example so if I run mine
00:09:15
again but let me stop it first and if I
00:09:18
run it again oh no I haven't stopped my
00:09:23
program so I'm going to close it okay
00:09:26
and now if I run my program you can see
00:09:29
that it asks height and width I guess so
00:09:32
previously we have entered four and six
00:09:34
and then for the symbol let's enter plus
00:09:37
again and now as you can see our shape
00:09:41
looks much nicer because of this set
00:09:44
width function because it has really
00:09:46
assigned to each symbol to each
00:09:49
character that our user has entered the
00:09:51
width of three fields okay so let's run
00:09:56
our program one more time and let's say
00:09:59
that that height is going to be 5 and
00:10:02
which is going to be 7 and let's enter
00:10:05
another shape so let's say for example -
00:10:07
and as you can see it has written out
00:10:10
the shape so the rectangle shape of
00:10:13
these dimensions that our user has
00:10:15
entered and it has used this symbol that
00:10:18
our user also has entered so I hope that
00:10:22
you enjoyed this video if you did make
00:10:24
sure to subscribe to my channel and
00:10:26
click the bell icon as well also if you
00:10:29
want me to make more videos like this so
00:10:31
if you want me to use programming to
00:10:33
draw more shapes make sure to write that
00:10:35
in the comments down below so that I can
00:10:37
know that you really enjoyed this video
00:10:39
and like it as well and code from this
00:10:42
video I am going to put in the
00:10:44
description so that you can find it
00:10:46
there and use it if you need it and
00:10:48
thanks for watching I'm going to see you
00:10:50
in my next video
00:10:52
bye