Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

23
Introduction to Programming <Lecture 1> Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2014

description

Introduction to Programming . Spring 2014. Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology. Basic Components of a Computer. Computer : machine that performs different tasks according to specific instructions. It has two major components: - PowerPoint PPT Presentation

Transcript of Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Page 1: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Introduction to Programming<Lecture 1>

Prof. Rommel Anthony PalominoDepartment of Computer Science and

Information TechnologySpring 2014

Page 2: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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

Page 3: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Hardware

Page 4: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

SoftwareTypes of Computer Programs: Operating Systems: Windows, Linux, Solaris Application Programs: Word, Games,

Browsers Compilers: Translate high level programming

languages into machine language

Page 5: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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.

Page 6: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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.

Page 7: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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

Page 8: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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: ???

Page 9: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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.

Page 10: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program Development

Problem Definition

Problem Analysis

Algorithm design and representati

on

Coding

Testing & Debugging

Maintenance

Page 11: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

Definition

Problem Analysis

Algorithm design and representati

on

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!

Page 12: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

Definition

Problem Analysis

Algorithm design and representati

on

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”

Page 13: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

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

Page 14: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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”

Page 15: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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.

Page 16: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

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.

Page 17: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

FlowchartProblem 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

Page 18: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

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

Page 19: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

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 programCompile-time error:

int n = 0

Runtime error:int n = 0;int x = 5/n; Division by

zero!

Page 20: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

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.

Page 21: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Tasks of Program DevelopmentProblem

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

Page 22: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Exercise Write a program that can calculate the

factorial of a given number “n”.

Page 23: Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology

Rommel AB Palomino - UDC Spring 2014

Questions?