GAME151 Live Coding #1 (Humber Game Programming)

GAME151 Live Coding #1 (Humber Game Programming)


Hey there,
this is Jeff, and I’m going to
be diving into doing a little bit of
live coding here in order to get you
started on assignment one. So, this assignment is mostly
about being able to print out a table, either to the console
or to Excel. I’ll show you a little bit
of both of those things as we get a little bit
further in here. That will show
the position, velocity, acceleration, applied force,
and the time for a jetski as we sort of
move through this simulation. So as you recall,
the simulation goes that, at the beginning,
500 newtons is applied to the jetski up
until 5.5 seconds when the engine shuts off,
no force is applied. And then at 10 seconds,
a force of negative 625 newtons
is applied until the jetski
comes to a stop. So, I’m not going
to go through all the details
of this here, but I’m going to
go far enough that hopefully you have
all the things set up. And then by the time we come
around to our class in week two,
we can start really talking about
the details. So, I’m going to dive in
and make a new project here. So, I’m just going to create
a Win32 console application. I’ve already made
a folder for this. So, this is just going to go
in my Jeff’s A1 Demo Folder. It’s good if you name
your project something… that I can
easily identify. Just going to
go with that. So this is going to
pop this wizard up. I mean if you’re
unfamiliar, it’s going to ask you a
bunch of stuff. So you want a
console application. That’s generally the
only important thing. I’m going to shut these off
because I don’t need them. If you leave them in,
it won’t really make any difference,
it will still work. And I hit finish and I’ll
have a project come together. All right,
for simplicity sake, I’m going to do a little bit
of organization here. Because there’s
a couple of files that I just
simply don’t need. So this stdafx.h
and .cpp, both of these files are
completely unimportant. They’re useful in
larger projects, but for now they’re just
kind of getting in the way. This targetver.h
also totally unnecessary and readme.txt also
totally unnecessary. So I’m just going to
select all of those, right click,
remove. And I’ll delete the files
from my desk as well. Totally unnecessary. We’re not going to have
any resource files, so we need to get
rid of this folder. And, so we’re left with
only one file here. So that was this
Jeff Rose Assignment1.cpp that I have here. And I’m going to
re-name this file to be called
main.cpp. I usually
do this because that’s typically
like in C++, that’s kind of
usually what you end up with
as your main file. It also includes
your main function, which is the entry point
of your program. And I like to
call it main.cpp, so that I can
find it easily later. That’s mostly what
this amounts to. That’s the
important bit for me. You’ll see now
in this file I have a little red squiggly
under include stdafx.h. Of course this is because
I deleted that file. But I don’t need it,
so I’m just going to delete this stuff out. So, I’m right down
to a blank slate. Literally the only thing
that my program does is start and exit, with an exit
code of zero, which tells the operating
system nothing went wrong. That’s it,
that’s all it does. So, usually just
a little sanity check that I like to do
here is just to do some basic stuff just to
print hello world out, so that I know for sure
that everything is cool. So, because many of
you are new to C++, there’s going to be
a couple of includes that I use here
that you won’t be that familiar
with maybe. But you will get more
used to dealing with these as time goes on. So, iostream is a library
of functions and objects that relate to streams
of various sorts. This includes streams
for opening, and reading,
and writing files. Reading from the console,
writing to the console, there’s a lot of stuff
that’s in there. So, I’m going to bring
that on and we’ll see some usage of that
in a moment. And I’m also going
to bring one string. It may come as a surprise
to some of you who are used
to languages where strings are
sort of default objects. In C and C++
they are not. All you have to do is
include string here to get access to them,
but they aren’t primitives like a lot of
other languages. That’s a thing. So, for your basic
hello world, there is a pretty
straightforward thing to do. And we’re going to make
a little bit of use of both iostream
and string here. In order to print to
the console using iostream, I’m going to
use this std. So, this is the standard
library’s namespace, this std double
colon cout. This double colon is
what we refer to as the namespace
resolution operator. So what we’re doing
here is we’re saying, get me cout that exists
within the namespace std. How do you know
to do that? Read the
documentation. That’s kind of the best
answer that I can give. C++ is somewhat unforgiving
and it really just takes some time to learn
some of this stuff. But, cout has
a handy operator that we can use,
this double arrow thing. And I can just
say hello world. And I don’t know… Let’s give that a try,
or actually… Let’s run this
and see what happens. Boom! Okay, so it
ran and it closed. And that was
very fast and I didn’t even see
what happened. So, this is the thing
that I expected, and that’s cool. What’s happening
here is that because this
instruction is running and then this thing is
telling the program to exit, the window pops open
for a second, not even long enough
for us to read anything, and then it
just disappears. So, we’re probably
most of the time when we’re writing
a console application, we’re going to want
some way to stop it from just closing
instantly. And sort of a cheap
and dirty way that I do that usually is using
the getchar function. So, this is tell the program
to wait for a keypress. So, basically
this is like the press any key
to continue thing. We’re not going to
use the character that it takes from
the keyboard for anything. We just want it to wait until
something gets pressed, and then the program
will exit immediately. So let’s see what
that changes here. All right, cool. So we get
Hello World! And I’m just going to
press, say space bar. Whoa, it didn’t
do anything. Okay, so I
hit enter. All right, so it’s not exactly
as I imagined originally, but okay, so cool,
so you can just hit enter and close
the program. No big deal. Good, so we have
something to work with. All right,
so now that we’ve proved that we have
a program that works and it doesn’t just
completely like crash and burn. This is probably a good point
to start actually thinking about the problem that we’re
trying to solve here. So, if you recall
from the assignment sheet, which I suppose
I can open up here. So, in this assignment
sheet it’s mentioned that you’re going to be
building a vector class, and a body class. So you have this
gdVec2 and gdBody. These are both things that
are going to show up in here. While they’re not
written this way here, I’m going to
suggest actually that we sort of
think this through, working our way deeper and
deeper through the problem, starting from body and then
working our way to vec2. So, what we want to do is
be able to simulate this jetski moving
through the world. We want to know
its position, its velocity, its acceleration,
and its mass. Those are big
things that we need to pay
attention to here. But that’s not unique
to jetskis, right? The reason we’re talking
about having a body, is that in physics
we refer to objects that have mass
and that have a position in the world,
as bodies. So, you know you’ll see
the planetary bodies, for example, are one thing we
refer to in that way. So, what I’m going to do,
since we know that we have a jetski,
and a jetski is a body. We’re going to be thinking
about the jetski as a body. So, I’m going to start off
working in the body here by just adding
a new item. Or actually I can just
add a class or you can use SHIFT + ALT + C,
I suppose if you like. But I’m going to just
right click on the project and go to add class. Should give me
a wizard here, so, all right,
I’m going to add a C++ class, and I
want to call it gdBody. Don’t have to do anything
else special here, and just tell
it finish. So, now if you
look over in this solution
explorer here, you’ll notice that there are,
in fact, two files called… Seriously? Okay, I misnamed it. My bad.
Give me one sec. I will just
delete those and go
add class again and let’s try
to spell it correctly the
first time. gdBody,
all right, finish. All right, okay,
so back to where we were. So we have
two files here. So, what’s up
with that? I’m sure that this will get
brought up in your C++ class. But in C++,
classes are a little more complicated than,
for example, in C#. In C# you have one class
that defines, declares and defines
all of the functions that belong
to an object. It serves the purpose of
not only declaring the interface that parts
of your program need to adhere to,
to be able to call functions and
use members of your object. But it also does the work
of actually defining each and every one of those
functions and how they work. In C++,
that is generally not how you do things,
although you can. And for reasons going
beyond today’s little live coding thing here,
it can be a bad idea to roll the two of
them into one file. Even though
it is possible. So I’m going to stick
with keeping both of these things separate
here for now and we’ll sort of
work with that. Before I move too far
into functions, we had mentioned the things
that a body has. We know that
a body has a mass. I’m going to call it a double,
this could be a float. A lot of the time
in game development we use floats
instead of doubles. But it’s not super
important for the sake of this
which we pick. I’m going to go with
a double for mass, so we have some floating
point value for mass, which we will assume
is in kilograms. And then we need
some way to keep track of
an acceleration. So we got some acceleration,
velocity, and position. Now, both all three
of these things, are things that are
multi-dimensional, right? If we’re talking about
something’s position x, y, we need an
object that keeps track of both of those
things separately. And that’s exactly
where this gdVec2 comes into the mix. So, we’re going to define
these in a moment once we get a class
in place for that. So I’m just going
to go ahead and add the
second class. So I’m going to
add gdVec2. All right,
so we have a gdVec2. I’m not going to go into
too much detail at this point about the individual
functions that go in here. Our next live coding
session like in class we’ll probably cover
more of that. But the important thing
that a vec2 has, if I could just spell is that it has
a value for x, and it has
a value for y. That’s kind of the
important stuff. So, these are the
big things that we need to be concerned
about here. And that’s as far as
I’m going to go with that for the time being. But that’s enough
to work with for now. I’m just going
to save this file. I’ll explain a little
bit more about the cpp files
in a moment. For now I’m mostly going
to be working in .h files. We’ll talk about .cpp
files when we get there. All right, so how do I use
this gdVec2 inside gdBody? If I just type
gdVec2 acceleration, it gives me
problems. Oh, maybe I should
spell it correctly. gdVec2. All right, well, despite
that I now spell it correctly, it still doesn’t know
what I mean. So, what’s up? This is a fairly
simple one to deal with. We need to… Remember these? These things in the weird
triangle brackets, these are things that belong
to the standard library. But this include statement
that I have here is something that
I’m going to use again. So, in here I
want an include and I’m going to
use double quotes here, and you’ll see visual
studios is kind enough, seeing as I got
the syntax right to let me know what files I
could potentially include. And unsurprisingly,
it shows me the body that
I have within here and vec2 that
I’ve put in here. You’ll note that only
the .h files show up. This is usually the
convention that we follow, where we include things
by their .h file because the
.h file describes the interface
to that object. And as time goes on
we’ll maybe talk a little bit more
about what that means. And I’m sure it will
come up in your C++ class. But for now,
we have included gdVec2.h
and look at that, so, no more red
squiggly mess. So, I’m just going
to expand this out. So, I’m going to
have a velocity and I’m going to
have a position. And all of those things
are vector twos. Great, so,
we have the basics. We have at least
the data that we need to
hold onto here even if we don’t
have much of what these objects require
in terms of functions. But that’s
a good start. So, I’m just going to
save all of my files. Okay, everything
is saved. And I’m going to jump
back to the main here just to kind of take
stock of where we’re at. And think a
little bit about what we want to
do in the end. Because ultimately,
we want to be able to print out table rows that look
a little bit like this, right? We want the time,
force, acceleration, velocity, position,
running across. And we would like to be able
to see that on the console, and preferably also
dump it to a file. Because when it’s
in a file it’s actually really easy to
bring it into excel, so that you can
make these charts. Prove to yourself that
everything’s working the way that it should. So, certainly doesn’t
hurt to think a little bit about starting
from the basics. Let’s just
see if we can make a vector
and print a vector. So, it shouldn’t
surprise anybody that if I want
to use gdVec2 in my main file, then I’m going to
have to include it, just like I did
in my main body. So, cool. I got gdVec2.h
in here and then that gives me
the ability to say… Let’s make a gdVec2 and we’ll call it
force, let’s say. I have that
gdVec2.force and well,
for the sake of it, let’s set its
x to 500 and its y to zero
just like we had at the start of
the problem there. Whether it stays written
like this or not, that’ll be up to
you in your own sort of personal
choices in style. Let’s go with this
and just try and print this out
and see what it looks like. Unfortunately,
printing it we’re going to have to sort of
format the printing of its
x and y values kind of separately
so that everything comes out the way
that we want, but it’s doable. So, I’m just going
to piece together a couple of bits here. So, the nice thing about
cout is that you can actually use it to string together a
whole bunch of different values. And just use those double
triangle brackets to concatenate everything
together and give you
an end result here. Yeah, sure, let’s
just do this for now. So we’ll print the force
x and the force y. I think I’m going to
leave out the y values for sort of
my last idea of this because y values aren’t really
needed for anything anywhere. And I should
note that there is
standard end line is what this means. So, this is for those of
you who are familiar with the backslash n is
a new line character. So you can say
backslash n here and it would basically
mean the same thing. But this constant
is kind of useful so that you don’t
have to remember. And also it works on both
Windows, and Linux, and Mac machines without
doing any weirdness. Some of you may be
familiar with the fact that new line
characters on Windows and Linux boxes are
a little bit different. All right, let’s
give this a shot. We have our little
program, cool. So, we got this thing
printing out in brackets. 500 comma zero. So, that’s all the
cout line consists of. So, this is
my first bracket, x value separated
by a comma, y value close, closed with
another parenthesis. So, all right,
we have the basic idea of printing out
a force. Now, we want to be
able to print out a lot more
than that, right? We want to be able
to print out table lines that are quite a bit
more here than what this is. So, let’s then go to the
next step of complexity. Because many of the things
in here that we want to print out are things that
belong to a body, right? So, let’s get
a body involved here. I’m going to
include that. And so I’m
also going to make an object. Let’s call
it jetski, so you got
gdBody jetski. And I’m going to start off
just setting its values. Eventually once we get
to building functions for these things,
these will have constructors where we can
sort of initialize these
values immediately. But for now I think that
it’s good just to be able to sort of work
with this and directly kind of play with
the values that we have here. So, mass of 200… So, we’ve got… Oh, jeez, yeah,
I guess this is going to turn into quite
a few things here. So, let’s just set a
bunch of stuff to zero. Maybe this is a good time
to do this jetski constructor. In fact, let’s just go
and do that right now, so that we don’t get
too out of joint. So, I just deleted
this squiggle gdBody. For those of you unfamiliar,
this a destructor. This is what gets called
when the object is going to be deleted
from memory. You’ll probably talk
about this more in your C++ class,
but you will eventually need to know your way
around how to use these, so that you don’t
end up leaking memory. For now, we won’t
really deal with that. Let’s just
keep it simple and focus on
taking in what we need to
take in here. So, I’m just going to
make a constructor that takes in
a mass for now. Okay, so, whoa, what’s the
deal with all of this? It’s giving me
all this trouble. It’s okay,
it’s fairly simple. This is where that cpp
file comes in. So, it’s claiming when
I hover over gdBody, function definition
for gdBody not found. Well, what
does it mean? Definition
for gdBody. The cpp file is responsible
for the definitions of your functions. So, the .h, this is
a function declaration or a function
signature. I will use that word
function signature probably pretty often. This tells you how
you call this function and the cpp file
needs to reflect it in order to describe
what the function actually does. So, I’m just going
to update this to contain the same
variables here. Okay, so the cpp file is no
longer complaining, everything’s cool. And over on this side great,
no complaints anymore. So, important thing to
remember is that you need the function declaration
or the function signature to match the definition
on the cpp side. You will also
notice this gdBody scope resolution operator
in front here. If it’s missing this you
will have problems. I guarantee you that you will
run into that problem and you will wonder
what’s going on. All right, but let’s just get
into the meat of this. So, what do we want
a constructor to do? Usually just to
initialize values. In C++, values do not
initialize themselves. If you create a new object
you cannot count on any of your
object’s members being set to zero,
unless you do it yourself. Word of warning,
do it yourself. So, let’s do that. So we want to set the
mass is equal to newMass. And we have
an acceleration that we’re going to
want to initialize that. But… Oh, in fact,
that means that we need to take one more
step back here. We probably
want to look at the constructor
for our vector. And I’m just going
to do something very simple for
that right now. So, I don’t need
a destructor for this either, so I’m just going to
get rid of that. This gdVec2
constructor here I’m going to leave it
with no parameters and I’m just simply
going to say in it x equal zero
and y equal zero. So, all that’s
meaning is that when we create
a new vector object it will automatically
set x and y to zero so that we can count on
them being set to zero. Just by virtue of
these things existing, they will automatically
get set to zero. And mass being sort of
the odd one out, will get set to newMass
using this constructor. Okay, at this point
we should be able to just
say gdBody jetski and this is a
little bit unlike C#, so bear with me here. I’m going to
put a bracket here and I’m going
to say 200. What is going on there? So, unlike C#,
I am not using new to create
a new object here. I am in fact creating
a new object in place. When you talk
a little bit more about memory management
this will become clear. But basically
what this is doing is it’s creating a new
gdBody called jetski and using the
constructor and passing 200
as its mass here. So, that’s what’s
happening on this line. So, I’m creating
a body called jetski with a mass
of 200 kilograms. So, let’s go
a little bit further and see about
what we want to do to print out
a complete line… for our table. I’m going to
add one more thing that I probably want
to keep track of. And that’s that I’m going
to want our current time. Our simulation is going
to tick through time, so we’re going to want
some value for time. And we’re going to want
to be able print that out. So we have the time,
the force, and we got the body that we’re interested
in following here. These are the three parts
that we’re sort of most interested
in seeing here. So, if we want
this table to look anything like
what we have here, we probably
want to actually print out
the header. That’s boring
and it’s easy. I’m just going to try
and copy and paste this. This may not work
at all but let’s… Pretty well,
I guess. So, I’m just going
to start off separating these
things with commas. So, there are tabs
between them right now and that may
work out to be what we want in the end. But let’s just
take a look. Let’s reformat this
slightly to scrunch these things
down a tiny bit. Great,
position in meters. Okay, so, what I’m
going to do here is I’m just going to
say standard cout. Where did
my time go? Sure, fine,
do that. All right, dump all
those things out and then standard
end line. Because we want to
bump this down to the next line
after this, right? Okay, so, this is
our table header. We got that
printed out. So, let’s try
printing one line of the
values underneath. So we have time first,
then force, then acceleration,
velocity, position. Oh, I forgot a couple
of spaces here. Let’s put
those in there, looks a
little better. All right,
sure. Let’s break this
down just a tiny bit. Some of you will look
at this formatting and you’re
going to go, Jeff, you’re crazy.
What are you doing? I promise you
it looks pretty. Just bear with me
for a moment. We’re going to
go on a trip. I’m going to say print
out the current time and after the
current time, give me a comma, next line down. Then give me force.x and give me a comma. Now, I want
to be clear here that when
I’m doing this I don’t mean that
in my output, go to the
next line. I’m just doing
this so that it’s easy for me
to read it. This is only a technique
that I’m using in order to make my code
easy to understand. It doesn’t really reflect
what’s going to come out of
the program. As you’ll see
in a moment, we’ll get there. So, now we’ve
got the jetski. Whoops,
not the ketski, the jetski.acceleration.x. Now, I’m only
going to print out the x values for each
of these things here because the y values
stay at zero the whole time. There’s really no point
in printing those out for the sake
of this chart. So, I’m just going
to keep things simple. So, there we go. So, we got current time,
a comma, force x comma, jetski
acceleration x comma, jetski
velocity x comma, jetski position x, and we don’t need
a comma after this. We just need
the end of the line. That’s all we need. So, let’s see what
this prints out. What we should expect
here is that we’ll get a current time
of zero, the force should
print out as 500. But the position, velocity
or the acceleration, velocity and
position of our jetski should all be zero. So, let’s see what
this does for us. Hey! Not bad. All right, so,
looking at this you’re going to go,
well, how do I
even remember what line goes
with what thing? I totally understand
where you’re coming from. This is not a very
well formatted table. This is because
we haven’t done anything to try and line
these things up. All we did was put
commas between them and obliviously,
if my first line here is zero it’s not as long
in characters as time space
brackets seconds. And that’s not
going to line up. If you want to make this
a little bit prettier to be able
to look at, there’s a little
bit more work that we can do here to
make this turn out cleanly. Probably the simplest thing
that I can sort of recommend is that you jam tabs
into the middle here. So, okay, I want to be
totally clear here. So, what I’ve done here
is there is a comma and a space between
time and force here. I can insert a tab character
with backslash t. So, I’m putting
backslash t in here, backslash t,
backslash t, I’m just replacing each of
these sort of comma, spaces. And I’m going to do the
same thing down here. This isn’t going to
work out quite right, but it’s going
to be pretty close and it will be
easy to fix. So, having gone
through and replaced all of our comma
separations with tabs, let’s see what
that works out like. Okay,
it’s closer. It’s not all
the way there, but obviously
this line is not lined up yet. So, I’m just going to add
actually, a second tab there. You will find actually,
that all that’s going on here
is that each of these
statements is two tabs wide. That’s all
that’s breaking here. So, by inserting
two tabs here we should get enough space
to pan everything out. So, let’s see what
this turns into. Pretty sweet. All right, cool. So, now as these
print downward, as long as none
of these values come out being eight
characters or longer, everything is going to
work out nicely here. If you are
printing a table where that sort
of thing happens, you maybe have
a little bit more work
on your hands. But for the sake of printing
out values like this here, this will do for
what we’re doing today. So, that’s like
kind of the minimum that we can do
in terms of printing something
out to the console. What if we want to print
something out to a file? It shouldn’t surprise you
that that’s actually not that different. There’s a little bit
more work involved, but it’s really pretty
simple stuff. So, here I’m going to
do this very same thing, but instead I’m going to dump
these things out to a file. So, here what
we want is I’m going to reach
into my standard library and I’m going to
grab a new type of thing that you will not
have seen before. This OFstream, which stands
for outputFileStream, so that’s what I’m going
to call the variable just so that it’s not
confused at all. Why are
we complaining? That’s true. I do need to include something
new at the top here. I need to put
ofstream in up here. I have access to that. Oh, my mistake… fstream. Fstream includes both
ofstream and ifstream, which should
surprise no one, is to be input
file stream. So, okay, I have
my output file stream. So that is the statement
that tells it to exist. So, I’m going to
use it and I’m going to
call it openMethod. And I’m going to tell
it that I want to dump these things
out into a file that I call
table.csv. You can call
it whatever. We’re going to talk
a little bit about what csv’s mean
and how they will be helpful to you especially
in this course in a moment,
but we will get there. And when you open a file,
it’s usually a pretty good idea
to just write in the statement that closes
the file immediately. So, I’m just going to space
this out a little bit and I’m going
to say .close. If for any reason
I forget to close the file, the file that
was being opened here will be locked
in your OS until you reboot or at least
run the program again. So, be cautious of that. This kind of thing
can often prevent you from deleting files
and folders or moving files. You definitely encountered
this before on your computer and now you know
why it happens. Most of the time
that sort of thing is because a program exited
before closing a file. So make sure to
close your file up. Okay, so we have
this file open and we’ve got a statement
to close it. But what do we
do to actually put things out
into the file? Well, you know how this
standard cout has this arrow syntax where
we’re just taking these strings and dumping
them out to standard out? Well, it should
please you to know that
I can in fact do exactly the
same thing here, except instead of
calling standard cout I can use just
my ouputFileStream. And I can grab
this block here for writing the
second line out. I’m just going to
bring these things together a little bit,
and I’ll copy that in here, and I’ll just change
standard cout to be
outputFileStream. So, now we’ve
got this block… which is the
table header and one line
to the console, and this one
to an output file. Let’s just put
another comment here open an output file. And we’ll just say
close the output file. Might as well comment
our stuff so that we know basically
what’s going on in here. So, if I run this,
you’re going to say, well,
what changed? Everything looks
the same. And you
would be right. Nothing really
changed here. If we want to actually see
what happened here, we need to
go look at the folder that
we’re working in here. So, I just have
this on my desktop
under Jeff’s A1 Demo. So you want to go look
in the project folder that you’ve
set up in C++. So, for me
that’s here, this Jeff’s A1 Demo,
Jeff_Rose_Assignment1, Jeff_Rose_Assignment1 and sure
enough I can find table.csv. So, this is
the same folder that all of my
source files are in. So, my main.cpp,
my gdVec2, my gdBody, all those things
are in there. My table appears
there with them. So, I’m going to
open this file up and you’re probably
going to look at it and go that’s a mess. And I’ll tell you
a little bit of why. So, let’s see once this
thing opens up. Come on, Excel,
it’s a 1k file. Can’t be
too much of a chore. Seriously? Come on,
let’s do this. All right, well,
while I’m waiting, I will talk about
this a little bit. So, note that this file
that I’ve created is called table.csv. So, .csv is a
very old file format and it stands for
comma separated value. So, what I printed out here,
while it has all those nice tabs in it,
it is kind of a jumbled mess in here. While those tabs
that we put in are really great
for being able to see what happens
on the console. And let’s run that. So, those tabs are really nice
for spacing things out to present things
on the console, but they really
don’t do much for us if we actually want
to print these things in a file
in a useful way. If I had put those
comma separated… if I had put commas
between each of these values you would get
zero here then 500, then zero,
then zero, then zero. And all of these things
would be spaced out nicely, separated individually
into their cells. And then if you want to go
about graphing these things it would be a breeze
because everything is already broken up
nicely for you. So, let’s do that. So, now this is probably
a pretty good time to start thinking
about organizing your code
a little bit. Yes, you can,
you may find that you want to
make a function to do some of
these things. I’m just going to kind
of do them in place, but ideally I would
suggest making a function that will output
a line for you. Like one line to the file
where you can tell it what you want to jam
in here as the separater. But anyway,
for the time being, let’s just put
these commas in here and we’ll see
what that changes. So, this is basically
taking us right back to how we had this
originally. So, it certainly goes to
show that one way of formatting for
a file is great, but presenting it
visually is pretty crap. So, you’re going to
find that sometimes those two different
circumstances don’t really work out to be
exactly the same. And this is
one of those cases. So, I’m just going to
run this program again after adding in
all those commas in. So, we get the same thing
that we always did here because we
still have tabs printing out
to the console. But now when
I open table.csv, low and behold,
everything is organized nicely and if I want to
I can just use Excel, tell it to widen
all those columns so that all the headers fit. And, awesome,
we’re looking good. So, that’s a pretty
good place to be in, in terms of
being able to sort of dump
data out. But, right now we don’t
have anything that works. It doesn’t do
very much yet. And that’s going to be
where our next sort of in class live coding
session comes in. This has been a good
primer on getting objects and sort of understanding
how to get at their data and how to use
them for things. But we’re going
to move in to how we build functions
for these things and particularly
the complicated subject of how to overload
operators, which is dangerous,
not dangerous, can be very confusing
if you abuse it. So, we’re going to discuss
that briefly next time around and we’re going to
talk a little bit about how you might
go about implementing some of the functions
that make up the body
and your vector, too. So for now
that’s probably a good point
to stop off at. I’ll see you in class
next Wednesday. See you later,
everybody.

Leave a Reply

Your email address will not be published. Required fields are marked *