Welcome back.
I've had people tell me,
"Programming looks so complicated.
It has all these weird symbols,
and weird names in, and...
I don't know where to start."
Well maybe we can simplify some things.
This video covers how to
organize a program in C or C++
I will also make some comments about comments.
Let's start off with the first lab assignment.
I have a printout of Paycheck.cpp
Let's see how the thing is organized.
Right at the top, I have a
comment block that has the title of 
the program. I am going to write here.
So this right here is just a block
that has a bunch of comments.
I have put in
the name of the program,
my name, the class,
the inputs for the program and outputs.
Pretty cool? 
C and C++ use #include statements 
to help the compiler
put the program together.
So right there's my
include statements. The next
thing I have is    int main
int main  goes all the way from
the open curly brace
all the way down
to a close curly brace.
So here's my open curly brace.
And right there's a close curly brace.
From there down
there to the bottom.
See that.  Isn't that cool?
The next thing I have,
I'm going to declare my variables.
So I declared
Hours, PayRate, RegularHours 
So, here's my variables.
OK, here are my variables.
Then I have input,
and I have process,
and output.
That's pretty simple.
Maybe this chart looks a little better.
At the top, I have my title bar
my include statements, 
then here's    int main
I'm listing my variables, then here's the
input, process, output,
and at the bottom
I have a return 0;
and a close curly brace.
Comments are written in a human language
to help you or the next person
better understand what the 
computer language is doing.
Put good comment in your code, even if you
think that no one else will ever see them.
There have been times I was deeply
involved in a project and
knew everything about the project, and I
didn't think I needed to comment my code
because I knew it so well.
Then I started a new project. 
And later returned to my first project.
I spent a extra amount of time 
trying to figure out what I
did in the first place.
So put in a comment even if you think
no one else will ever see them.
The C-style comments start slashed star   /*   
and end with star slash   */
So you can even start with a slash star  /*
put in several lines of comments
end with the star slash   */
C++ style comments start with slash slash //
and at the end of line
Most of the modern C compilers will
also take the C++ style comments.
So you can mix and 
match them in C++ and
most of the time you can do the
same thing in the C-language.
Here is a sample of the title block comment.
I have the name of the program,
version, the date, the name of the programmer,
the company or in this case is going to be
the class you're taking,
and the input and the output.
This will help the
next time you end up opening up a file.
You don't have to read the whole program
to find out what's going on. 
You can just see it right at 
the top of the program.
English essays either use a blank line
between paragraphs or indent each paragraph.
few spaces at the beginning. When you use 
several lines of code that are related to
each other to do a specific task,
put up blank line and a comment to
briefly describe the code.
You can also put comments on 
individual lines of code.
If you did anything that is 
kinda trickier might take some
extra time figuring out what it did,
make sure you put a comment on that line.
The include statement is used to merge
code from some other file into your
program as the program is being compiled.
Header files get their name because the
#include statement is placed at the
top of the program.
Although you might not believe it,
C and C++ make programming
easier by providing header files,
Here are a couple samples for
include files the C language uses.
#include 
That's for standard I/O
We also might have something like
#include 
We need that for things
like square root cosine
sin tangent, things like that.
In C++ Microsoft has this 
#include "stdafx.h"
in most of the programs.
So if you're not using Microsoft, don't
put it in other computer compilers.
C++ also uses things like 
#include 
We need that for
doing the input and output from a keyboard,
We also might have things like #include 
One thing you might notice is
look up at the C, it has   
but C++ just has 
C++ uses  then they do a few extra things 
then they go ahead and include  also.
Here's what happens to the difference
between using the quotes " " and angle brackets 
If the header file is located
in your project directory,
you use the quote.
If the header file is located
in the compiler's include directory 
then use angle brackets.
So normally you're going to be using
angle brackets unless you
create your own header files.
Microsoft put that "stdafx.h"
inside the project directory.
Well that's Microsoft.
Console applications,
using the keyboard and screen,
start off with some version of
int main.  The simplest one is just 
   int main ( )
and then start the program 
with the curly brace.
A little bit fancier version is 
    int main (int argc, char* argv[ } )
main open parentheses
And then start the program 
with the curly brace.
This is so that we can collect
information from
another program or from a command line
You really don't need those right now,
so you could just start off with
int main ( )
Microsoft version is a little weird.
It says  int _tmain(int argc, _TCHAR* argv[])
You know what they do?
They take that line
and then convert it right back
into a normal   int main
So if you want, you can just start
new programs with the normal   int main
Main is considered a function.
Functions can return data.
I have int main.  
At the bottom of my program I will
have a return statement with an integer.
For example,   return 0;
You could have some other 
value there to indicate
maybe there is a problem with the
program. So typically return 0;  
means everything worked out fine
and return 1;  or  return 2;
to indicate possibly some
type of error code.
If you don't want to return
an integer you can say 
   void main
Then down at the bottom you can still
have a return statement, but you cannot
return a value.
Here comes the part of the program where
I declare my variables and constants .
I start by putting down a data type 
and then a name and a semi-colon;
I can also initialize the
variable at the same time.
For example, here I say   
    int count = 20;
I can also declare a constant.
Constants, once declared cannot be changed
by the program when it's running.
Here I declared 
   const double TaxRate = 0.0875;
I also put a comment there to indicate
that the 0.085 is really 8.75% 
to make it easier for somebody 
to figure out what that is later.
Now want it inputt the data
that's going to be processed.
Here comes my prompt and my input.
It's really important that you put
a prompt. Iif you just start
and try to input from the keyboard, all
you're going to do is have a flashing
cursor on the screen and nobody
is going to know what to do.
So here's the prompt in C++.
I put hours worked colon space
and then my close quote.
I've put the space there so that the
input doesn't run right up 
next to the the prompt message.
After I put the prompt, then I
can read from the keyboard.
Very similar in the C language.
Instead of using  cout
I have to use   printf   I also have to use
those parentheses.
Now I need to process the data.
Here's where I take my input data,
do all my math computations,
on it or whatever I need to do.
At the end, I'm ready to do the output.
We'll output using C++.
I'll use the   cout   statement
with  <<
In C, I'll use   printf   with the
open parentheses ( and the close parentheses )
In a second example, I declare a
character array called   message[]
and I set it to say
"You passed the test"
In C++ I can say,
   cout << 
and then the name of the character array
and a semi-colon.
In the C-language, I'll say 
   printf
and then first thing I do is I have a
format string so it says
   "%s"
The "%s" says that
"I have a string following"
In C++ you have to do a few extra things
to identify how many digits you want
displayed after decimal place.
We will need to include iomanip
(that stands for I/O manipulation).
This example shows how to output
two-digits past the decimal place
using C++. I have to include iostream
just to use cout.
I also have to include iomanip
so I can define how many
digits past the decimal.
cout   has a setioflags for
ios::fixed
It also has a ios::showpoint
colon colon
And then I can say 
    cout << setprecision(2)
to identify two places past the decimal.
Then I have paycheck (which is a double)
and then
the double will have two places past the
decimal regardless of whether
I have something like 30 cents or 
no cents or whatever.
  endl 
is at the end of the line to move
the cursor to the next line on the screen.
Make sure you typed the
last character of   endl
a small-L not a one (1)
It stands for end-of-line not end-one.
The C language uses printf.
Also I have to make sure I include
   stdio.h
because I'm using printf or scanf.
So then it says
double paycheck = 183.75;
In the format string
percent means I want to 
format some data.
lf  stands for long float. Because I'm 
using a double but in front it I put a .2
saying I want
two places past the decimal. Backslash-n ( \n )
to move the cursor to the next line.
Make sure you put in a backslash-n ( \n )
and not forward slash-n ( /n ).
If you put a forward slash-n ( /n ),
/n is going to show up on the screen
instead of moving the cursor 
to the next line.
Well that's all for now and good luck
with your C or C++ program.
At least now you know how to
organizer and put it together.
Have fun. Programming is cool !
