Thursday, 3 November 2016

03 Intro Programming cycle

0:00
ok once you have understood what
0:03
algorithms that we start inviting a few
0:06
simple programs in the same programming
0:08
language before we begin will give a
0:13
brief introduction to the process of
0:15
programming when you're programming you
0:17
follow typically what is known as the

0:20
programming cycle and this contains
0:24
three parts one is the process where you
0:27
write the program or edit the program
0:31
and after you're done editing the
0:33
program you save it and then you compile
0:36
your program if you're compliation
0:38
succeeds you are ready to run the
0:39
program if you're compilation fails then
0:42
you return to the editing step and
0:45
correct the errors
0:46
ok and compile again once compilation
0:49
process succeeds then you can run the
0:51
program and check whether the output is
0:53
correct its output is correct your done
0:55
if not you go back to the adac process
0:58
ok so this is why it is known as the
1:00
edict compile and run cycle
1:03
ok so you edit the program first then
1:07
compile it if there are compilation
1:09
errors you go back and edit it again a
1:11
device you run the program when you run
1:15
the program if the logic is correct then
1:18
you're done if your logic is incorrect
1:21
then you go back and make changes to the
1:24
program complete it and run it again
1:26
ok so this is the process that we have
1:28
to follow in the brain VR program we
1:32
look at each of these steps one by one
1:34
in editing
1:37
it's typically done in what is known as
1:40
an editor now it is a program that lets
1:43
you create a text file make changes to
1:47
the text file and update that expand and
1:50
later save it so in order to create a
1:54
program pick a particular editor of your
1:57
choice if you're on the next I would
1:59
recommend a simple editor like g8 it if
2:02
you're on Windows there is a free editor
2:04
called notepad plus plus
2:08
be careful that this is not the usual
2:10
North bread that comes along with the
2:12
system
2:13
write your coordinator of your choice
2:17
and save it into a file let us call it
2:21
sample Dorsey once your code is saved
2:26
you have to compile a program now why do
2:30
we have to compile a program why is to
2:32
step necessary the computer does not
2:35
understand see pursue it cannot execute
2:40
the sea program or the individuals
2:43
statements in a C in C language
2:45
correctly for example let's say that in
2:52
c you can write G equal to a percentage
2:55
be the percentage operation stands for
2:57
more blue so this statement says that
3:01
you take a model B and assign it to the
3:03
variable-g now the microprocessor of the
3:07
processor in the computer cannot execute
3:09
the statement because it does not
3:10
understand this C programming language
3:13
so it translates into an equal and piece
3:19
of code consisting of even more basic
3:23
statements for example here this is just
3:26
for the purpose of illustration and
3:28
start important that you understand
3:30
exactly what's going on but in a
3:33
statement like g equal to EI % HB can be
3:36
translated into a bunch of statement
3:38
saying Lord data from a particular
3:41
memory location into a particular
3:43
register load the second piece of data
3:46
from another memory location to the
3:48
second register divide the contents of
3:51
these two registers store the remainder
3:54
in the third register
3:55
ok and then finally take the result and
3:59
store it into a third memory location so
4:02
the simple statement that we wrote is
4:04
equal to a people person day to be or g
4:07
equal to a model b becomes a bunch of
4:10
basic statements that the microprocessor
4:12
can understand and then it executes
4:15
these statements
4:16
ok so why not program in the
4:19
microprocessor language or in assembly
4:21
language writing programs in machine
4:24
language is varied
4:26
tedious one line in a higher the
4:30
programming language like C translates
4:34
into multiple lines of machine language
4:37
okay so i think machine language code is
4:40
very long it's very tedious and is
4:43
particularly prone to errors
4:45
also they are not portable if you're
4:47
right machine code for a particular
4:49
process that let's say you're writing
4:53
the code for an Intel processor and you
4:54
translate it into an AMD machine it
4:57
might not work
4:58
okay Paris if you take your sequel and
5:00
compile it in another mission it will
5:02
run on that mission so compilers work as
5:06
a bridge
5:07
what they do is take a high level c
5:09
programming language and translate it
5:12
into the equivalent machine code so
5:16
think of them as a translator so you the
5:18
input is a sea program and then you give
5:22
it to a compiler the output of the
5:24
compiler will be the equivalent machine
5:26
program for the Tillerman machine you
5:29
want to run it on
5:30
ok so a compiler is a translator which
5:32
translates from c2 machine called how do
5:37
you combine look at we have just seen
5:40
why we bother with compilation and on
5:43
unix systems or linux systems you can
5:45
compile the program using the GCC
5:48
compiler so G stands for goosey computer
5:52
so for example if you have edited and
5:55
saved your file is sampled see you can
5:58
just type on the command prompt on the
6:01
terminal GCC sample don't see if your
6:05
code does not have any others then the
6:08
system will silently see that ok
6:12
the compilation is done and it will show
6:14
you the prompt if there are errors the
6:18
system will list the others and so you
6:20
can go back to the editor editor code to
6:22
collectors and come back and compile
6:24
again as long as they're compilation
6:28
errors there will be no executable file
6:31
created
6:32
ok so the executable file list of cord
6:35
is the file that you can finally run
6:38
and if there are compilation errors the
6:40
compiler will not produce executable
6:41
call
6:42
ok so name your file is whatever you
6:48
want let's call it your file name dot C
6:50
and then GCC your file named seen people
6:54
producing executable file if you're on
6:57
linux the executable files that it
7:00
creates is something called a dot out
7:02
okay if there are no errors and you look
7:05
at your directly there will be a new
7:07
file called a doubt in your directory
7:08
and we will explain the directory
7:12
structures in and this session
7:15
ok let us look at a very simple C
7:19
program
7:20
ok open your editor with depending on
7:23
which system you are in so let's write a
7:26
very simple program it's it's very short
7:29
what it task is three lines of code and
7:33
some punctuation this is known as the C
7:38
syntax let's examine this code what this
7:42
code does is it prints a particular
7:45
message which is welcome to see ok and
7:50
it has various components you type it
7:53
into an editor asset is make no
7:55
punctuation mistakes syntax service now
8:00
if you compile the program and you have
8:02
typed the program correctly then a new
8:06
file called a doubt will be created
8:09
ok so if you type GCC sample dot C and
8:12
if there are no errors it will just say
8:14
nothing ok if that if it say something
8:17
then there is a compilers matter
8:18
compilation creates an executable it out
8:22
and now you can run the program by
8:26
typing and this is important
8:29
dot /a doubt
8:33
ok so the syntax is important what to
8:35
type is dot /a dope and then when you
8:39
run the program it will see
8:41
welcome to welcome to see
8:44
because that is what the program is
8:47
supposed to do
8:48
ok let's look at the program a little
8:53
more carefully water its components
8:55
ok it had three lines the first line
8:59
said hash include stdio garbage
9:04
ok so it has multiple components one is
9:08
the first symbol which is a hash the
9:13
first symbol which is a hash please do
9:16
not forget to include that and actually
9:18
there is no space between the hash and
9:20
the first I ok so there is no space here
9:23
so hash include STD or debit this line
9:27
is supposed to tell see that please
9:30
include the standard input/output
9:32
Liberty the standard input/output
9:34
library is what has the printer routines
9:38
which will print output messages onto
9:40
the determinant ok so if you want to
9:42
have any input output component of your
9:45
program then you should include SDR
9:48
portage include this line routinely near
9:51
in the first line of your see file
9:53
because in the course of this class we
9:58
will often need scanners and productive
10:00
statement so will often need input
10:02
statements and output statements so
10:05
include this by default now if you look
10:09
at the second line we will have a
10:12
function called name and again note the
10:16
parentheses here that is also part of
10:18
this Intex so main is supposed to be a
10:21
function of all see programs start by
10:25
executing the main function and it
10:28
starts from the first statement of the
10:30
main function now what does the main
10:32
function have it has a single line which
10:35
says printf welcome to see so interface
10:39
the function called to output from a sea
10:42
program so to print a particular message
10:45
you and close it in double quotes
10:49
ok so whatever is enclosed in the double
10:52
quotes will be printed
10:53
ok so to repeat again please note the
10:57
extra punctuation symbols which tell you
11:00
that these are valid see statements
11:04
ok so all the underline statements at
11:06
all the underlying symbols are important
11:09
ok so in the line printed welcome to see
11:12
this is what is known as a statement NC
11:16
and statements in C and in a semicolon
11:19
so this semicolon is also important
11:22
because it tells you that this is where
11:24
the statement means what typical errors
11:29
do we have when we couldn't see let's
11:32
systematically enumerate a few common
11:34
areas that could happen in even a simple
11:36
program like what we have seen for
11:38
example you could forget to include
11:40
studio darted something if you don't
11:42
include the standard input library then
11:45
the compiler will give you an error
11:47
message
11:48
you may include forget to include the
11:50
main function then also you will get
11:53
some error message you could forget to
11:55
include the semicolon in the statement
11:57
you could forget to include the braces
12:01
the curly braces in Maine or forget to
12:07
close the double code open or close
12:09
double quote in the printer statement so
12:12
these are a few errors that you could
12:15
make even in a simple code like what we
12:17
have seen we have only three lines but
12:19
they could also have errors i would
12:22
advise you to try deliberately making
12:25
these mistakes in your code try
12:27
compiling them and study their messages
12:30
once you are familiar with the error
12:32
messages this will help you later in
12:34
your coding because when you see there
12:36
are messages you can guess what it is
12:39
did you possibly make in your code so go
12:41
back to the code and collected

No comments:

Post a Comment