1
00:00:01,160 --> 00:00:02,630
OK, welcome back, everybody.

2
00:00:03,380 --> 00:00:14,150
So this is our program that we just recently wrote that uses a two dimensional dynamic array to store

3
00:00:14,150 --> 00:00:17,360
our multiplication table in this lecture.

4
00:00:17,780 --> 00:00:28,520
We are just going to be kind of formatting the output better because the problem with the last lecture

5
00:00:28,730 --> 00:00:34,700
or at least the problem with the output that we had in the last lecture was that it was a little messy

6
00:00:34,700 --> 00:00:37,610
when we kind of started increasing our table size, right?

7
00:00:38,510 --> 00:00:44,180
So we're going to discuss something in C++ that can format the output that prints to the console.

8
00:00:44,750 --> 00:00:52,460
We're just going to discuss one function that comes from another library where you can manipulate the

9
00:00:53,120 --> 00:00:56,060
input and output streams.

10
00:00:56,930 --> 00:01:00,200
So it's going to be a pretty straightforward lecture.

11
00:01:00,650 --> 00:01:01,820
Not a lot of new stuff.

12
00:01:01,820 --> 00:01:08,390
I was going to introduce a nother way to make it two dimensional dynamic array.

13
00:01:09,080 --> 00:01:15,610
It's actually a better way, but I feel like that is probably too overwhelming right now.

14
00:01:15,620 --> 00:01:19,760
Shouldn't introduce like multiple ways right off the bat.

15
00:01:19,760 --> 00:01:27,740
I think later on we can get into that because I just I don't want people to be confused with just having

16
00:01:27,740 --> 00:01:30,920
so much input on the dynamic arrays so fast.

17
00:01:30,920 --> 00:01:32,830
So we'll go ahead and use this.

18
00:01:32,840 --> 00:01:34,130
It's totally fine.

19
00:01:34,670 --> 00:01:38,420
For right now, there is a way that takes up a little bit less memory.

20
00:01:40,080 --> 00:01:46,940
And we can discuss that in the near future, but I think that I would like to use this dynamic array

21
00:01:46,950 --> 00:01:49,260
for the first project, this style.

22
00:01:49,800 --> 00:01:52,260
And so that's what you're going to be using.

23
00:01:53,160 --> 00:01:58,290
We will have that either in the next lecture or the lecture after will be discussing the project.

24
00:01:59,340 --> 00:02:02,760
But in this lecture audience, let's just go over how to fix our output.

25
00:02:02,760 --> 00:02:07,050
So let's see what the problem actually was originally.

26
00:02:07,980 --> 00:02:13,020
So I'm just going to make sure that I have this current version saved and then I'm going to go ahead

27
00:02:13,020 --> 00:02:15,340
and compile it.

28
00:02:15,360 --> 00:02:21,330
And let's go ahead and run it and put a specific table size here.

29
00:02:23,350 --> 00:02:28,510
So I'll go ahead and just say, like table size eight or something like that.

30
00:02:29,230 --> 00:02:36,400
So you notice that it kind of has like this, you know, offset spacing and stuff.

31
00:02:36,400 --> 00:02:37,930
It just doesn't look very clean.

32
00:02:38,230 --> 00:02:41,110
It's just leaning kind of this way over here.

33
00:02:42,130 --> 00:02:44,560
And so there's a way that we can fix that.

34
00:02:45,310 --> 00:02:48,910
It actually is another library we're going to include.

35
00:02:48,970 --> 00:02:57,010
And just like I o stream, it's going to be about input and output streams, but it's actually going

36
00:02:57,010 --> 00:02:58,930
to be called Io minute.

37
00:02:59,170 --> 00:03:04,300
So that is probably standing for what you think it is, which is manipulation.

38
00:03:04,720 --> 00:03:06,700
So input output manipulation.

39
00:03:07,840 --> 00:03:16,840
And we're only going to discuss one function that comes from this part of the standard template library

40
00:03:17,350 --> 00:03:23,560
and that is going to be the set W, which stands for set width.

41
00:03:24,100 --> 00:03:25,600
So it just looks like this.

42
00:03:25,600 --> 00:03:32,440
It's set W and then we're going to put our little parentheses here since it's a function and it's not

43
00:03:32,440 --> 00:03:36,010
a method or member function where we put a dot before it.

44
00:03:36,010 --> 00:03:40,360
It's just a function like this similar to like get line or something like that.

45
00:03:42,310 --> 00:03:45,880
And then we're going to put one argument to this function.

46
00:03:45,880 --> 00:03:55,180
And that argument is going to be the minimum number of spaces that we expect our output variable to

47
00:03:55,180 --> 00:03:55,900
consume.

48
00:03:55,900 --> 00:03:57,370
And what is our output?

49
00:03:57,610 --> 00:03:59,710
It's really this right here.

50
00:04:00,280 --> 00:04:02,710
So we're printing out an integer, right?

51
00:04:03,160 --> 00:04:08,830
We're getting that integer from this kind of double indexing the multiplication table, right?

52
00:04:08,830 --> 00:04:10,240
Because it's a 2D array.

53
00:04:11,990 --> 00:04:19,250
But this piece of output is going to be now affected by this right here, and we need to say how many

54
00:04:19,250 --> 00:04:24,050
characters at minimum we expect the output to consume.

55
00:04:24,960 --> 00:04:28,680
So here you notice, we just have to write.

56
00:04:30,150 --> 00:04:35,940
And the problem is that we have this mixture of like one number and then we have these two numbers,

57
00:04:35,950 --> 00:04:41,490
so notice that our output here looks fine in the beginning, columns right zeros are aligned.

58
00:04:41,490 --> 00:04:45,210
This two three four five six seven is aligned right here.

59
00:04:46,650 --> 00:04:50,130
So, you know, and then these are aligned up to here.

60
00:04:50,880 --> 00:04:58,920
And then what happens, unfortunately, is that since these are double digits, they kind of push everything

61
00:04:58,920 --> 00:05:00,000
to the side.

62
00:05:00,870 --> 00:05:02,100
And we don't want that.

63
00:05:02,110 --> 00:05:09,330
So what we're going to say is we're going to set the width to be two characters for right now.

64
00:05:11,070 --> 00:05:17,730
And that expects there to basically always be two characters, so if you have one digit, it's going

65
00:05:17,730 --> 00:05:18,940
to just move it over.

66
00:05:18,960 --> 00:05:22,050
For example, we have a 12 over here and nine right here, right?

67
00:05:22,410 --> 00:05:24,300
It's just going to move the nine over.

68
00:05:24,750 --> 00:05:25,920
Not really move the nine over.

69
00:05:25,920 --> 00:05:29,790
What it'll do is it's actually, yeah, it will move the nine over.

70
00:05:29,790 --> 00:05:33,930
Sorry, so remove the nine over to the two position here.

71
00:05:33,930 --> 00:05:38,130
And so they'll be nice and a line because it expects a width of two.

72
00:05:39,090 --> 00:05:42,510
So let's go ahead and see what that looks like if we just add this.

73
00:05:42,510 --> 00:05:49,710
So remember, all I did was just include this Eyoma nib from the stereotypical library.

74
00:05:49,710 --> 00:05:56,910
And then I went ahead and added, This w right here, so I'm going to save this.

75
00:05:57,750 --> 00:06:02,850
I'll do a little clear and then PowerShell here, compile it.

76
00:06:03,030 --> 00:06:03,840
I'm going to run it.

77
00:06:03,840 --> 00:06:05,820
And let's do.

78
00:06:06,180 --> 00:06:08,430
Let's just say, yeah, we'll do seven.

79
00:06:10,050 --> 00:06:13,080
And you notice that it's looking pretty nice now.

80
00:06:14,040 --> 00:06:21,960
So it's not all like pushed over, it's actually aligned pretty nice, and you notice now this nine

81
00:06:21,960 --> 00:06:29,040
here is aligned with this two on the 12 and then at the 12 wasn't like pushed over like this and affecting

82
00:06:29,040 --> 00:06:31,170
all the rest of the output on the row.

83
00:06:33,020 --> 00:06:37,280
So let's go ahead and run this again now, though, and I'm going to put something that will cause us

84
00:06:37,280 --> 00:06:41,690
to get into three digit numbers, so hundreds, right?

85
00:06:42,170 --> 00:06:45,770
So let me do something like 12 a table of size 12.

86
00:06:47,090 --> 00:06:54,830
So you notice that there still is a little bit of an issue here like this is not formatted so nicely,

87
00:06:54,830 --> 00:06:55,970
this stuff right here.

88
00:06:56,270 --> 00:07:02,570
And that's because we just set the width for an expected consumption of two characters two spaces.

89
00:07:03,350 --> 00:07:06,650
But now, since we're dealing with three digit numbers, we're going to have to up that.

90
00:07:07,730 --> 00:07:10,070
So if I change this to three and save it.

91
00:07:11,480 --> 00:07:15,200
And then I compile it, and then I read it again.

92
00:07:16,570 --> 00:07:23,800
And I'm going to put 12 now you notice that it looks pretty nice, so I'm going to go ahead and scroll

93
00:07:23,800 --> 00:07:25,390
up a bit so we can see this.

94
00:07:26,350 --> 00:07:30,020
So now you notice everything is looking pretty good.

95
00:07:30,040 --> 00:07:31,780
You notice they added some extra space here.

96
00:07:31,790 --> 00:07:35,740
That is because we're expecting a minimum consumption of three character spaces.

97
00:07:36,160 --> 00:07:37,720
So when?

98
00:07:38,680 --> 00:07:44,290
When we have, you know, this is basically pushed over three spaces, then from here we have three

99
00:07:44,290 --> 00:07:45,070
spaces.

100
00:07:45,490 --> 00:07:49,090
So that's why you're seeing some additional space between these beginning columns.

101
00:07:50,040 --> 00:07:58,410
But what it does is it makes it possible for us to still align a three digit number with just a single

102
00:07:58,410 --> 00:07:59,790
digit number here as well.

103
00:08:00,890 --> 00:08:02,390
So it looks nice and clean.

104
00:08:02,780 --> 00:08:08,750
And of course, if you got into the the numbers in the thousands, you would want to set this to four.

105
00:08:09,380 --> 00:08:15,140
And right now, I just have a single space separating these numbers, but you can kind of modify that

106
00:08:15,140 --> 00:08:16,600
to look however you'd like.

107
00:08:16,610 --> 00:08:17,960
I think this looks clean, though.

108
00:08:19,700 --> 00:08:21,990
All right, so a pretty short lecture.

109
00:08:22,010 --> 00:08:24,650
That's all I was going to go over today.

110
00:08:24,920 --> 00:08:33,410
This is actually one of multiple things that can be used from this i o minute right here.

111
00:08:35,480 --> 00:08:42,260
But I'm not going to go into other stuff, I just want you to know how to use, said W. or set with

112
00:08:42,260 --> 00:08:47,300
so you can use it for the upcoming project, which we are about to get into.

113
00:08:47,300 --> 00:08:50,710
Now that is going to be our Tic-Tac-Toe game.

114
00:08:50,720 --> 00:08:54,770
You're going to need to output a variable size Tic TAC toe board.

115
00:08:55,940 --> 00:09:00,950
And you're going to want to know how to make it look nice and clean for the output, so this is something

116
00:09:00,950 --> 00:09:03,710
that you're probably going to end up needing to use.

117
00:09:04,810 --> 00:09:08,980
So with that, I will go ahead and see you in the next lecture.
