OK, welcome back, everybody.
So this is our program that we just recently wrote that uses a two dimensional dynamic array to store
our multiplication table in this lecture.
We are just going to be kind of formatting the output better because the problem with the last lecture
or at least the problem with the output that we had in the last lecture was that it was a little messy
when we kind of started increasing our table size, right?
So we're going to discuss something in C++ that can format the output that prints to the console.
We're just going to discuss one function that comes from another library where you can manipulate the
input and output streams.
So it's going to be a pretty straightforward lecture.
Not a lot of new stuff.
I was going to introduce a nother way to make it two dimensional dynamic array.
It's actually a better way, but I feel like that is probably too overwhelming right now.
Shouldn't introduce like multiple ways right off the bat.
I think later on we can get into that because I just I don't want people to be confused with just having
so much input on the dynamic arrays so fast.
So we'll go ahead and use this.
It's totally fine.
For right now, there is a way that takes up a little bit less memory.
And we can discuss that in the near future, but I think that I would like to use this dynamic array
for the first project, this style.
And so that's what you're going to be using.
We will have that either in the next lecture or the lecture after will be discussing the project.
But in this lecture audience, let's just go over how to fix our output.
So let's see what the problem actually was originally.
So I'm just going to make sure that I have this current version saved and then I'm going to go ahead
and compile it.
And let's go ahead and run it and put a specific table size here.
So I'll go ahead and just say, like table size eight or something like that.
So you notice that it kind of has like this, you know, offset spacing and stuff.
It just doesn't look very clean.
It's just leaning kind of this way over here.
And so there's a way that we can fix that.
It actually is another library we're going to include.
And just like I o stream, it's going to be about input and output streams, but it's actually going
to be called Io minute.
So that is probably standing for what you think it is, which is manipulation.
So input output manipulation.
And we're only going to discuss one function that comes from this part of the standard template library
and that is going to be the set W, which stands for set width.
So it just looks like this.
It's set W and then we're going to put our little parentheses here since it's a function and it's not
a method or member function where we put a dot before it.
It's just a function like this similar to like get line or something like that.
And then we're going to put one argument to this function.
And that argument is going to be the minimum number of spaces that we expect our output variable to
consume.
And what is our output?
It's really this right here.
So we're printing out an integer, right?
We're getting that integer from this kind of double indexing the multiplication table, right?
Because it's a 2D array.
But this piece of output is going to be now affected by this right here, and we need to say how many
characters at minimum we expect the output to consume.
So here you notice, we just have to write.
And the problem is that we have this mixture of like one number and then we have these two numbers,
so notice that our output here looks fine in the beginning, columns right zeros are aligned.
This two three four five six seven is aligned right here.
So, you know, and then these are aligned up to here.
And then what happens, unfortunately, is that since these are double digits, they kind of push everything
to the side.
And we don't want that.
So what we're going to say is we're going to set the width to be two characters for right now.
And that expects there to basically always be two characters, so if you have one digit, it's going
to just move it over.
For example, we have a 12 over here and nine right here, right?
It's just going to move the nine over.
Not really move the nine over.
What it'll do is it's actually, yeah, it will move the nine over.
Sorry, so remove the nine over to the two position here.
And so they'll be nice and a line because it expects a width of two.
So let's go ahead and see what that looks like if we just add this.
So remember, all I did was just include this Eyoma nib from the stereotypical library.
And then I went ahead and added, This w right here, so I'm going to save this.
I'll do a little clear and then PowerShell here, compile it.
I'm going to run it.
And let's do.
Let's just say, yeah, we'll do seven.
And you notice that it's looking pretty nice now.
So it's not all like pushed over, it's actually aligned pretty nice, and you notice now this nine
here is aligned with this two on the 12 and then at the 12 wasn't like pushed over like this and affecting
all the rest of the output on the row.
So let's go ahead and run this again now, though, and I'm going to put something that will cause us
to get into three digit numbers, so hundreds, right?
So let me do something like 12 a table of size 12.
So you notice that there still is a little bit of an issue here like this is not formatted so nicely,
this stuff right here.
And that's because we just set the width for an expected consumption of two characters two spaces.
But now, since we're dealing with three digit numbers, we're going to have to up that.
So if I change this to three and save it.
And then I compile it, and then I read it again.
And I'm going to put 12 now you notice that it looks pretty nice, so I'm going to go ahead and scroll
up a bit so we can see this.
So now you notice everything is looking pretty good.
You notice they added some extra space here.
That is because we're expecting a minimum consumption of three character spaces.
So when?
When we have, you know, this is basically pushed over three spaces, then from here we have three
spaces.
So that's why you're seeing some additional space between these beginning columns.
But what it does is it makes it possible for us to still align a three digit number with just a single
digit number here as well.
So it looks nice and clean.
And of course, if you got into the the numbers in the thousands, you would want to set this to four.
And right now, I just have a single space separating these numbers, but you can kind of modify that
to look however you'd like.
I think this looks clean, though.
All right, so a pretty short lecture.
That's all I was going to go over today.
This is actually one of multiple things that can be used from this i o minute right here.
But I'm not going to go into other stuff, I just want you to know how to use, said W. or set with
so you can use it for the upcoming project, which we are about to get into.
Now that is going to be our Tic-Tac-Toe game.
You're going to need to output a variable size Tic TAC toe board.
And you're going to want to know how to make it look nice and clean for the output, so this is something
that you're probably going to end up needing to use.
So with that, I will go ahead and see you in the next lecture.