程序代写代做代考 compiler algorithm interpreter javascript Java PowerPoint Presentation

PowerPoint Presentation

Basics in programming

References
Kingsley-Hughes, Adrian, and Kathie Kingsley-Hughes. Beginning Programming, Wiley, 2005.

Steve McConnell, Code Complete 2nd edition, Microsoft

What is programming
Programming is the ability to talk to the computer in a language it can understand and using grammar and syntax that it can follow to get it to perform useful tasks for you.

What is programming
Whenever you are programming, no matter how simple or complicated your task, you are always giving the computer an instruction.

Why so many programming languages
Well, while it’s true that different types of computer understand different types of code (so a PC is fundamentally different from a Mac), each type of computer really only understands one language, and that’s not the language you write code in.

Why so many programming languages
A program (either an interpreter or a compiler) is required to convert the code from text into a binary language that the computer can decipher.

Why so many programming languages
A computer operates by reading instructions in binary, which you might be familiar with. It is a number system but it differs from our usual base 10 system by only having two digits — 0 and 1.

Why so many programming languages

Why so many programming languages
Binary is tedious and if we had to work in binary with our computers using it all the time things would get very complicated

Why so many programming languages
When you are programming, or, more specifically, writing code, what you are actually doing is writing code that another program can understand to translate that code into something that the computer can understand.

Why so many programming languages

Why so many programming languages
When you are programming, or, more specifically, writing code, what you are actually doing is writing code that another program can understand to translate that code into something that the computer can understand.

Why so many programming languages
When you are programming, or, more specifically, writing code, what you are actually doing is writing code that another program can understand to translate that code into something that the computer can understand.

Different code = same result

What is needed to make programs
Development environment

Compiler (Optional?)

What is needed to make programs
A development environment is a program that you use to type the code into.
Some languages need a specific development environment (for example, Visual Basic), while others need only a simple text editor (JavaScript is an example of a language you can work with using nothing more than a text editor).
There is also a huge array of languages where you have a choice as to what development environment to use (C++ is one such language).

What is needed to make programs
A compiler, see last lecture

How computers read code

How computers read code
Old and simple way is to process all code from top to bottom

-> Only fast when code is small and simple

! Problem is that all code is loaded into memory

How computers read code

How computers read code

How computers read code
Solution?

Break up the code!

-> Different parts of the code to handle different parts of the solution

How computers read code

How computers read code
The code is broken up into smaller components, so it is easier to write and you can test it earlier and more often.

How computers read code
Debugging any code errors is a lot easier because you know what part of the code handles what aspect of the program.

How computers read code
You are in a position to reuse certain parts of your code in other projects more easily because they will be self-contained.

How computers read code
Building up a big project from smaller, interconnected chunks enables you to build up a project over time and add more features as your skills improve!

How computers read code
Building up a big project from smaller, interconnected chunks enables you to build up a project over time and add more features as your skills improve!

How computers read code
Code can be broken into:

– statements
– functions and procedures

How computers read code
The statement is the programming equivalent of the sentence. It is one line of computer instruction that can be understood by the system.

How computers read code
If statements are the sentences of programming, then functions and procedures are the paragraphs.

How computers read code
Functions are the ultimate way to sort out your code into usable chunks.

There might be times when you need only one statement but generally your code will make use of many statements and it is then that you will start to group them into functions.

How computers store the code

Some historical and nowadays ways to store code

How computers store the code
How is the data stored on these media?

It is stored in the simplest form possible — binary. What is being read is a series of zeros and ones.

How computers store the code
Code can be stored in:

Plain text

Compiled

How to design code?
One of the basic concepts is to use flow chart before doing any programming

How to design code?

How to design code?

How to design code?

How to design code?
Before doing any programming we should first plan how we solve problem given?

How to design code?
A sequence is the simplest flowcharting construction. You do each step in order. 

How to design code?
This structure is called a decision, “If Then.. Else” or a conditional. A question is asked in the decision shape. Depending on the answer the control follows either of two paths.

How to design code?
This structure allows you to repeat a task over and over. The red chart above on the left does the task and repeats doing the task until the condition is false. It always does the task at least once. The green chart on the right checks the condition first and continues doing the task while the condition is true.

How to design code?
Flowcharts are used to visualize the processes and make it understandable for nontechnical people. They are also used to visualize algorithms and comprehend pseudo code which is used in programming.

How to design code?
1. Make algorithm that sums two number

How to design code?
2. Illustrate process of allergic person buying food

How to design code?
3. Illustrating the process of withdrawing cash

How to design code?
More advanced flow chart
– Storing values / information

How to design code?
4. Calculate sum of five values?

Exercise 2.
What are the advantages and disadvantages of storing code in a) plain text and b) compiled?

Create a flowchart that solves following problem:
”Should I take my umbrella with me today?”

/docProps/thumbnail.jpeg