WEBVTT

00:00.840 --> 00:09.680
Stew's practice now you see problems is create a function that takes two vectors and returns that dot

00:09.680 --> 00:10.510
product.

00:10.520 --> 00:23.130
The two vectors two vectors must be the same size so it's no such thing as a vector space but we can

00:23.130 --> 00:25.320
use an array.

00:25.320 --> 00:32.610
So let's say we had an array of say

00:35.690 --> 00:38.150
1 in 3

00:40.810 --> 00:42.280
4 7

00:44.340 --> 00:52.520
scene Victor 2 it's also 3.

00:53.150 --> 01:07.940
To say these are two three dimensional vectors K in let's write a function or actually you saw double

01:10.820 --> 01:11.470
doubles

01:14.650 --> 01:19.740
and rate a function called the product.

01:22.230 --> 01:31.860
And this takes in two arrays and they're going be constant because we're only going to read from a vector.

01:31.860 --> 01:36.170
We're not going to actually change that that way.

01:38.020 --> 01:48.240
Of all cause factor one or two and the lengths of the vector

01:54.240 --> 01:59.790
scope that it does here implement.

02:01.310 --> 02:08.120
So what is the dot product of two vectors as well as just each of their components multiplied together

02:08.960 --> 02:10.540
and then added.

02:10.640 --> 02:18.910
So it would be one times two plus four times five plus seven times eight.

02:19.780 --> 02:30.490
So one product is 0 and then Absolute through the array.

02:30.940 --> 02:31.920
This link

02:34.610 --> 02:41.790
boss knows we need the link here of course because otherwise we don't know how many how many elements

02:41.790 --> 02:43.800
each vector has.

02:44.150 --> 02:50.100
It was a product plus equals vector.

02:50.240 --> 02:55.920
One of times the keys at the end there.

02:55.990 --> 02:57.860
It's wrong vector to

03:02.130 --> 03:05.250
return the product.

03:05.590 --> 03:09.330
So use this say that dot product

03:12.630 --> 03:14.850
or let's see how it's

03:18.410 --> 03:20.540
dot product.

03:24.300 --> 03:27.320
Jer. 1.

03:29.430 --> 03:31.220
2 is

03:35.760 --> 03:45.130
her one vector to in the link is 3 right.

03:45.260 --> 03:56.270
It's from this see.

03:56.420 --> 04:01.160
So the dot product of vector one vector 2 is 78.

04:02.610 --> 04:05.530
It seems to make sense to you.

04:05.530 --> 04:10.190
Plus when he was

04:12.660 --> 04:14.060
sometimes h

04:17.700 --> 04:18.810
sometimes eight

04:21.520 --> 04:25.450
us to was 20 year.

04:25.690 --> 04:27.410
It's not OK

04:30.010 --> 04:31.970
so that's the first one.

04:34.500 --> 04:47.270
Suze says it's a make a function call get character that will take in a C string prompt and the string

04:47.390 --> 04:51.630
and return a character from standard in and from the user.

04:51.860 --> 04:59.120
So this is going to build on our input examples that we've been kind of going through throughout the

04:59.120 --> 05:11.470
course if the user types something incorrectly or doesn't match our inputs the function should recover

05:11.470 --> 05:17.990
from failure gracefully and output the error C string and promp easier to try again.

05:18.020 --> 05:29.130
Ok so its main function returns a character get character

05:33.000 --> 05:33.770
in.

05:33.810 --> 05:36.900
This will be the ROM.

05:38.850 --> 05:42.870
It's char.

05:43.410 --> 05:48.630
This and the error string

05:52.780 --> 05:53.350
here

05:57.030 --> 06:02.420
that's.

06:02.610 --> 06:05.550
So most of this should be very familiar.

06:05.550 --> 06:10.630
So we need the input and can reuse that failure.

06:12.200 --> 06:19.060
And we use do while loop as we want to be able to do more than one time failure.

06:20.490 --> 06:21.150
Right.

06:21.440 --> 06:24.980
And we want to do it more than one time because they could input something correctly.

06:25.770 --> 06:29.820
So failure to all false

06:34.660 --> 06:40.270
in will output the prompt Changs.

06:40.300 --> 06:45.630
So this is from the is one of the arguments which is output the prompt.

06:45.670 --> 06:55.990
You don't know where it is in its input to get the input and then just like before we check to see if

06:56.620 --> 07:00.360
fail the you know that's

07:04.470 --> 07:06.860
a case in this one.

07:07.050 --> 07:11.140
And for this we have to clear the flag.

07:12.900 --> 07:18.820
And ignore that we actually need constants.

07:18.820 --> 07:20.700
And in fact I put it up here.

07:23.260 --> 07:33.000
Inch or Shahr is more 256.

07:33.320 --> 07:34.930
Again that's very arbitrary.

07:37.860 --> 07:38.550
Nor

07:43.560 --> 07:48.910
for sure is up until the newline right.

07:51.150 --> 07:59.080
It's all old stuff and we should output the error rate here.

07:59.580 --> 08:06.970
Either will input the air or the programmer will set the air for this function right.

08:07.980 --> 08:11.990
And failure is true in this case.

08:13.360 --> 08:14.460
Otherwise.

08:14.470 --> 08:28.470
So what we want to do is to actually ignore any characters after this or this is the case where it worked.

08:32.160 --> 08:33.180
Or there was no air

08:35.840 --> 08:46.160
and I'm going to do something a little bit new and say If so what I want to say is like if it's a character

08:46.300 --> 08:53.110
write it not like an integer or say or something like this double.

08:53.120 --> 08:54.800
So if it's character

08:57.690 --> 09:01.840
hey put it it's these

09:05.210 --> 09:07.820
I don't know how to do that yet but I'll show you in a second.

09:07.980 --> 09:14.280
I want to do have it in lower case inputs.

09:14.440 --> 09:26.410
So we need the CC type you remember colludes type so that actually has a function that will lower case

09:26.410 --> 09:33.600
the inputs to lower this input.

09:36.780 --> 09:38.640
This is exactly what we did before.

09:38.650 --> 09:48.070
So we shouldn't be any difference and we're going to output the error if it wasn't a character so it

09:48.100 --> 09:56.780
wasn't a character and go here and we're going to output the air again at and say that that was a failure.

10:01.660 --> 10:06.210
And you can actually check to see if it's character using CC type.

10:06.220 --> 10:08.600
In fact it's called is alpha

10:12.710 --> 10:15.970
and then don't actually say whether or not it was a character

10:20.090 --> 10:22.400
or its return.

10:23.630 --> 10:33.120
This and so try is once you read this

10:37.620 --> 10:45.200
and try to get a character so will say Shaar input.

10:46.740 --> 10:55.170
Goulds to get this character and the whole point of this was to pass in the prompt itself.

10:55.170 --> 11:02.090
So say please enter character that is.

11:02.130 --> 11:05.380
And also the air string.

11:05.380 --> 11:06.000
So

11:09.310 --> 11:12.460
input error.

11:12.660 --> 11:15.030
Please try again.

11:17.810 --> 11:20.500
And then we'll just output the character itself.

11:24.930 --> 11:26.540
There Jerry

11:29.270 --> 11:30.610
put these

11:33.280 --> 11:33.850
this

11:38.370 --> 11:41.540
are on that piece and put it character into one.

11:42.060 --> 11:53.110
So see how this was an input error because that's not an alphanumeric character or alpha character.

11:54.070 --> 11:56.030
It's not part of the alphabet.

11:56.290 --> 11:58.200
Is is alphabet.

11:58.200 --> 11:59.230
Right.

11:59.330 --> 12:06.210
So if you see Affe characters Frank So that's working pretty well.

12:07.280 --> 12:14.030
So there's actually another part this says create a new function that is called character that will

12:14.030 --> 12:23.820
also take in valid inputs that the user can type in and how many there are.

12:24.060 --> 12:30.600
So the functions should only allow those inputs by the user and give an error if the user didn't input

12:30.720 --> 12:32.230
it correctly.

12:32.760 --> 12:42.210
So to do this we're actually going to use an array so and also take advantage of

12:46.230 --> 12:48.940
functions that have the same name.

12:50.500 --> 12:52.470
It's function overloading.

12:52.760 --> 13:02.570
So we're going to still have the same thing so as to be prompt this and conc our star error but it's

13:02.570 --> 13:16.590
also going to have extra things called Call it counts Chaar valid input and that's going to be an array.

13:16.590 --> 13:23.420
And so we're going to actually input all the valid characters that you're allowed to type in here.

13:23.870 --> 13:31.720
And let's say it's valid and what it's like.

13:33.470 --> 13:38.200
So we need to have the length of the array right.

13:38.240 --> 13:40.460
This isn't a C string.

13:40.580 --> 13:44.810
These are actually just caret is just a character array

13:48.410 --> 13:56.260
that and for the most part it's going to be quite similar to this one above.

13:56.260 --> 13:58.120
So we're going to copy all of this

14:01.110 --> 14:06.280
and rewrite it.

14:06.430 --> 14:10.490
And the difference will be here.

14:11.970 --> 14:23.920
So after this we're going to lowercase it and then we're going to check all of our valid inputs here.

14:23.980 --> 14:26.370
So a valid input.

14:27.360 --> 14:42.340
Link loss and we're going to see if the input that we got is one of those allowable inputs like this.

14:42.430 --> 14:49.740
And if it is we're just going to return the input and that's it.

14:50.320 --> 15:00.380
So we are going to try this again but we're going to have some character so let's say we had.

15:00.850 --> 15:07.360
And you'll see in a really quick second why why we're writing this function at all.

15:07.360 --> 15:17.400
So character say valid inputs are let's say yes and no

15:20.140 --> 15:26.130
care if you see where we're going with this.

15:26.160 --> 15:27.250
These enter.

15:27.310 --> 15:31.360
So let's say for the prompt it should be.

15:31.480 --> 15:35.400
For example would you like to play.

15:37.930 --> 15:40.800
Why is slash and tear.

15:41.280 --> 15:48.060
And then here we're going to say valid inputs and there's only two of them.

15:50.950 --> 15:51.880
Right.

15:52.170 --> 15:53.490
In order on this

15:58.450 --> 15:59.640
spelt was incorrectly

16:06.750 --> 16:08.000
put this

16:11.310 --> 16:12.100
time.

16:12.420 --> 16:13.010
OK.

16:13.380 --> 16:14.990
Would you like to play again.

16:15.000 --> 16:22.290
So if I remember back before we could like say q and you'd still say no.

16:22.290 --> 16:22.830
Right.

16:42.950 --> 16:45.130
So we don't want this action.

16:47.950 --> 16:53.390
Because otherwise it would have it would have done this.

16:53.410 --> 16:56.380
But then kind of.

16:56.500 --> 17:04.320
So the reason why that didn't work is because it was an actual alphanumeric character and it did this

17:04.330 --> 17:05.120
but it didn't.

17:05.410 --> 17:08.260
It didn't return true here.

17:08.260 --> 17:09.380
Right.

17:10.510 --> 17:12.940
But it didn't go to this case that we wanted it to.

17:12.940 --> 17:19.060
So we actually remove the else case so and we can do that because we're actually just returning right

17:19.060 --> 17:21.340
here instead.

17:21.340 --> 17:23.730
So let's try this again.

17:23.760 --> 17:27.600
So it's a Q That's an input error.

17:27.970 --> 17:30.230
You mean put there.

17:30.280 --> 17:36.490
No your character was and you're doing this again and.

17:36.510 --> 17:38.180
Yes.

17:38.170 --> 17:38.860
Right.

17:38.960 --> 17:41.310
This is working this way.

17:42.450 --> 17:48.410
So you see why we're writing this function.

17:48.490 --> 17:56.650
This is going to be a pretty important function for not only the next project we're going to do the

17:56.650 --> 17:58.300
one after that as well.

17:58.630 --> 18:01.000
So I'll see you in the next section.
