Upload
benedict-lawson
View
216
Download
0
Embed Size (px)
Citation preview
Introduction to Programming<Lecture 1>
Prof. Rommel Anthony PalominoDepartment of Computer Science and
Information Technology
Spring 2011
Rommel AB Palomino - UDC Spring 2011
2
Basic Components of a Computer Computer: machine that performs different
tasks according to specific instructions. It has two major components:
Hardware: composed of electronic and mechanical parts
Software: data, and computer programs
Rommel AB Palomino - UDC Spring 2011
3
Hardware
Rommel AB Palomino - UDC Spring 2011
4
SoftwareTypes of Computer Programs: Operating Systems: Windows, Linux, Solaris Application Programs: Word, Games,
Browsers Compilers: Translate high level programming
languages into machine language
Rommel AB Palomino - UDC Spring 2011
5
Programming Languages What is a Programming Language?
Express human instructions to computers Each language has its own syntax Languages evolved over time. There exist five
different programming languages generations.
Rommel AB Palomino - UDC Spring 2011
6
Interpreted vs. Compiled Language Interpreted: Source code is directly executed
at runtime by the interpreter.
Compiled: source code goes to the compiler and creates object code or machine code. Then it is executed in the host CPU.
Rommel AB Palomino - UDC Spring 2011
7
Interpreted vs. Compiled Language
Compiled Needs compilation
every time you change the code.
Hard to debug Compiled language is
faster because source code is reduced to machine code, and then is executed.
Interpreted• Easy to develop• Easy to debug• Slower to
execute because source code is directly executed (“interpreted”) at runtime
Rommel AB Palomino - UDC Spring 2011
8
Generation Languages
Human
Machine1GL or First Generation: Machine Language (0110101100110000011)
2GL or Second Generation: Assembly languages.push ebx / mov ebx,1 / dec ebx
3GL or Third Generation: more programmer friendly. High level lang. such as C, C++, Java.
4GL or Forth Generation: reduce programming effort, developing time, and cost.
5GL or Fifth Generation: use of constraints rather than an algorithm. Comp. solves problem w/o prog.Use in AI research such as ProLog.
Sixth Generation: ???
Rommel AB Palomino - UDC Spring 2011
9
Program Development Life Cycle The process of developing a software,
according to the desired needs of a user, by following a basic set of interrelated procedures.
Rommel AB Palomino - UDC Spring 2011
10
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm design and
representation
Coding
Testing & Debugging
Maintenance
Rommel AB Palomino - UDC Spring 2011
11
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm design and
representation
Coding
Testing & Debugging
Maintenance
•Define clearly the problem in terms of their inputs, outputs and constraints.•A clearly defined problem is half the solution.•This step is very critical for success of the completion of the program.Problem Example:“Create a Program that will give the sum of consecutives numbers from 0 to a determined number”
•Invest a significant portion of your time in this phase!
Rommel AB Palomino - UDC Spring 2011
12
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm design and
representation
Coding
Testing & Debugging
Maintenance
•Once identified the problem, we should find the most effective and simplest solution.•Divide and Conquer: Break problem into smaller and simple sub-problems
Input: certain natural number (n) Output: sum of consecutive natural numbers from 0 to n
Problem Example:“Create a Program that will give the sum of consecutives numbers from 0 to a determined number”
Rommel AB Palomino - UDC Spring 2011
13
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm Design and
Representation
Coding
Testing & Debugging
Maintenance
•After doing the analysis, we need to design our proposed solution.
• The solution has to be expressed in a step-by-step manner, so the computer will understand it: Algorithm.
•Ways of representing it: • Human Language:
flowchart• Pseudocode: human
lang/prog. lang.
•Design techniques:• Modular Programming• Top-Down Design• Structured Programming
Rommel AB Palomino - UDC Spring 2011
14
Pseudocode
1. Get number “n”2. Set count to 03. Set sum to 04. While count is less than or equal to “n“ do
Add count value to sum Increment count by 1
5. Return sum
Problem Example:“Create a Program that will give the sum of consecutives natural numbers from 0 to a determined number”
Rommel AB Palomino - UDC Spring 2011
15
Flowchart
Process
Data
Cond
Process: represents process of executing an or group of operations that results in a change of value, form or location of information. i.e.:Add 1 to XSum = sum + 1Data: Input/output. i.e.:Read NGet NDisplay XConditional: Yes/No questions.It has two outputs, one for Yes, and one for No.
Rommel AB Palomino - UDC Spring 2011
16
Flowchart
Terminal
Flowline symbol:Represents the flow of information or the correct sequence of steps in the flowchart.
Terminal Symbol/Terminator:Represents the start or end point of a flowchart.
Connector:Connects parts of flowcharts.
Rommel AB Palomino - UDC Spring 2011
17
Flowchart
Problem Example:“Create a Program that will give the sum of consecutives natural numbers from 0 to a determined number”
Start
Read n
count = 0
sum = 0
count<=n?
sum = sum + count
count = count + 1
yes
Print sum
End
no
Rommel AB Palomino - UDC Spring 2011
18
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm Design and
Representation
Coding
Testing & Debugging
Maintenance
•Algorithm ready!•Process of translate it into computer instructions.•Each prog. language has its own syntax.•Actual software.
int n = 5; // let’s pretend we are reading
int sum =0, count = 0;
while( count <= n ){ sum = sum + count; count = count + 1;}System.out.println(sum);
Start
Read n
count = 0
sum = 0
count<=n?
sum = sum + count
count = count + 1
yes
Print sum
End
no
Rommel AB Palomino - UDC Spring 2011
19
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm Design and
Representation
Coding
Testing & Debugging
Maintenance
•Don’t expect your program works the first time!•Debugging: finding errors (bugs) in your program and fix them.•Two error types: • Compile-time: before
running your program. Syntax errors.
• Runtime: occurs when you are running your program
Compile-time error:int n = 0
Runtime error:int n = 0;int x = 5/n; Division by
zero!
Rommel AB Palomino - UDC Spring 2011
20
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm Design and
Representation
Coding
Testing & Debugging
Maintenance
Testing: process of validation of the program. Three major types:• Unit testing: test basic
units of software• Integration testing: tests
two or more tested units• System testing: based on
functional/requirement specification
Is my program really doing what it was required to do?
Look back into your requirements, and your problem definition!
Formulate basic tests. i.e. entering the min and max values for parameters.
Rommel AB Palomino - UDC Spring 2011
21
Tasks of Program Development
Problem Definition
Problem Analysis
Algorithm Design and
Representation
Coding
Testing & Debugging
Maintenance
Maintenance: •Updating and correcting of the program for changing conditions or newly discovered bugs.
What if your requirements change?
What if your boss wants to add more functionality to your program?
Should I start all over again from scratch?
NO!!!! … as long as you do all your previous steps correctly , of course.
Rommel AB Palomino - UDC Spring 2011
22
Exercise Write a program that can calculate the
factorial of a given number “n”.
Rommel AB Palomino - UDC Spring 2011
23
Questions?