In this section we'll be talking about new ways to represent our data by creating our own user defined
types.
We'll leave this off by talking about structures.
Structures are a way of combining multiple different types into one bigger type.
So for example there's no built in book type for C++ but we can make it ourselves and here's how you
do that.
So we say structure which is short for structure and key word.
OK.
And we say the name of our type is going to call a book type and noticed that we have the Brace's here
statement.
We're put a few more some statements inside of each statement block.
And these statements will be the sort of definition of what our book type is composed of OK.
So for example we could have a book ID which is it.
It has a string which is the title of the book.
This is the author
and maybe the year it was published in Libya as well.
So inside this block redeclare all the inner types that make up our structure.
And so that's what that's what these five variables are.
OK.
So each of these variables inside belong to this structure.
In other words and this is really just a way of grouping variables together into our own type.
And remember that this is this is only the declaration of our type and defined by these five.
This case five variables.
But this isn't the this isn't a variable itself.
This whole thing is not a variable it's the declaration type.
So if you want to actually make a variable Here's how you do it.
So this book type like this and we give it in the book say Okay.
So just like we had with like an integer you say book type type and then book as very well me.
OK.
So you can actually access all these members right.
Since we we know we have five member variables of this book.
OK.
So how you access them is through the dot operator.
So you've actually seen it before with seat in but it's not exactly the same thing.
In this case.
So here you say a book in say want to access use e book ID.
So you say a book Dot and will even notice in eclipse that it brings up kind of the completions of what
the member variables are.
The author of book ID.
Oh year.
So let's say one book I read press Enter him and set the book at the king's house.
And we use a function for the
title and author here called Sturr copy which will copy a string into our Auray book title.
Know.
It's
so we're just putting this string literal into the title and copy all of it and even put the character
for a while and then stir up copy
offer
me 100 points you know is Dickins
year a million points you know.
Ouch.
You know nine in price say that's OK.
So the reason the dot operator each time to access the member variable of the book and so in this case
reading all five member variables and all you do is say your variable name that you came up with appear.
And then Dortch whatever.
So our book type really acts like any other type so we could even have you know an array of books and
we want to
Pook's this array of 10 books and actually define them all if you want like books Sphero dot you know
Id
right.
So you could just kind of continue on like that.
So it works just like any other variable.
Or And again structures are a very important feature that help us with our design.
OK.
With our design of our data in fact just like we use functions to design or code we use structures to
design our data.
So often we need to define data in terms of the problem itself.
So for example if we had a library we need books or a in searchers really do help great.
Yes I hope you remember the picture that I showed at the start of the course where we had the transforming
input and output.
This is my mental model of programming while we've been focusing mostly on the kind of transform part
of the algorithm.
Part of it.
Now in this section we'll be really focusing on the input data.
Then we'll talk more about structures and how they can interact with functions in the next lecture.